2010-11-02 37 views
1

我有一個Vanguard webservice,我可以使用自定義java類調用(使用基本認證)。 java的wsimport工具被用來生成java代理存根,並且這一切都很完美。從Matlab內調用JAX-WS webservice

Java代碼(下面所有課程wsimport生成給定的URL +認證信息):

Authenticator.setDefault(new SimpleAuth(username,pass)); 
MyWSObject obj = new MyWSObject(url);   -> triggers the exception 
ServicePortType port = obj.getServicePort(); 
OutputType result = port.MyWSMethod(params); 
OutputData data = result.getOutputData(); 

當我運行從MATLAB完全相同的Java函數(包含上述代碼)的web服務調用失敗有一個不起眼的錯誤:

??? Java exception occurred: 
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: com.ctc.wstx.exc.WstxUnexpectedCharException: 
Unexpected character '"' (code 34) in DOCTYPE declaration; expected a space between public and system identifiers 

at [row,col,system-id]: 
[1,63,"<my webservice url>"] 
     at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256) 
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:84) 
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:99) 
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:89) 
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.hasWSDLDefinitions(RuntimeWSDLParser.java:209) 
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:119) 
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254) 
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217) 
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165) 
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93) 
at javax.xml.ws.Service.<init>(Service.java:56) 
at edu.soton.decode.activities.vanguardws.MyWSObject.<init>(MyWSObject.java:42) 
at edu.soton.decode.activities.VanguardActivity.execute(VanguardActivity.java:80) 

如果我使用Wireshark監視請求/在這兩種情況下反應變量我看到:

==直接調用Java函數==

以下所有調用/響應都由wsimport生成的JAX-WS代碼自動發生。我的代碼只是調用生成的服務代理上的webservice方法,沒什麼奇怪的。

GET /bin/ws.dsb?wsdl/mywebservice HTTP/1.1 
User-Agent: Java/1.6.0_22 
Host: myhost 
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 
Connection: keep-alive 
... 

HTTP/1.1 401 Authorization Required 
Server: Vanguard Server/5.1.10 
Connection: close 
Content-Length: 608 
Date: Mon, 01 Nov 2010 15:04:17 GMT 
Last-Modified: Mon, 01 Nov 2010 15:04:17 GMT 
Expires: Mon, 01 Nov 2010 15:04:17 GMT 
Cache-Control: no-cache 
WWW-Authenticate: Basic realm="Local Library" 
Auto-Studio-Login: 0 
Content-Type: text/html 
... 

GET /bin/ws.dsb?wsdl/mywebservice HTTP/1.1 
User-Agent: Java/1.6.0_22 
Host: myhost 
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 
Connection: keep-alive 
Authorization: Basic Z29yaXNzZW46ZGlyaw== 
... 

HTTP/1.1 200 OK 
Server: Vanguard Server/5.1.10 
Connection: close 
Content-Length: 5408 
Date: Mon, 01 Nov 2010 15:04:17 GMT 
Last-Modified: Mon, 01 Nov 2010 15:04:17 GMT 
Expires: Mon, 01 Nov 2010 15:04:17 GMT 
Cache-Control: no-cache 
Set-Cookie: KillIDws=lpvovmb3oa9; path=/ 
Content-Type:text/xml 
... 

POST /bin/ws.dsb?soap/mywebservice HTTP/1.1 
Content-type: text/xml;charset="utf-8" 
Soapaction: "" 
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 
User-Agent: JAX-WS RI 2.1.6 in JDK 6 
Host: myhost 
Connection: keep-alive 
Authorization: Basic Z29yaXNzZW46ZGlyaw== 
Content-Length: 214 
... 

HTTP/1.1 200 OK 
Server: Vanguard Server/5.1.10 
Connection: close 
Content-Length: 851 
Date: Mon, 01 Nov 2010 15:04:18 GMT 
Last-Modified: Mon, 01 Nov 2010 15:04:18 GMT 
Expires: Mon, 01 Nov 2010 15:04:18 GMT 
Cache-Control: no-cache 
Set-Cookie: KillIDws=lpvovmb3oi2; path=/ 
Content-Type:text/xml; charset=utf-8 
... 

- >最後響應到底在哪從MATLAB ==內部調用同一個Java功能

GET /bin/ws.dsb?wsdl/mywebservice HTTP/1.1 
Accept: */* 
Accept-Encoding: gzip 
Accept-Language: en 
User-Agent: Mozilla/5.0 (Java 1.6.0_22; Windows XP 5.2 amd64; en_GB) ICEbrowser/v6_0_2 
Host: myhost 
Connection: Keep-Alive 
... 

HTTP/1.1 401 Authorization Required 
Server: Vanguard Server/5.1.10 
Connection: close 
Content-Length: 608 
Date: Mon, 01 Nov 2010 15:02:42 GMT 
Last-Modified: Mon, 01 Nov 2010 15:02:42 GMT 
Expires: Mon, 01 Nov 2010 15:02:42 GMT 
Cache-Control: no-cache 
WWW-Authenticate: Basic realm="Local Library" 
Auto-Studio-Login: 0 
Content-Type: text/html 
... 

結果返回

== - >一切都停止在這裏與上面顯示的例外。因此,在Matlab內運行時,似乎Matlab正在爲JVM環境做些什麼,以阻止生成的代理進行第二次認證調用。它只是在401之後退出,而不是在純Java情況下進行身份驗證。

我已經設置了MATLAB_JAVA環境變量,以便在這兩種情況下使用相同的JVM(sun 1.6)。我也注意到Matlab在發送請求時並不尊重http.agent屬性。

+0

你能發佈從MATLAB調用的Java代碼嗎? – zellus 2010-11-02 10:22:19

+0

編輯:添加java代碼+完整例外 – dgorissen 2010-11-02 10:53:01

+0

根據您的wireshark分析,* url *似乎是正確的。 * params *有區別嗎?您可以使用* MATLAB_JAVA *指定另一個jvm。 – zellus 2010-11-02 11:02:53

回答

2

事實證明,這個問題似乎只發生在64位版本的Matlab在非Linux平臺上。它工作正常,如果我安裝一個32位版本的Matlab。我將這個問題標記爲答案,因爲這似乎是Matlab的一個問題,Mathworks正在調查這個問題(線程ID:1-DUMQQZ))。

+1

+1反饋。 – zellus 2010-11-08 20:36:31

+1

更新:這是一個確認的錯誤。我引用:「唯一的解決方法是使用-nodisplay標誌啓動MATLAB,即在不加載桌面的情況下啓動MATLAB,或者(如您之前的電子郵件中已經指出的)在Windows上使用32位MATLAB,或者Linux上的64位MATLAB。「 – dgorissen 2011-03-09 10:30:45

0

如果代理設置對此問題負責,則可以使用以下靜態方法進行配置。

% configure 
java.lang.System.getProperties().put('http.proxyHost', 'your.proxy'); 
java.lang.System.getProperties().put('http.proxyPort', 'port number'); 
java.lang.System.getProperties().put('http.proxyUser', 'name'); 
java.lang.System.getProperties().put('http.proxyPassword', 'password'); 

java.lang.System.getProperties().put('http.proxySet', 'true'); 

% verify 
java.lang.System.getProperty('http.proxyHost') 
java.lang.System.getProperty('http.proxyPort') 
java.lang.System.getProperty('http.proxyUser') 
java.lang.System.getProperty('http.proxyPassword') 

% test 
urlread('http://www.yahoo.com/') 
+0

http.proxySet是一個城市的神話。它沒有效果。 – EJP 2012-04-11 19:01:27

0

ICEbrowser,MATLAB仍然在某些平臺上用於HTML渲染,它將一些自己的類插入到全局VM設置中。如果您從不在當前會話中打開幫助瀏覽器,這可能對您有用。