Restlet has been edited by willem jiang (Jan 03, 2009).

Change summary:

Fixed the snippet url error

(View changes)


Restlet Component

The Restlet component provides Restlet based endpoints for consuming and producing RESTful resources.

URI format


Format of restletUrl:


Restlet promotes decoupling of protocol and application concerns. The reference implementation of Restlet Engine supports a number of protocols. However, we have tested the HTTP protocol only. The default port is port 80. We do not automatically switch default port based on the protocol yet.


Name Default Value Description
restletMethod GET The method to be used in the request for producer. For consumer, the Restlet Endpoint only consumes requests made by restletMethod. The string value is converted to by the Method.valueOf(String) method.
restletBindingRef null The name to lookup the RestletBinding object in the Camel Registry.
restletRealmRef null The name to lookup the Realm Map in the Camel Registry.

Message Headers

Name Type Description
org.apache.camel.restlet.auth.login String Login name for basic authentication. It is set on the IN message by application and get filtered before Restlet Request header by Camel.
org.apache.camel.restlet.auth.password String Password name for basic authentication. It is set on the IN message by application and get filtered before Restlet Request header by Camel.
org.restlet.*   Attributes of a Restlet message that get propagated to Camel IN headers.

Message Body

Camel will store the Restlet response from the external server on the OUT body. All headers from the IN message will be copied to the OUT message so headers is preserved during routing.


Restlet Endpoint with Authentication

This sample starts a Restlet consumer endpoint that listens POST requests on http://localhost:8080. The route looks like follow. The consumer invokes a processor that creates a response to echo the request body and the value of header "id".

from("restlet:http://localhost:8080/securedOrders?restletMethod=post&restletRealmRef=realm").process(new Processor() {
    public void process(Exchange exchange) throws Exception {
                "received [" + exchange.getIn().getBody()
                + "] as an order id = "
                + exchange.getIn().getHeader("id"));

The restletRealmRef in URI query is an option to lookup a Realm Map in the registry. If this option is specified, the Restlet consumer will use the information to authenticate user logins. Only authenticated requests can access the resources. In this sample, we create a Spring application context that serves as a registry. The bean ID of the Realm Map should match the restletRealmRef.

An error occurred: The system administrator has been notified.

The sample starts a direct endpoint that sends requests to the server on http://localhost:8080 (i.e. our Restlet consumer endpoint).

// Note: restletMethod and restletRealmRef are stripped 
// from the query before a request is sent as they are 
// only processed by Camel.

That is all we need. We are ready to send a request and try out the Restlet component. The sample client sends a request to "direct:start-auth" endpoint with the following headers. Notice that org.apache.camel.restlet.auth.login and org.apache.camel.restlet.auth.password will not be propagated as Restlet header.

  • org.apache.camel.restlet.auth.login (internally used by Camel)
  • org.apache.camel.restlet.auth.password (internally used by Camel)
  • id ("application" header)
final String id = "89531";

Map<String, Object> headers = new HashMap<String, Object>();
headers.put(RestletConstants.LOGIN, "admin");
headers.put(RestletConstants.PASSWORD, "foo");
headers.put("id", id);

String response = (String) template.requestBodyAndHeaders("direct:start-auth", 
        "<order foo='1'/>", headers);

The sample client will get a response:

received [<order foo='1'/>] as an order id = 89531

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences