cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Rhodes <>
Subject Camel CXF-RS resource method called twice when using performInvocation
Date Sun, 20 Mar 2016 01:38:14 GMT
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=""

<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"
loggingFeatureEnabled="true" loggingSizeLimit="20">
<ref bean="jsonProvider" />

<!-- The camel route context -->
<camel:camelContext id="camelContext">
<camel:from uri="cxfrs:bean:rsServer?performInvocation=true" />
<camel:to uri="log:body?level=INFO" />
<camel:to uri="file:data/outbox" />


and the Java code for the class in question looks like this:

@Consumes( MediaType.APPLICATION_JSON )
@Produces( MediaType.APPLICATION_JSON )
public class CustomerService
private static long invocationCount = 0;
Map<Long, Customer> customers = new HashMap<Long, Customer>();
    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
Mar 19, 2016 9:32:55 PM org.apache.cxf.interceptor.LoggingInInterceptor
INFO: Inbound Message
ID: 1
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
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.


This message optimized for indexing by NSA PRISM

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message