验证CXF HttpAsyncClient使用use.async.http.conduit上下文属性 [英] Verifying CXF HttpAsyncClient use of use.async.http.conduit contextual property

查看:712
本文介绍了验证CXF HttpAsyncClient使用use.async.http.conduit上下文属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图利用CXF异步HTTP客户端传输,通过设置use.async.http.conduit属性,如<详细href=\"http://stackoverflow.com/questions/20497003/using-cxf-httpasyncclient-through-setting-use-async-http-conduit-contextual-prop\">this螺纹,并通过这CXF文章建议。结果

I am trying to make use of the CXF asynchronous HTTP client transport, through setting the "use.async.http.conduit" property, as detailed in this thread, and recommended by this CXF article.

我这样做,用下面的code:结果


I do that using the following code:


Client client = ClientProxy.getClient(wsClient);
client.getRequestContext().put("use.async.http.conduit", Boolean.TRUE);



碰巧的是,我的Web服务调用超时(可能是由于一些环境问题的网络)和我的客户异常包含(摘录):结果


As it happens, my web service call is timing out (probably due to some environmental network issue), and my client exception contains (extract):

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:698)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:641)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1218)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
    at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.getResponseCode(URLConnectionHTTPConduit.java:260)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1513)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1486)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1305)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)


的异常堆栈之上表明 java.net.HttpURLConnection中的类是仍在使用,而且基于CXF文档的设置还没有生效的。


The exception stack above suggests that the java.net.HttpURLConnection class is still in use and that based on the CXF documentation the setting has not taken effect.

我试图找出是如何确保use.async.http.conduit已生效,即是有一个特定的行为进行检验,或特定的日志配置,我可以启用该客户端会肯定地告诉我在Apache HttpAsyncClient在使用?

What I am trying to figure out is how to ensure that the "use.async.http.conduit" has taken effect, i.e. is there a particular behaviour that can be tested, or a particular log config that I can enable on the client that would undoubtedly tell me the Apache HttpAsyncClient is in use?

非常感谢:)

推荐答案

我刚刚找到了答案,我的问题,通过的 CXF文档和的有用博客。搜索结果
因此,首先如何识别默认的Java客户端传输或Apache的异步传输客户端是否被使用:搜索结果
除了code我使用(见问题)

I just found the answer to my question, inspired by more reading of the CXF documentation, and of a useful blog.

So first how to identify whether the default Java transport client or the Apache async transport client is used:

In addition to the code I was using (see question)

Client client = ClientProxy.getClient(wsClient);
client.getRequestContext().put("use.async.http.conduit", Boolean.TRUE);

我添加以下内容:

I added the following:

HTTPConduit conduit = (HTTPConduit)client.getConduit();
System.out.println(conduit.getClass().getName());

这最初产生

org.apache.cxf.transport.http.URLConnectionHTTPConduit

这跟我的设置不能正常工作。这时候,阅读更多CXF文件后,我意识到我缺少的依赖(库在我的类路径): CXF-RT-运输-HTTP-HC 。所以我增加了图书馆在我的Maven依赖关系:

which told me the setting was not working. That is when, after reading more of the CXF documentation, I realised I was missing a dependency (library on my classpath): cxf-rt-transports-http-hc. So I added the library in my maven dependencies:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-hc</artifactId>
    <version>${cxf.version}</version>
</dependency>

然后重试我的code,输出现在来代替:

then retried my code, and the output was now instead:

org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit

瞧!

这篇关于验证CXF HttpAsyncClient使用use.async.http.conduit上下文属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆