Package org.restlet

Examples of org.restlet.Request


            c.stop();
        }
    }

    private void sendPut(String uri) throws Exception {
        Request request = new Request(Method.PUT, uri, createTestXml());
        Client c = new Client(Protocol.HTTP);
        Response r = c.handle(request);

        try {
            checkForChunkedHeader(r);
View Full Code Here


     * @return The formatted log entry.
     */
    protected String getDefaultResponseLogMessage(Response response,
            int duration) {
        StringBuilder sb = new StringBuilder();
        Request request = response.getRequest();

        if (isDebugging()) {

        } else {
            long currentTime = System.currentTimeMillis();

            // Append the date of the request
            sb.append(String.format("%tF", currentTime));
            sb.append('\t');

            // Append the time of the request
            sb.append(String.format("%tT", currentTime));
            sb.append('\t');

            // Append the client IP address
            String clientAddress = request.getClientInfo().getUpstreamAddress();
            sb.append((clientAddress == null) ? "-" : clientAddress);
            sb.append('\t');

            // Append the user name (via IDENT protocol)
            if (isIdentityCheck()) {
                org.restlet.engine.log.IdentClient ic = new org.restlet.engine.log.IdentClient(
                        request.getClientInfo().getUpstreamAddress(), request
                                .getClientInfo().getPort(), response
                                .getServerInfo().getPort());
                sb.append((ic.getUserIdentifier() == null) ? "-" : ic
                        .getUserIdentifier());
            } else if ((request.getChallengeResponse() != null)
                    && (request.getChallengeResponse().getIdentifier() != null)) {
                sb.append(request.getChallengeResponse().getIdentifier());
            } else {
                sb.append('-');
            }

            sb.append('\t');

            // Append the server IP address
            String serverAddress = response.getServerInfo().getAddress();
            sb.append((serverAddress == null) ? "-" : serverAddress);
            sb.append('\t');

            // Append the server port
            Integer serverport = response.getServerInfo().getPort();
            sb.append((serverport == null) ? "-" : serverport.toString());
            sb.append('\t');

            // Append the method name
            String methodName = (request.getMethod() == null) ? "-" : request
                    .getMethod().getName();
            sb.append((methodName == null) ? "-" : methodName);

            // Append the resource path
            sb.append('\t');
            String resourcePath = (request.getResourceRef() == null) ? "-"
                    : request.getResourceRef().getPath();
            sb.append((resourcePath == null) ? "-" : resourcePath);

            // Append the resource query
            sb.append('\t');
            String resourceQuery = (request.getResourceRef() == null) ? "-"
                    : request.getResourceRef().getQuery();
            sb.append((resourceQuery == null) ? "-" : resourceQuery);

            // Append the status code
            sb.append('\t');
            sb.append((response.getStatus() == null) ? "-" : Integer
                    .toString(response.getStatus().getCode()));

            // Append the returned size
            sb.append('\t');

            if (!response.isEntityAvailable()
                    || Status.REDIRECTION_NOT_MODIFIED.equals(response
                            .getStatus())
                    || Status.SUCCESS_NO_CONTENT.equals(response.getStatus())
                    || Method.HEAD.equals(request.getMethod())) {
                sb.append('0');
            } else {
                sb.append((response.getEntity().getSize() == -1) ? "-" : Long
                        .toString(response.getEntity().getSize()));
            }

            // Append the received size
            sb.append('\t');

            if (request.getEntity() == null) {
                sb.append('0');
            } else {
                sb.append((request.getEntity().getSize() == -1) ? "-" : Long
                        .toString(request.getEntity().getSize()));
            }

            // Append the duration
            sb.append('\t');
            sb.append(duration);

            // Append the host reference
            sb.append('\t');
            sb.append((request.getHostRef() == null) ? "-" : request
                    .getHostRef().toString());

            // Append the agent name
            sb.append('\t');
            String agentName = request.getClientInfo().getAgent();
            sb.append((agentName == null) ? "-" : agentName);

            // Append the referrer
            sb.append('\t');
            sb.append((request.getReferrerRef() == null) ? "-" : request
                    .getReferrerRef().getIdentifier());
        }

        return sb.toString();
    }
View Full Code Here

                                                .getCurrent();

                                        if (context != null) {
                                            final Response response = context
                                                    .getClientDispatcher()
                                                    .handle(new Request(
                                                            Method.GET,
                                                            this.url.toString()));

                                            if (response.getStatus()
                                                    .isSuccess()) {
View Full Code Here

*/
public class ValidatorTestCase extends RestletTestCase {

    public void testRequired() {
        // Create mock call
        Request rq = new Request();
        Response rs = new Response(rq);

        // Prepare the validator to test
        Validator validator = new Validator();
        validator.setNext(new TraceRestlet(null));
        validator.validatePresence("a");
        validator.handle(rq, rs);

        // Test if the absence of "a" is detected
        assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, rs.getStatus());

        // Test if the presence of "a" is ignored
        rq.getAttributes().put("a", "123");
        rs.setStatus(Status.SUCCESS_OK);
        validator.handle(rq, rs);
        assertEquals(Status.SUCCESS_OK, rs.getStatus());
    }
View Full Code Here

        assertEquals(Status.SUCCESS_OK, rs.getStatus());
    }

    public void testFormat() {
        // Create mock call
        Request rq = new Request();
        Response rs = new Response(rq);

        // Prepare the validator to test
        Validator validator = new Validator();
        validator.setNext(new TraceRestlet(null));
        validator.validateFormat("a", "\\d*");
        validator.handle(rq, rs);

        // Test if the absence of "a" is ignored
        assertEquals(Status.SUCCESS_OK, rs.getStatus());

        // Test if a wrong format of "a" is detected
        rq.getAttributes().put("a", "abc");
        rs.setStatus(Status.SUCCESS_OK);
        validator.handle(rq, rs);
        assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, rs.getStatus());

        // Test if a correct format of "a" is ignored
        rq.getAttributes().put("a", "123");
        rs.setStatus(Status.SUCCESS_OK);
        validator.handle(rq, rs);
        assertEquals(Status.SUCCESS_OK, rs.getStatus());
    }
View Full Code Here

* @author Jerome Louvel
*/
public class AwsTest {
    public static void main(String[] args) throws Exception {
        // Prepare the request
        final Request request = new Request(Method.GET,
                "http://s3.amazonaws.com/quotes/nelson");
        request.setChallengeResponse(new ChallengeResponse(
                ChallengeScheme.HTTP_AWS_S3, "44CF9590006BF252F707",
                "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));

        // Add some extra headers
        final Series<Parameter> extraHeaders = new Form();
        extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com");
        extraHeaders.add("X-Amz-Magic", "abracadabra");

        // For the test we hard coded a special date header. Normally you don't
        // need this as the
        // HTTP client connector will automatically provide an accurate Date
        // header and use it
        // for authentication.
        // extraHeaders.add("X-Amz-Date", "Thu, 17 Nov 2005 18:49:58 GMT");
        request.getAttributes().put("org.restlet.http.headers", extraHeaders);

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

View Full Code Here

     * Returns a request.
     *
     * @return Request instance.
     */
    protected Request getRequest() {
        return new Request();
    }
View Full Code Here

    /**
     * Tests context's base reference getting/setting.
     */
    public void testBaseRef() throws Exception {
        final Request request = getRequest();
        final String resourceRefURI = "http://www.restlet.org/path/to/resource";
        final Reference resourceRef = getReference(resourceRefURI);
        request.setResourceRef(resourceRefURI);
        assertEquals(resourceRef, request.getResourceRef());
        String uri = "http://www.restlet.org/path";
        Reference reference = getReference(uri);
        request.getResourceRef().setBaseRef(uri);
        assertEquals(uri, request.getResourceRef().getBaseRef().toString());
        assertEquals(reference, request.getResourceRef().getBaseRef());
        uri = "http://www.restlet.org/path/to";
        reference = getReference(uri);
        request.getResourceRef().setBaseRef(uri);
        assertEquals(uri, request.getResourceRef().getBaseRef().toString());
        assertEquals(reference, request.getResourceRef().getBaseRef());
    }
View Full Code Here

    /**
     * Tests method getting/setting.
     */
    public void testMethod() throws Exception {
        final Request request = getRequest();
        request.setMethod(Method.GET);
        assertEquals(Method.GET, request.getMethod());
        request.setMethod(Method.POST);
        assertEquals(Method.POST, request.getMethod());
    }
View Full Code Here

    /**
     * Tests redirection reference getting/setting.
     */
    public void testRedirectionRef() throws Exception {
        final Request request = getRequest();
        final Response response = getResponse(request);
        String uri = "http://www.restlet.org/";
        Reference reference = getReference(uri);
        response.setLocationRef(uri);
        assertEquals(reference, response.getLocationRef());
View Full Code Here

TOP

Related Classes of org.restlet.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.