首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Matlab内部调用JAX-WS WS服务

从Matlab内部调用JAX-WS WS服务
EN

Stack Overflow用户
提问于 2010-11-02 09:59:44
回答 3查看 3.3K关注 0票数 1

我有一个先锋队 can服务,我可以使用一个定制的java类调用它(使用基本身份验证)。java wsimport工具用于生成java代理存根,这一切都很完美。

java代码(下面的所有类都是由wsimport生成的,提供了一个url +身份验证信息):

代码语言:javascript
复制
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函数(包含上述代码)时,webservice调用失败,错误不明:

代码语言:javascript
复制
??? 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在这两种情况下监视请求/响应,我会看到:

== 函数直接调用==

下面的所有调用/响应都是由wsimport生成的JAX代码自动发生的。我的代码只是在生成的服务代理上调用webservice方法,没有什么特别之处。

代码语言:javascript
复制
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 ==中调用的函数完全相同

代码语言:javascript
复制
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 (Sun1.6)。我还注意到,Matlab在发送请求时不尊重http.agent属性。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-08 11:19:53

事实证明,这个问题似乎只发生在非linux平台上的Matlab 64位版本上。如果我安装了一个32位版本的Matlab,它可以正常工作。我将把这个问题标记为答案,因为这似乎是Matlab的一个问题,Mathworks正在调查这个问题(线程id: 1-DUMQZ]。

票数 2
EN

Stack Overflow用户

发布于 2010-11-04 18:27:41

如果代理设置负责此问题,则可以使用下列静态方法进行配置。

代码语言:javascript
复制
% 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
EN

Stack Overflow用户

发布于 2010-11-10 21:02:33

ICEbrowser在某些平台上仍然用于HTML呈现,它将自己的一些类插入到全局VM设置中。如果您从未在当前会话中打开“帮助”浏览器,则此操作可能对您有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4076564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档