Please refer to this page for the original resources: http://camel.apache.org/cxfrs.html

In our current project, we need to provide RESTful interface to the outside world from some web application, which will be using Apache Camel to do the internal business routing. So we are considering using Camel to serve the RESTful interface.

After some investigation, I found the CXFRS component. It provides what I need. But from the above resource page, there’s not much documentation about the internal processing logic of the component. So I wrote some test. Here’s some conclusion:

  1. At the declaration of the cxf:rsServer, the “serviceClass” property should be set to some concrete class, you cannot put some interface here. But in fact, during the process of the Camel, the methods in that concrete class will not be called, this class is only used by CXF to mapping REST request URI to the resource class method according to JSR311 specification. After CXF receiving the REST request, it will be delivered to the Camel Route(skipping the resource method). So in the “How To Consume the REST request in Camel” example in the original resource page, the method in the resource class (“CustomerService”) will not be called.
  2. Be careful of the method definition in the resource class. The parameter in the method will be delivered by the Camel Route to the next endpoint. For example, if you define the method as below, in the next endpoint, the body of the Exchange will be a String message.

    @POST
        @Produces("application/xml")
        public Response post(String message){
            ……

          }
  3. The return value of the last endpoint will be returned to the REST client, so don’t forget to return some value.

In conclusion, using camel to do REST if very easy, but you should pay more attention to the things that have not been documented.

This is the source code for my example.