1 Reply Latest reply on Jun 26, 2015 2:00 AM by bharadwaj n

    cxf:rsClient not replacing exchange body

    Aaron Cirillo Newbie

      I have an issue where I am consuming from a JMS queue and trying to manipulate the body of the exchange with a cxf:rsClient, but it is not working. Typically what happens is I use the cxf:rsClient and the response or payload that I get back from the remote server is placed in the body of the exchange. That does not happen when I use a route that consumes from a queue. Does anyone know if I am doing anything wrong? Simplified version below that reproduces the issue:

       

      ####################################

      ###

      ###  blueprint.xml I am using

      ###

      ####################################

       

      <?xml version="1.0" encoding="UTF-8"?>

      <blueprint default-activation="eager"

                 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"

                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                 xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"

                 xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"

                 xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"

                 xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.1.0"

                 xsi:schemaLocation="http://camel.apache.org/schema/blueprint/cxf

                 http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd

                 http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd

                 http://aries.apache.org/xmlns/jpa/v1.1.0

                 http://aries.apache.org/schemas/jpa/jpa_110.xsd

                 http://aries.apache.org/xmlns/transactions/v1.1.0

                 http://aries.apache.org/schemas/transaction/transactionv11.xsd">

       

       

       

       

          <!-- Beans for ActiveMQ -->

          <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">

              <!-- <property name="brokerURL" value="failover:(tcp://:61616)" /> -->

              <property name="brokerURL" value="tcp://localhost:61616" />

          </bean>

          <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">

              <property name="maxConnections" value="8" />

              <property name="connectionFactory" ref="jmsConnectionFactory" />

          </bean>

          <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">

              <property name="connectionFactory" ref="pooledConnectionFactory" />

              <property name="concurrentConsumers" value="10" />

          </bean>

          <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">

              <property name="configuration" ref="jmsConfig" />

          </bean>

         

         

          <cxf:rsServer id="restEndpoint"

                       address="http://0.0.0.0:8080/jms-test"

                       serviceClass="com.aaron.jms.test.RestImpl"

                       loggingFeatureEnabled="true"

                       loggingSizeLimit="100000">

            <cxf:providers>

               <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />

            </cxf:providers>

          </cxf:rsServer>

         

          <cxf:rsClient id="restClient"

                       address="http://jsonplaceholder.typicode.com"

                       serviceClass="com.aaron.jms.test.RestImpl"

                       loggingFeatureEnabled="true"

                       loggingSizeLimit="100000">

            <cxf:providers>

               <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />

            </cxf:providers>

          </cxf:rsClient>

         

          <camelContext autoStartup="true" id="jms-test" xmlns="http://camel.apache.org/schema/blueprint">

              <route customId="true" id="jms-producer">

                  <from uri="cxfrs://bean://restEndpoint?bindingStyle=SimpleConsumer"/>

                  <wireTap uri="activemq:jms-test?jmsMessageType=Text"/>

              </route>

              <route customId="true" id="jms-consumer">

                  <from uri="activemq:jms-test"/>

                  <log message="incoming message from queue"/>

                  <to uri="log:com.aaron.jms.test?showBody=true%26showHeaders=true%26maxChars=100000"/>

                  <transform>

                      <constant>"replaced message body with transformer in route"</constant>

                  </transform>

                  <log message="message after transformation"/>

                  <to uri="log:com.aaron.jms.test?showBody=true%26showHeaders=true%26maxChars=100000"/>

                  <setHeader headerName="CamelHttpPath">

                      <constant>/users</constant>

                  </setHeader>

                  <setHeader headerName="CamelHttpMethod">

                      <constant>GET</constant>

                  </setHeader>

                  <log message="calling rest client"/>

                  <to uri="cxfrs://bean://restClient"/>

                  <log message="message after calling rest client below:"/>

                  <to uri="log:com.aaron.jms.test?showBody=true%26showHeaders=true%26maxChars=100000"/>

                  <!-- I should see the payload from the rest client in the above log message, but I do not! -->

              </route>

          </camelContext>

       

       

      </blueprint>

       

      ####################################

      ###

      ###  RestImpl class

      ###

      ####################################


      package com.aaron.jms.test;

      public class RestImpl implements RestInterface{

       

       

          @Override

          public void runService() {

              return;

          }

         

      }

       

      ####################################

      ###

      ###  RestInterface class

      ###

      ####################################


      package com.aaron.jms.test;

       

      import javax.ws.rs.Consumes;

      import javax.ws.rs.POST;

      import javax.ws.rs.Path;

      import javax.ws.rs.core.MediaType;

       

      @Path("")

      public interface RestInterface {

       

          @POST

          @Consumes(MediaType.APPLICATION_JSON)

          @Path("/runservice")

          public void runService();

         

      }