我试图通过使用Camel& amp;来调用第三方SOAP Web服务。 CXF。以下是wsdl
的摘录<message name="setDeviceDetailsv4">
<part name="parameters" element="tns:setDeviceDetailsv4"></part>
<part name="gdspHeader" element="tns:gdspHeader"></part>
</message>
<message name="setDeviceDetailsv4Response">
<part name="result" element="tns:setDeviceDetailsv4Response"></part>
</message>
<portType name="SetDeviceDetailsv4">
<operation name="setDeviceDetailsv4" parameterOrder="parameters gdspHeader">
<input message="tns:setDeviceDetailsv4"></input>
<output message="tns:setDeviceDetailsv4Response"></output>
</operation>
</portType>
<binding name="SetDeviceDetailsv4PortBinding" type="tns:SetDeviceDetailsv4">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="setDeviceDetailsv4">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal" parts="parameters"></soap:body>
<soap:header message="tns:setDeviceDetailsv4" part="gdspHeader" use="literal"></soap:header>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="SetDeviceDetailsv4Service">
<port name="SetDeviceDetailsv4Port" binding="tns:SetDeviceDetailsv4PortBinding">
<soap:address location="http://localhost:${HttpDefaultPort}/GDSPWebServices/SetDeviceDetailsv4Service"></soap:address>
</port>
</service>
可以看出,肥皂体使用&#34;参数&#34;上面wsdl中提到的与tns相关的部分:setDeviceDetailsv4。
示例客户端代码如下所示:
System.out.println("Invoking setDeviceDetailsv4...");
SetDeviceDetailsv4_Type _setDeviceDetailsv4_parameters = null;
GdspHeader _setDeviceDetailsv4_gdspHeader = null;
SetDeviceDetailsv4Response _setDeviceDetailsv4__return = port.setDeviceDetailsv4(_setDeviceDetailsv4_parameters, _setDeviceDetailsv4_gdspHeader);
System.out.println("setDeviceDetailsv4.result=" + _setDeviceDetailsv4__return);
当我通过与上述客户端代码匹配的骆驼路线拨打电话时,我期待CXF / Camel附加&#34; gdspHeader&#34;到肥皂标题,但不是,它将其作为参数发送到网络方法。一个单独的开发人员手工编写了SOAP调用,这是他所拥有的,并且它完美运行!!
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.gdsp.xxxxxxx.com/">
<soapenv:Header>
<ws:gdspHeader>
<gdspCredentials>
<userId>xxxx</userId>
<password>xxxx</password>
</gdspCredentials>
</ws:gdspHeader>
</soapenv:Header>
<soapenv:Body>
<ws:setDeviceDetailsv4>
<deviceId>xxxxxx</deviceId>
<state>x</state>
</ws:setDeviceDetailsv4>
</soapenv:Body>
</soapenv:Envelope>
然而,当我通过Camel进行调用时,我得到的是SOAP消息:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns2:gdspHeader xmlns:ns2="http://ws.gdsp.xxxx.com/">
<gdspCredentials>
<password>xxxx</password>
<userId>xxxx</userId>
</gdspCredentials>
</ns2:gdspHeader>
</soap:Header>
<soap:Body>
<ns1:setDeviceDetailsv4 xmlns:ns1="http://ws.gdsp.Xxxxx.com/">
<ns2:arg0 xmlns:ns2="http://ws.gdsp.xxx.com/">
<deviceId>xxxx</deviceId>
<state>x</state>
</ns2:arg0>
<ns2:arg1 xmlns:ns2="http://ws.gdsp.xxxx.com/">
<gdspCredentials>
<password>xxxx</password>
<userId>xxxx</userId>
</gdspCredentials>
</ns2:arg1>
</ns1:setDeviceDetailsv4>
</soap:Body>
</soap:Envelope>
它失败了。我试图使gdspCredentials为NULL并且不起作用,如果我只传入一个参数,CXF会抛出一个soap错误,指出该方法需要两个参数。
这是我的pom.xml文件的一部分
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.7</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<frontEnd>jaxws21</frontEnd>
<faultSerialVersionUID>1</faultSerialVersionUID>
<wsdl>src/main/resources/wsdl/extWebServices.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
如何让我的Camel / CXF调用与其他开发人员的调用相匹配?
答案 0 :(得分:0)
根据我的需要,wsdl没有开箱即用。我能够修改wsdl以删除&#34;标题&#34;选项并使用拦截器来处理标题部分和处理器以处理响应&amp;请求编组/解组。