2012-04-19 101 views
1

我已经使用WSDLToJava生成客户端存根。之后,我创建了这里提到的客户http://cxf.apache.org/docs/developing-a-consumer服务超时问题

this.testService = new TestService(wsdlURL, SERVICE_NAME); //line #1 
    this.port = testService.getTestPort();   //line #2 
    Client client = ClientProxy.getClient(port);  //line #3 
    client.getInInterceptors().add(new LoggingInInterceptor()); 
    client.getOutInterceptors().add(new LoggingOutInterceptor()); 
    HTTPConduit conduit = (HTTPConduit)client.getConduit(); 
    // setting timeouts for connection 
    String timeOutSecond = CoreProperty.getProp(CORE_SERVICE_TIME_OUT_MILLISECONDS); 
    int timeout =0; 
    try{ 
     if(Utils.isNotNullOrBlank(timeOutSecond)) 
      timeout = Integer.parseInt(timeOutSecond.trim()); 
     else 
      timeout = Constants.DEFAULT_SERVICE_TIME_OUT_MILLISECONDS; 
    }catch (NumberFormatException e) { 
     timeout = Constants.DEFAULT_SERVICE_TIME_OUT_MILLISECONDS; 
    } 
    conduit.getClient().setReceiveTimeout(timeout); 

的问题是,线#1正在采取近5分钟,如果服务器关闭抛出错误 - 在wsdlURL规定。

我想设置一个超过30秒的时间来建立客户端连接。

如果服务已启动,所有工作正常,并且receivetimeout设置正常。我如何设置建立连接的超时时间。 如果服务器关闭,程序正在#1线等待,它等待着超过4分钟,我想避免这种情况。

谢谢你的时间。请帮忙

+0

超时通过'conduit.getClient()setConnectionTimeout(...)',设置连接是你在找什么? – 2012-04-21 09:58:42

回答