转载

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官网。未验证。

参考

https://www.igorkromin.net/index.php/2018/12/06/setting-jax-ws-webservice-client-timeout-values-correctly-within-a-weblogic-12c-container/

https://github.com/javaee/metro-jax-ws/issues/1166

https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6/html/development_guide/develop_a_jax-ws_client_application

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.
原文  https://www.zhongdaiqi.com/jax-ws-ri-2-2-9-java-webservice-timeout-setting/
正文到此结束
Loading...