【问题标题】:How to set JAX-WS client timeout?如何设置 JAX-WS 客户端超时?
【发布时间】:2012-12-24 11:54:15
【问题描述】:

我正在 Jboss 5.1.0 GA 上开发 Jax-ws 客户端。 我想设置 Web 服务客户端超时。

我已经尝试过 StubExt.PROPERTY_CLIENT_TIMEOUT

int timeoutMillisecond=3000;
bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);

它可以工作,但是只有在 3*timeoutMillisecond 之后(9000 毫秒之后)才会抛出异常,但是 3000ms 会写入日志文件。

2012-12-24 15:42:40,053 DEBUG Sending request
2012-12-24 15:42:49,057 ERROR WebServiceException returned: 
javax.xml.ws.WebServiceException: org.jboss.ws.core.WSTimeoutException: Timeout after: 3000ms

我还尝试了很多其他方法

bp.getRequestContext().put("com.sun.xml.ws.connect.timeout", 100);
bp.getRequestContext().put("com.sun.xml.ws.request.timeout", 100);
// from com.sun.xml.ws.developer.JAXWSProperties
bp.getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT, 100);
bp.getRequestContext().put(JAXWSProperties.REQUEST_TIMEOUT, 100);

但在 Jboss 5.1 上没有任何效果


您能告诉我如何正确设置客户端超时吗?

【问题讨论】:

标签: java web-services jakarta-ee jboss jax-ws


【解决方案1】:

我执行了以下步骤并解决了问题

  1. 升级了 jbossws-native 库,follow this link
    jbossws-native-3.4.0 是 Jboss 5.1.0GA 的最新支持版本。可以看JBossWS - Supported Target Containers

  2. 使用StubExt.PROPERTY_CLIENT_TIMEOUT

    int timeoutMillisecond=3000;
    bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);
    

顺便说一句,在这个版本中StubExt.PROPERTY_CONNECTION_TIMEOUT 也可以正常工作。

【讨论】:

    【解决方案2】:

    您可以为您的服务端口使用these 设置。

    BindingProvider bindingProvider = (BindingProvider) YOUR_SERVICE_PORT;
    Map<String, Object> context = bindingProvider.getRequestContext();
    context.put(BindingProviderProperties.CONNECT_TIMEOUT, 3*1000);
    context.put(BindingProviderProperties.REQUEST_TIMEOUT,3*1000);
    

    【讨论】:

    • BindingProviderProperties.REQUEST_TIMEOUT 是“com.sun.xml.ws.request.timeout”的变量名和 BindingProviderProperties.CONNECT_TIMEOUT 的“com.sun.xml.ws.connect.timeout”,OP已经试过了,还是不行。
    【解决方案3】:

    你完全错过了结帐代码:

    网址 url = 新网址("http://tst.com:9990/ws/hello?wsdl");

        //1st argument service URI, refer to wsdl document above
    //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://tstsoap/", "HelloWorldImplService");
    
        Service service = Service.create(url, qname);
    
       HelloWorld hello = service.getPort(HelloWorld.class);
    

    如您所见,如果不先创建服务,您将无法获取端口。
    所以超时总是发生在服务创建时。 所以为端口设置时间是没有意义的...... 有人需要发布有关服务超时的信息……而不是端口超时…… 除非有人能证明我错了......

    【讨论】:

      猜你喜欢
      • 2011-03-09
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 2017-11-18
      • 2011-02-05
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      相关资源
      最近更新 更多