【问题标题】:how to set property maxConnection in cxf cilent code如何在 cxf 客户端代码中设置属性 max Connection
【发布时间】:2017-06-01 07:34:00
【问题描述】:

我正在开发 cxf 客户端。我从 wsdl 生成存根并从那里开发代码。我的代码是这样的

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。

【问题讨论】:

    标签: connection cxf httpurlconnection httpconnection cxf-client


    【解决方案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"));

    【讨论】:

    • 谢谢。但我不使用异步。您的示例仅用于异步。它适用于同步呼叫吗?
    • 是的,它也适用于同步,只是不要将其设置为 false。
    • 再次感谢。您说“只是不要将其设置为假”。你是说bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
    • 哦,我的错,我的意思是把它设置为 false。bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.FALSE); 基本上 CXF 优先考虑异步,但同时它也以相同的方式接受同步客户端的配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多