Java SOAP/JAX-WS:如何设置超时?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36422306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:25:46  来源:igfitidea点击:

Java SOAP/JAX-WS: How to set timeouts?

javaweb-servicessoapjax-ws

提问by chris01

I am calling a webservice with Java. It is working well but I'd like to set a connection timeout too.

我正在使用 Java 调用网络服务。它运行良好,但我也想设置连接超时。

My code:

我的代码:

URL urlwsdl = new URL ("file://" + wsdl);
QName qn = new QName("http://myserver/myservice", "MyService");
port = new TimeSeriesService_Service (urlwsdl, qn).getMyServicePort (); 

BindingProvider prov = (BindingProvider) port;
prov.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://server1/myservice");
prov.getRequestContext ().put (BindingProvider.USERNAME_PROPERTY, "max");
prov.getRequestContext ().put (BindingProvider.PASSWORD_PROPERTY, "secret");

QueryRequest1 req = new QueryRequest1 ();
QueryResponse1 res = port.queryRequest1 (req);  // *** TIMEOUT for ~2 minutes

I found some posts on the internet. They use the context of the binding provider as I do for http-auth.

我在网上找到了一些帖子。他们使用绑定提供程序的上下文,就像我对 http-auth 所做的一样。

e.g.

例如

prov.getRequestContext ().put ("com.sun.xml.ws.request.timeout", 1000000);

But they use objects I do not have in my namespace.

但是他们使用我的命名空间中没有的对象。

e.g.

例如

sun.net.client.defaultConnectTimeout
com.sun.xml.ws.connect.timeout
com.sun.xml.ws.request.timeout

I have sun.net but not .client. I have com.sun.xml but not .ws.

我有 sun.net 但没有 .client。我有 com.sun.xml 但没有 .ws。

I have a simple java jdk (1.7, Debian 8.3, 64bit) and can compile and run my webservice, the webclient and also wsimport. No netbeans and no jboss installed.

我有一个简单的 java jdk(1.7,Debian 8.3,64 位)并且可以编译和运行我的网络服务、网络客户端和 wsimport。没有安装 netbeans 和 jboss。

Any ideas how I can set a timeout? Thanks for help! Chris

任何想法如何设置超时?感谢帮助!克里斯

回答by Willem Salembier

Using the JDK JAX-WS implementation you probably should set the internal properties

使用 JDK JAX-WS 实现,您可能应该设置内部属性

 ((BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", timeout);
 ((BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.request.timeout", timeout);

Please upvote my JIRA issue to standardize this in an upcoming version of JAX-WS https://java.net/jira/browse/JAX_WS-1166

请为我的 JIRA 问题投票以在即将发布的 JAX-WS 版本中对此进行标准化 https://java.net/jira/browse/JAX_WS-1166