我已经使用SpringDSL在Camel中实现了一个简单的SOAP服务使用者。我将它定向到SoapUI中运行的模拟服务,这样我就可以看到传入的请求和返回的响应。我还配置了日志拦截器。我观察到的是SoapUI接收到的请求和响应被返回并记录为SOAP信封,其中包含日志拦截器中的正确数据,但是,当我试图在CXF调用之后立即记录正文时,它是空的(不是null,只是一个空字符串(。这是我的配置:
<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>
这是日志的相关部分:
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
我做错了什么?
好吧,我有点想明白了,我添加了以下代码:
<bean id="prepareResponse" class="com.dummy.PrepareResponse"/>
并在CXF调用后立即调用它,例如
<process ref="prepareResponse"/>
bean的代码非常简单:
@Override
public void process(Exchange exchange) throws Exception {
Object[] result = exchange.getIn().getBody(Object[].class);
exchange.getOut().setBody(result[0]);
}