APISonar


org.restlet.data.Protocol.HTTP

> org > restlet > data > Protocol > HTTP
org APIs restlet APIs data APIs Protocol APIs HTTP APIs

Example 1
public static void main(String[] args) {
        // Instantiates and starts a simple HTTP server.
        try {
            new Server(Protocol.HTTP, null).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Example 2
public static void main(String[] args) throws Exception {
        // Prepare the request
        Request request = new Request(Method.GET, "http://www.restlet.org");
        request.setReferrerRef("http://www.mysite.org");

        // Handle it using an HTTP client connector
        Client client = new Client(Protocol.HTTP);
        Response response = client.handle(request);

        // Write the response entity on the console
        Representation output = response.getEntity();
        output.write(System.out);
    }
Example 3
protected void setUpClient(int serverPort, String path) throws Exception {
        this.client = new Client(Protocol.HTTP);
        this.uri = "http://localhost:" + serverPort + path;
        this.client = new Client(Protocol.HTTP);
    }
Example 4
public static void main(String[] args) throws Exception {
        // Creating a minimal Restlet returning "Hello World"
        Restlet restlet = new Restlet() {
            @Override
            public void handle(Request request, Response response) {
                response.setEntity("Hello World!", MediaType.TEXT_PLAIN);
            }
        };

        // Create the JXTA/HTTP server
        new Server(Protocol.HTTP, restlet).start();
    }
Example 5
public static void main(String[] args) throws Exception {
        // Outputting the content of a Web page
        Client client = new Client(Protocol.HTTP);
        client.get("http://www.restlet.org").getEntity().write(System.out);
    }
Example 6
public static void main(String[] args) throws Exception {
        // Instantiating the HTTP server and listening on port 8182
        new Server(Protocol.HTTP, 8182, NegotiatedServerResource.class)
                .start();
    }
Example 7
public Service(String serviceUri, Representation xmlService)
            throws IOException {
        this(new Client(Protocol.HTTP), serviceUri, xmlService);
    }
Example 8
public static void main(String[] args) throws Exception {
        // Create a new Component.
        Component component = new Component();

        // Add a new HTTP server listening on port 8182.
        component.getServers().add(Protocol.HTTP, 8182);

        // Attach the sample application.
        component.getDefaultHost().attach("/firstSteps",
                new FirstStepsApplication());

        // Start the component.
        component.start();
    }
Example 9
public void testUnhandledConsumer() throws IOException {
        Client client = new Client(Protocol.HTTP);
        Response response = client.handle(new Request(Method.POST, 
            "http://localhost:" + portNum + "/orders/99991/6"));
        // expect error status as no Restlet consumer to handle POST method
        assertEquals(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, response.getStatus());
        assertNotNull(response.getEntity().getText());
    }
Example 10
public static void main(String[] args) {
        long startTime = System.currentTimeMillis();

        Client client = new Client(Protocol.HTTP);

        FileRepresentation fr = new FileRepresentation("file:///c:/test.mpg",
                MediaType.VIDEO_MPEG);
        System.out.println("Size sent: " + fr.getSize());

        Response response = client.post("http://localhost:8554/", fr);

        System.out.println("Status: " + response.getStatus());
        long endTime = System.currentTimeMillis();
        System.out.println("Duration: " + (endTime - startTime) + " ms");
    }
Example 11
public static void main(String[] args) throws Exception {

        Server server = new Server(Protocol.HTTP, 8554, new Restlet() {
            @Override
            public void handle(Request request, Response response) {
                FileRepresentation fr = new FileRepresentation(
                        "file:///c:/test.mpg", MediaType.VIDEO_MPEG);
                System.out.println("Size sent: " + fr.getSize());
                response.setEntity(fr);
            }
        });

        server.start();
    }
Example 12
protected void call(String uri) throws Exception {
        final Request request = new Request(Method.GET, uri);
        Client c = new Client(Protocol.HTTP);
        final Response r = c.handle(request);
        assertEquals(r.getStatus().getDescription(), Status.SUCCESS_OK, r
                .getStatus());
        assertEquals("Hello world", r.getEntity().getText());
    }
Example 13
protected int setUpServer(int suggestedPort, String path) throws Exception {
        c = new Component();
        final Server server = c.getServers().add(Protocol.HTTP, suggestedPort);
        c.getDefaultHost().attach(createApplication(path));
        c.start();
        return server.getActualPort();
    }
Example 14
public void testProtocolConstructors() {
        assertEquals("http://restlet.org", new Reference(Protocol.HTTP,
                "restlet.org").toString());
        assertEquals("https://restlet.org:8443", new Reference(Protocol.HTTPS,
                "restlet.org", 8443).toString());

        final Reference ref = new Reference(Protocol.HTTP, "restlet.org");
        ref.addQueryParameter("abc", "123");
        assertEquals("http://restlet.org?abc=123", ref.toString());
    }
Example 15
public static void deleteUser(String userName, String password) {
        Request request = getAuthenticatedRequest(Method.DELETE,
                getUserUri(userName), userName, password);
        Response resp = new Client(Protocol.HTTP).handle(request);
        System.out.println(resp.getStatus() + " : " + resp.getLocationRef());
    }
Example 16
public static void putUser(String userName, String password,
            String fullName, String email) {
        Form form = new Form();
        form.add("user[password]", password);
        form.add("user[full_name]", fullName);
        form.add("user[email]", email);

        Response resp = new Client(Protocol.HTTP).put(getUserUri(userName),
                form.getWebRepresentation());
        System.out.println(resp.getStatus());
    }
Example 17
public static void main(String[] args) throws Exception {
        // Instantiating the Application providing the Range Service
        Application app = new Application();

        // Plug the server resource.
        app.setInboundRoot(HelloServerResource.class);

        // Instantiating the HTTP server and listening on port 8111
        new Server(Protocol.HTTP, 8111, app).start();
    }
Example 18
protected Reference createBaseRef() {
        final Reference reference = new Reference();
        reference.setProtocol(Protocol.HTTP);
        reference.setAuthority("localhost");
        if (!shouldAccessWithoutTcp()) {
            reference.setHostPort(getServerWrapper().getServerPort());
        }
        return reference;
    }
Example 19
public static void main(String[] args) throws Exception {
        Server server = new Server(Protocol.HTTP, 8111);
        server.setNext(MyServerResource20.class);
        server.start();
    }
Example 20
public void makeUser(String user, String password) {
        // Create the input form
        final Form input = new Form();
        input.add("password", password);

        // Create the target URI, encoding the user name
        final String uri = "https://maps.example.com/user/"
                + Reference.encode(user);

        // Invoke the web service
        new Client(Protocol.HTTP).put(uri, input.getWebRepresentation());
    }
Example 21
protected void call(String uri) throws Exception {
        Client client = new Client(Protocol.HTTP);
        testCall(client, Method.POST, uri);
        testCall(client, Method.PUT, uri);
    }
Example 22
public static void main(String[] args) throws Exception {
        ChallengeAuthenticator guard = new ChallengeAuthenticator(
                new Context(), ChallengeScheme.HTTP_BASIC, "Tutorial");
        // Instantiate and populate the verifier
        MapVerifier verifier = new MapVerifier();
        verifier.getLocalSecrets().put("scott", "tiger".toCharArray());

        // Set the verifier
        guard.setVerifier(verifier);
        guard.setNext(HelloServerResource.class);

        // Instantiating the HTTP server and listening on port 8182
        new Server(Protocol.HTTP, 8182, guard).start();
    }
Example 23
public MailServerComponent() throws Exception {
        // Set basic properties
        setName("RESTful Mail Server component");
        setDescription("Example for 'Restlet in Action' book");
        setOwner("Restlet S.A.S.");
        setAuthor("The Restlet Team");

        // Adds a HTTP server connector
        Server server = getServers().add(Protocol.HTTP, 8111);
        server.getContext().getParameters().set("tracing", "false");

        // Attach the application to the default virtual host
        getDefaultHost().attachDefault(new MailServerApplication());
    }
Example 24
public StreamClientHelper(Client client) {
        super(client);
        getProtocols().add(Protocol.HTTP);
        getProtocols().add(Protocol.HTTPS);
    }
Example 25
protected void startServer(ChallengeScheme challengeScheme,
            RoleChecker roleChecker) throws Exception {
        final Application appConfig = getApplication();
        startServer(appConfig, Protocol.HTTP, challengeScheme, roleChecker);
    }