2016-06-07 160 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以刪除「標題」選項,並使用攔截器來處理標題部分和處理器,以處理響應請求編組/解組。