JAX-WS RI 2.2.9 Java WebService Timeout时间设置

JDK1.8 +Tomcat环境,采用以下配置实现了超时配置,且验证有效。

bindingProvider.getRequestContext().put(“com.sun.xml.internal.ws.connect.timeout”, 30000);
bindingProvider.getRequestContext().put(“com.sun.xml.internal.ws.request.timeout”, 60000);

给人感觉,有多种不同的实现!小红帽RedHat给出的示例是针对JBoss,看起jdk有些不一样。

public void testConfigureTimeout() throws Exception
{
   //Set timeout until a connection is established
   ((BindingProvider)port).getRequestContext().put("javax.xml.ws.client.connectionTimeout", "6000");

   //Set timeout until the response is received
   ((BindingProvider) port).getRequestContext().put("javax.xml.ws.client.receiveTimeout", "1000");

   port.echo("testTimeout");
}
代码看起来跟引入的包名匹配度高,但是实测不生效。
而Github上的资料显示,不同的环境下,采用的配置有些不一样,也没有一个统一的标准。
A little overview of several implementations:
// Weblogic JAX-WS properties
((BindingProvider) port).getRequestContext().put(“com.sun.xml.ws.connect.timeout”, timeout);
((BindingProvider) port).getRequestContext().put(“com.sun.xml.ws.request.timeout”, timeout);
// JDK JAX-WS properties
((BindingProvider) port).getRequestContext().put(“com.sun.xml.internal.ws.connect.timeout”, timeout);
((BindingProvider) port).getRequestContext().put(“com.sun.xml.internal.ws.request.timeout”, timeout);
// JBOSS CXF JAX-WS properties, warning these might change in the future (CXF-5261)
((BindingProvider) port).getRequestContext().put(“javax.xml.ws.client.connectionTimeout”, timeout);
((BindingProvider) port).getRequestContext().put(“javax.xml.ws.client.receiveTimeout”, timeout);
小节,对于JAX-WS的超时配置,需要依据自身的环境配置来决定。默认的超时时间是30s连接,响应超时是60s,这个可以参与apache cfx官网。未验证。
参考
http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport(includingSSLsupport)-Example   搜索一下timeout可以查找到配置说明。
Attribute Description
ConnectionTimeout Specifies the amount of time, in milliseconds, that the client will attempt to establish a connection before it times out. The default is 30000 (30 seconds). 
0 specifies that the client will continue to attempt to open a connection indefinitely.
ReceiveTimeout Specifies the amount of time, in milliseconds, that the client will wait for a response before it times out. The default is 60000. 
0 specifies that the client will wait indefinitely.

Leave a Reply