Java Code Examples for org.restlet.Restlet.handle()

The following are Jave code examples for showing how to use handle() of the org.restlet.Restlet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: restlet-framework   File: CompositeHelper.java   Source Code and License Vote up 6 votes
@Override
public void handle(Request request, Response response) {
    super.handle(request, response);

    if (getFirstInboundFilter() != null) {
        getFirstInboundFilter().handle(request, response);
    } else {
        final Restlet next = this.inboundNext;
        if (next != null) {
            next.handle(request, response);
        } else {
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            getHelped()
                    .getLogger()
                    .error("The "
                                    + getHelped().getClass().getName()
                                    + " class has no Restlet defined to process calls. Maybe it wasn't properly started.");
        }
    }
}
 
Example 2
Project: restlet-framework   File: Redirector.java   Source Code and License Vote up 5 votes
/**
 * Redirects a given call on the server-side to a next Restlet with a given
 * target reference. In the default implementation, the request HTTP
 * headers, stored in the request's attributes, are removed before
 * dispatching. After dispatching, the response HTTP headers are also
 * removed to prevent conflicts with the main call.
 * 
 * @param next
 *            The next Restlet to forward the call to.
 * @param targetRef
 *            The target reference with URI variables resolved.
 * @param request
 *            The request to handle.
 * @param response
 *            The response to update.
 */
protected void serverRedirect(Restlet next, Reference targetRef,
        Request request, Response response) {
    if (next == null) {
        getLogger().warn(
                "No next Restlet provided for server redirection to "
                        + targetRef);
    } else {
        // Save the base URI if it exists as we might need it for
        // redirections
        Reference resourceRef = request.getResourceRef();

        // Reset the protocol and let the dispatcher handle the protocol
        request.setProtocol(null);

        // Update the request to cleanly go to the target URI
        request.setResourceRef(targetRef);
        rewrite(request);
        next.handle(request, response);

        request.setResourceRef(resourceRef);
        // Allow for response rewriting and clean the headers
        response.setEntity(rewrite(response.getEntity()));
        rewrite(response);

        // In case of redirection, we may have to rewrite the redirect URI
        rewriteLocation(request, response);
    }
}
 
Example 3
Project: Camel   File: MethodBasedRouter.java   Source Code and License Vote up 5 votes
@Override
public void handle(Request request, Response response) {
    Method method = request.getMethod();
    LOG.debug("MethodRouter ({}) received request method: {}", uriPattern, method);
    
    Restlet target = routes.get(method);
    if (target != null) {
        target.handle(request, response);
    } else {
        LOG.debug("MethodRouter ({}) method not allowed: {}", uriPattern, method);
        response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
        // must include list of allowed methods
        response.setAllowedMethods(routes.keySet());
    }
}
 
Example 4
Project: restlet-framework   File: Router.java   Source Code and License Vote up 2 votes
/**
 * Effectively handles the call using the selected next {@link Restlet},
 * typically the selected {@link Route}. By default, it just invokes the
 * next Restlet.
 * 
 * @param next
 *            The next Restlet to invoke.
 * @param request
 *            The request.
 * @param response
 *            The response.
 */
protected void doHandle(Restlet next, Request request, Response response) {
    next.handle(request, response);
}