有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何设置JAXWS客户端超时?

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

我试过StubExt。属性客户端超时

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

它可以工作,但只有在3*timeoutmillised之后(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没有任何效果


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


共 (3) 个答案

  1. # 1 楼答案

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

    1. 升级了jbossws本机库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. # 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);
    
  3. # 3 楼答案

    您完全缺少point check out代码:

    URL=新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);
    

    如您所见,如果不先创建服务,就无法获得端口
    因此,超时总是发生在服务创建时。 因此,为端口设置时间是毫无意义的。。。。。。。 有人需要发布一些关于服务超时的信息。。。。不是端口超时。。。。 除非有人能证明我错了