1

i have a restful webservice configured using cxf and camel. My config xml is :

<jaxrs:server id="restContainer" address="/" staticSubresourceResolution="true"> <jaxrs:serviceBeans>  
<ref bean="FooBar" />
  </jaxrs:serviceBeans> 
 <jaxrs:providers>  
<bean class="org.apache.cxf.jaxrs.provider.JSONProvider">
  <property name="dropRootElement" value="true" /> 
 <property name="supportUnwrapped" value="true" /> 
 </jaxrs:providers>  
<camelcxf:rsServer id="rsServer" address="/" serviceClass="com.camel.example.FooBar" /> <camel:camelContext id="camelContext-1">  
<camel:route> 
 <camel:from uri="cxfrs:bean:rsServer" />  
<camel:to uri="http://localhost:8080/Google/rest/search" />  
</camel:route>  
</camel:camelContext> 

Now i have FooBar class which is exposed as a service and is like this :

@Service("Demo") @Path("/foo/bar") public class FooBar{

       @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public PoiDetailsResponse poiGetDetails(
            PoiDetailsRequest json)
    {
        System.out.println(json.getUname());
        System.out.println(json.getDeviceid());
        //do some validation and some business logic
        //return accordingly;
    }

My concern is that when i hit my server .. camelContext takes over immediately and the method present in my class is not at all touched .. infact whatever response comes from my "to" part of the route is send back to the client.. now one way is that i add multiple processor for every businesss logic. but i really want to have my method executed first and then route starts .. how can i do this ?? Also i can hit my server with whatever parameters i want, even if they are wrong (meaning wrong datatypes of variables of PoiDetailsRequest) and get any response parameters (which are not part of PoiDetailsResponse), this is ofcourse not a good thing.. please suggest something..

Sikorski
  • 2,653
  • 3
  • 25
  • 46
  • If you don't get an answer quickly, I would highly recommend posting a link to this question to the Camel Mailing list. The developers are usually very quick to respond. http://camel.apache.org/mailing-lists.html – JustinKSU Apr 23 '12 at 14:31
  • 1
    Yes and Claus Ibsen maybe there to help you again, he is a one man army – Kalpak Gadre Apr 23 '12 at 14:46

1 Answers1

0

You dont need to use the Camel cxfrs component if you want to expose a RS service and use the service bean. You can just use plain CXF RS for this.

The Camel cxfrs component is for when you want to let the RS service route directly into the Camel route.

If you want your method executed first, then you can from your method call Camel by using the ProducerTemplate to send a message to a Camel route using the direct endpoint.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • First of all, thanks Claus you have helped me alot. Secondly just out of curiosity would POJO producing would do any better here ? Also if you see my above camel context configuration .. i make a call to another webservice(lets say google) after my server gets hit and i need response(from the webservice: google) back to my server for processing and validation and sending it further to the end user.. so any suggestions on this ? – Sikorski Apr 24 '12 at 05:40
  • Christian Posta wrote a blog entry recently about using REST with Camel. It may be worth checking out: http://www.christianposta.com/blog/?p=229. – Claus Ibsen Apr 26 '12 at 10:27
  • And for discussing improvements and the likes of the Camel REST components then the Camel mailing list is a better place than stackoverflow – Claus Ibsen Apr 26 '12 at 10:28
  • ok, now that i have got some hold of camel concept .. i am using both approaches (1)exposing my rest service through cxf and camel and then sending response back by a POJO via bean binding .(2) approach suggested by Claus in above answer. – Sikorski Apr 27 '12 at 09:02