0

我使用 Spring DSL 在 Camel 中实现了一个简单的 SOAP 服务使用者。我将它定向到在 SoapUI 中运行的模拟服务,这样我就可以看到请求的传入和返回的响应。我还配置了日志拦截器。我观察到的是 SoapUI 收到的请求和响应被返回并记录为 SOAP 信封,在日志拦截器中带有适当的数据,但是当我尝试在 CXF 调用之后立即记录正文时,它是空的(不是空的,只是一个空的细绳)。这是我的配置:

<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 

我究竟做错了什么?

4

1 回答 1

0

好的,我有点想通了,我添加了以下代码:

<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]);
    }
于 2020-03-12T18:31:55.043 回答