2012-12-18 115 views
0

我應該使用由第三方公開的SOAP服務。我有兩個基本問題w.r.t:從WSDL創建客戶端jar

Q1。 WSDL需要通過瀏覽器訪問的基本身份驗證。現在,當我嘗試使用wsgen/WSDL2JAVA/使用Eclipse Webservice客戶端創建客戶端jar時,我得到HTTP 401 unauthorised。如果我下載並保存到本地WSDL,然後用axis's WSDL2JAVA,我得到


Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL 
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:178) 
    at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35) 
    at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24) 
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'file:/C:/TEST/TOOLS/Authentication.wsdl'.: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound. 
    at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source) 
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
    at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:320) 
    at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:133) 
    ... 2 more 
Caused by: org.xml.sax.SAXParseException: The prefix "wsdl" for element "wsdl:definitions" is not bound. 
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) 
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) 
    ... 7 more 

Q2。我們如何處理經常變化的WSDL,我們是否每次生成客戶端JAR並重新部署應用程序?

任何幫助我創建client.jar的指針都會很棒。

回答

0

對於WSDL中的每個更改,您都應該重新部署client.jar。

我會建議你這個。

  1. 創建一個jar項目來從wsdl生成類。例如,檢查cxf-codegen-plugin wsdl2java。
  2. 創建另一個引用前一個項目的jar項目(Client.jar)。

因此,無論何時WSDL發生變化,您都應該修改項目中的WSDL URL,然後構建兩個jar項目以創建Client.jar。更好的做法是使用WSDL URL作爲Client.jar內部或外部的可配置屬性值來維護它。

希望這會有所幫助。

+0

感謝Sarvana,但創建客戶端jar本身

在下面的例子中,你會看到前綴由XMLNS(XML命名空間)屬性定義由於WSDL由第三方公開並且具有基本身份驗證,因此是一個問題。在使用wsdl2Java時,我得到上述異常,因爲我不知道在哪裏設置ID/PWD,以便wsdl2Java工具清除身份驗證。我希望我明確提出了我的問題。 在此先感謝! – user1912337

+0

由於基本身份驗證,它看起來不是例外。另外wsdl2java工具不需要被設置憑據。只有在您使用客戶端代理調用端點時纔可能進行身份驗證。看起來WSDL沒有以正確的方式保存。或者wsdl本身的語法有一些問題。 –

0

在您的WSDL文件,勾選 「< 」WSDL:定義「>」 標記爲的xmlns:wsdl特性,如果缺少它會拋出錯誤:

「org.xml.sax.SAXParseException :在發佈的錯誤摘要的第5行找到元素「wsdl:definitions」的前綴「wsdl」未綁定「。

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:ns1="http://org.apache.axis2/xsd" 
xmlns:ns="http://pojo.service.quickstart.samples" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
targetNamespace="http://pojo.service.quickstart.samples"> 

審查XML命名空間在這裏是如何工作的: http://www.w3schools.com/xml/xml_namespaces.asp