0

I've implemented a simple SOAP service consumer in Camel using Spring DSL. I directed it to my mock service which is running in SoapUI, so that I can see requests coming in and responses returned. I've also configured logging interceptors. What I observe is the request received by the SoapUI and response is returned and logged as SOAP envelope with proper data in the logging interceptor, however when I try to log the body right after the CXF call, it's empty (not null, just an empty string). Here's my configuration:

<cxf:cxfEndpoint id="soapEndpoint"
                 address="http://localhost:8088/mockServiceSoapBinding"
                 wsdlURL="wsdl/blah.wsdl"
                 serviceClass="my.schema.MyServicePortType"
                 endpointName="s:MyServicePort"
                 serviceName="s:MyService"
                 xmlns:s="http://com.foo">
    <cxf:outInterceptors>
        <ref bean="loggingOutInterceptor"/>
    </cxf:outInterceptors>
    <cxf:inInterceptors>
        <ref bean="loggingInInterceptor"/>
    </cxf:inInterceptors>
    <cxf:properties>
        <entry key="dataFormat" value="POJO"/>
    </cxf:properties>
</cxf:cxfEndpoint>

<camelContext id="main" xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="jetty:http://localhost:8181/callSoap"/>

        <setBody>
            <groovy>
                body = new MyRequest();
                ... populate the object here ...
                return body;
            </groovy>
        </setBody>

        <setHeader name="operationName">
            <constant>sendRequest</constant>
        </setHeader>
        <setHeader name="operationNamespace">
            <constant>http://com.foo</constant>
        </setHeader>

        <log message="****************** BEFORE CXF CALL ${body}" loggingLevel="INFO"/>

        <to uri="cxf:bean:soapEndpoint"/>

        <log message="****************** AFTER CXF CALL ${body}" loggingLevel="INFO"/>
    </route>
</camelContext>

And here is the relevant portion of the log:

11:39:47.123 [default-workqueue-1] INFO  o.a.c.s.P.P.MyServicePortType - Inbound Message
----------------------------
ID: 1
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml; charset=utf-8
Headers: {Content-Length=[640], content-type=[text/xml; charset=utf-8], Server=[Jetty(6.1.26)]}
Payload: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://com.foo">
   <soapenv:Header/>
   <soapenv:Body>
      <ns0:MyResponse>
      <!-- SOME XML HERE -->
      </ns0:MyResponse>
   </soapenv:Body>
</soapenv:Envelope>
--------------------------------------
11:39:47.168 [default-workqueue-1] INFO  route1 - ****************** AFTER CXF CALL 

What am I doing wrong?

JavaDuke
  • 113
  • 6

1 Answers1

0

OK, I kinda figured it out, I added the following code:

<bean id="prepareResponse" class="com.dummy.PrepareResponse"/>

and invoke it right after the CXF call, e.g.

<process ref="prepareResponse"/>

The code of the bean is very simple:

@Override
    public void process(Exchange exchange) throws Exception {
        Object[] result = exchange.getIn().getBody(Object[].class);
        exchange.getOut().setBody(result[0]);
    }
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
JavaDuke
  • 113
  • 6