使用AsynchttpConductor CXF(JAVA)的非阻塞web服务客户端

使用AsynchttpConductor CXF(JAVA)的非阻塞web服务客户端,java,web-services,nonblocking,Java,Web Services,Nonblocking,我正在尝试用JAVA创建一个非I/O阻塞的web服务客户机。我正在使用来自CXF的AsynchttpConductor 然而,当有2个请求时,它似乎会创建一个新的连接,而不是重用它。它将创建新的动态端口来发送web服务 源代码: 公共分派getDispatcher(字符串别名、字符串命名空间、字符串wsdlLocation、字符串serviceName、字符串portName)引发IOException、GeneralSecurityException{ Dispatch<Sour

我正在尝试用JAVA创建一个非I/O阻塞的web服务客户机。我正在使用来自CXF的AsynchttpConductor

然而,当有2个请求时,它似乎会创建一个新的连接,而不是重用它。它将创建新的动态端口来发送web服务

源代码: 公共分派getDispatcher(字符串别名、字符串命名空间、字符串wsdlLocation、字符串serviceName、字符串portName)引发IOException、GeneralSecurityException{

    Dispatch<Source> dispatcher = getDispatcher(wsdlLocation, namespace, serviceName, portName);

    // Create our custom SSLSocketFactory
    SSLSocketFactory socketFactory = new SSLSocketFactoryGenerator(alias, keyStoreLocation, trustStoreLocation)
            .getSSLSocketFactory();

    Client client = ((org.apache.cxf.jaxws.DispatchImpl) dispatcher).getClient();
    client.getRequestContext().put("use.async.http.conduit", true);
    client.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    client.getRequestContext().put("org.apache.cxf.transport.http.async.MAX_CONNECTIONS", 501);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    System.out.println("testtest: "+conduit.getClass().getName());
    TLSClientParameters tlsClientParameters = new TLSClientParameters();
    tlsClientParameters.setSSLSocketFactory(socketFactory);
    conduit.setTlsClientParameters(tlsClientParameters);
    conduit.getClient().setConnection(ConnectionType.KEEP_ALIVE); 
    conduit.getClient().setReceiveTimeout(10000000L);

    return dispatcher;
}
Dispatch dispatcher=getDispatcher(wsdlLocation、命名空间、serviceName、portName);
//创建我们的自定义SSLSocketFactory
SSLSocketFactory socketFactory=新的SSLSocketFactoryGenerator(别名、密钥重定位、trustStoreLocation)
.getSSLSocketFactory();
Client Client=((org.apache.cxf.jaxws.DispatchImpl)dispatcher.getClient();
client.getRequestContext().put(“use.async.http.conductor”,true);
client.getRequestContext().put(AsynchttpConductor.USE\u ASYNC,AsynchttpConductFactory.UseAynchPolicy.ALWAYS);
client.getRequestContext().put(“org.apache.cxf.transport.http.async.MAX_CONNECTIONS”,501);
httpconductor=(httpconductor)client.getconductor();
System.out.println(“testtest:+conductor.getClass().getName());
TLSClientParameters TLSClientParameters=新的TLSClientParameters();
tlsClientParameters.setSSLSocketFactory(socketFactory);
导管.沉降参数(tlsClientParameters);
conductor.getClient().setConnection(ConnectionType.KEEP_活动);
conductor.getClient().setReceiveTimeout(10000000L);
返回调度员;
}
调用dispatcher以发送web服务:

Source requestSource = (new StreamSource(new StringReader(request)));
    MyHandler handler = new MyHandler();
    Future<?> f = dispatch.invokeAsync(requestSource, handler);
    Thread.sleep(3000);

    MyHandler handler2 = new MyHandler();
    Source requestSource2 = (new StreamSource(new StringReader(request)));
    Future<?> f2 = dispatch.invokeAsync(requestSource2, handler2);
sourcerequestsource=(新的StreamSource(新的StringReader(请求));
MyHandler=新的MyHandler();
Future f=dispatch.invokeAsync(requestSource,handler);
睡眠(3000);
MyHandler handler2=新的MyHandler();
SourceRequestSource2=(新的StreamSource(新的StringReader(请求));
Future f2=dispatch.invokeAsync(requestSource2,handler2);
日志文件:

08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.impl.nio.conn.managedNttpClientConnectionImpl-http-outgoing-0 127.0.0.1:13629127.0.0.1:8080[ACTIVE][rw:w]:写入542字节 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“POST/fghet/sd/qqwsdfdd?wsdl http/1.1[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“接受:/[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“用户代理:apache CXF 3.1.4.redhat-1[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“连接:保持活动[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“内容长度:323[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“内容类型:应用程序/soap+xml;字符集=UTF-8[\r][\n]” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.wire-http-outing-0>>“主机:本地主机:8080[\r][\n]” 08:24:35.491[I/O dispatcher 1]调试org.apache.http.wire-http-outing-0>>“[\r][\n]” 08:24:35.491[I/O dispatcher 1]调试org.apache.http.wire-http-outing-0>>“aaaaaaa 003yyyyyyyyy” 08:24:35.491[I/O dispatcher 1]DEBUG org.apache.http.impl.nio.conn.managedNttpClientConnectionImpl-http-outgoing-0 127.0.0.1:13629127.0.0.1:8080[ACTIVE][r:w]:事件已清除[w] 08:24:38.468[main]DEBUG org.apache.http.impl.nio.client.MainClientExec-[exchange:2]开始执行 08:24:38.469[main]DEBUG org.apache.http.client.protocol.RequestAddCookies-CookieSpec selected:default 08:24:38.469[main]DEBUG org.apache.http.client.protocol.RequestAuthCache-未在上下文中设置Auth缓存 08:24:38.469[main]DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient-[exchange:2]请求连接{}-> 08:24:38.469[main]DEBUG org.apache.http.impl.nio.conn.poolignHttpClientConnectionManager-连接请求:[路由:{}->保持活动状态:0;分配的路由:1000个中的1个;分配的总数:5000个中的1个] 08:24:38.470[I/O dispatcher 2]DEBUG org.apache.http.impl.nio.conn.poolignHttpClientConnectionManager-租用连接:[id:http-outing-1][路由:{}->保持活动状态:0;分配的路由:1000个路由中的2个;分配的总数:5000个路由中的2个] 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.InternalHttpAsyncClient-[exchange:2]已分配连接:CPoolProxy{http-outing-1[ACTIVE]} 08:24:38.470[I/O dispatcher 2]DEBUG org.apache.http.impl.nio.conn.managedNttpClientConnectionImpl-http-outing-1 127.0.0.1:13630127.0.0.1:8080[ACTIVE][r:]:设置属性http.nio.exchange-handler 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.conn.managedNttpClientConnectionImpl-http-outgoing-1 127.0.0.1:13630127.0.0.1:8080[ACTIVE][rw:]:事件集[w] 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.conn.managedNttpClientConnectionImpl-http-outgoing-1 127.0.0.1:13630127.0.0.1:8080[ACTIVE][rw:]:设置超时0 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.internalioidispatch-http-outing-1[活动]:已连接 08:24:38.470[I/O dispatcher 2]DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl-http-outing-1127.0.0.1:13630127.0.0.1:8080[ACTIVE][rw:]:设置属性http.nio.http-exchange-state 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.InternalHttpAsyncClient-启动连接路由 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.MainClientExec-已建立连接路由 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.MainClientExec-[exchange:2]尝试1执行请求 08:24:38.470[I/O dispatcher 2]DEBUG org.apache.http.impl.nio.client.MainClientExec-目标身份验证状态:未被质询 08:24:38.470[I/O dispatcher 2]调试org.apache.http.impl.nio.client.MainClientExec-代理