2017-06-01 83 views
0

我正在开发cxf客户端。我从wsdl生成存根并从那里开发代码。我的代码是类似的东西如何在cxf静默代码中设置属性maxConnection

URL WSDL_LOCATION = new URL(targetURL); 
CustomerWS_Service CustomerWSService = new CustomerWS_Service (WSDL_LOCATION); 
CustomerWS customerWS = CustomerWSService.getCustomerWSPort(); 

现在,我想一些属性设置为连接:

max_total_connection: maximum number of connections allowed 
max_connection_per_host: maximum number of connections allowed for a given host config 

一些研究告诉我在HttpURLConnection类来设置这些属性。但我不知道该怎么做,或者至少如何从代码中获得HttpUrlConnection obj。

回答

1

您必须在公交级别进行设置。总线属性可以像下面这样配置。你不使用异步,所以不需要把这个属性。 此外,我会建议创建客户JaxWsClientFactoryBean SpringBus bus = new SpringBus(); bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); bus.setProperty("org.apache.cxf.transport.http.async.SO_KEEPALIVE",Boolean.TRUE); bus.setProperty("org.apache.cxf.transport.http.async.SO_TIMEOUT",Boolean.FALSE); bus.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS","totalConnections")); bus.setProperty("org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS","connectionsPerHost"));

+0

谢谢。但我不使用异步。您的示例仅适用于异步。它是否适用于同步通话? – David

+0

是的它适用于同步以及不要将其设置为false。 –

+0

再次感谢。你说“只是不要把它设置为假”。你的意思是bus.setProperty(AsyncHTTPConduit.USE_ASYNC,Boolean.TRUE); – David