Camel gang: I'm using the Camel CXFRS support to publish a REST service using Camel. What I want is for the incoming request to actually invoke my service class, and the response from that to go into the Camel route for further processing. That appears to happen just fine when using the performInvocation=true option, BUT... when I do that, it appears that the method on the resource class is called twice for each incoming REST call.
My beans.xml looks like this: ------------------------------------------------- <?xml version="1.0" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> <bean id="myTypeConverter" class="com.fogbeam.exp.camel.cxfrs.typeconverter.MyTypeConverter" /> <!-- <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider" /> --> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" /> <cxf:rsServer id="rsServer" address="http://localhost:9090/CxfRsRouterTest/route" serviceClass="com.fogbeam.exp.camel.cxfrs.jaxrs.beans.CustomerService" loggingFeatureEnabled="true" loggingSizeLimit="20"> <cxf:providers> <ref bean="jsonProvider" /> </cxf:providers> </cxf:rsServer> <!-- The camel route context --> <camel:camelContext id="camelContext"> <camel:route> <camel:from uri="cxfrs:bean:rsServer?performInvocation=true" /> <camel:to uri="log:body?level=INFO" /> <camel:to uri="file:data/outbox" /> </camel:route> </camel:camelContext> </beans> ------------------------------------------------------- and the Java code for the class in question looks like this: ------------------------------------------------------------------------------- @Path("/customerservice/") @Consumes( MediaType.APPLICATION_JSON ) @Produces( MediaType.APPLICATION_JSON ) public class CustomerService { private static long invocationCount = 0; Map<Long, Customer> customers = new HashMap<Long, Customer>(); @POST @Path("/customers/") public Customer insertCustomer(Customer customer) { System.out.println( "invocationCount: " + (invocationCount++)); System.out.println("----------------\ninvoking insertCustomer, Customer name is: " + customer.getName() + "\n*********************************************" ); customers.put(customer.getId(), customer); return customer; } } --------------------------------------------------------------------------------------- When I run this, the Camel process logs as follows: Mar 19, 2016 9:32:30 PM org.apache.cxf.endpoint.ServerImpl initDestination INFO: Setting the server's publish address to be http://localhost:9090/CxfRsRouterTest/route Mar 19, 2016 9:32:55 PM org.apache.cxf.interceptor.LoggingInInterceptor INFO: Inbound Message ---------------------------- ID: 1 Address: http://localhost:9090/CxfRsRouterTest/route/customerservice/customers Encoding: UTF-8 Http-Method: POST Content-Type: application/json Headers: {accept-encoding=[gzip,deflate], connection=[keep-alive], Content-Length=[39], content-type=[application/json], Host=[localhost:9090], User-Agent=[CxfRSClientMain]} Payload: { "id":"123", "name" -------------------------------------- invocationCount: 0 ---------------- invoking insertCustomer, Customer name is: Phillip Rhodes ********************************************* invocationCount: 1 ---------------- invoking insertCustomer, Customer name is: Phillip Rhodes ********************************************* Mar 19, 2016 9:32:56 PM org.apache.cxf.interceptor.LoggingOutInterceptor INFO: Outbound Message --------------------------- ID: 1 Response-Code: 200 Content-Type: application/json Headers: {Content-Type=[application/json], Date=[Sun, 20 Mar 2016 01:32:55 GMT]} Messages: (message truncated to 20 bytes) Payload: {"id":123,"name":"Ph -------------------------------------- This behavior seems wrong to me. I wouldn't expect my service method to be called twice when somebody hits the REST endpoint. Can anybody confirm if this is invalid, and if so, comment if there's a way to fix this? Or is it a bug in Camel or CXF? Any and all help is much appreciated. This is using Camel 2.16.2, FWIW. Also, there's a question up on StackOverflow from somebody having what appears to be the same issue. http://stackoverflow.com/questions/35958121/apache-camel-cxfrsendpoint-performinvocation-setting-triggers-invokation-twice Thanks, Phil --- This message optimized for indexing by NSA PRISM