2016-06-07 155 views
0

我想通过使用骆驼& CXF调用第三方SOAP Web服务。下面是从WSDL骆驼CXF Wsdl2java问题

<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> 

如可以看到的,所述皂体使用,其在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 /骆驼的“gdspHeader”追加到肥皂但它不是,它将它作为参数发送到Web方法。一个单独的开发人员手工编写了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> 

然而,当我做出过骆驼打电话,这里是我得到的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> 

我怎样才能让我的骆驼/ CXF调用匹配什么其他开发商做了?

回答

0

wsdl无法满足我的需求。我可以修改wsdl以删除“标题”选项,并使用拦截器来处理标题部分和处理器,以处理响应请求编组/解组。