[英]How do Jersey-client and Apache HTTP Client compare?
First of all, I'm not trying to start a flame-war here. 首先,我不是想在这里开始一场火焰战争。 I know Jersey sufficiently well, but have hardly used httpclient.
我非常了解泽西岛,但很少使用httpclient。
What are the key differences between jersey-client and Apache's httpclient? jersey-client和Apache的httpclient之间的主要区别是什么? In what areas is one better than the other?
哪个区域比另一个好? Is there a good comparison chart somewhere?
在某处有一个很好的比较图表吗? Which one performs better with larger files (say 2048 MB)?
对于较大的文件(比如2048 MB),哪一个表现更好?
Many thanks for your comments! 非常感谢您的评论!
These two things probably should not be compared directly. 这两件事可能不应该直接比较。 Jersey is a REST-client, featuring full JAX-RS implementation, neat fluent API and a powerfull filter stack.
Jersey是一个REST客户端,具有完整的JAX-RS实现,简洁流畅的API和强大的过滤器堆栈。 Apache Http Client is a HTTP-client, perfect in managing low-level details like timeouts, complex proxy routes and connection polling.
Apache Http Client是一个HTTP客户端,非常适合管理超时,复杂代理路由和连接轮询等低级细节。 They act on a different levels of your protocol stack.
它们作用于协议栈的不同级别。 When you're using Jersey there is always some kind of HTTP client backend involved.
当您使用Jersey时,总会涉及某种HTTP客户端后端。 Given no backend explicitly, Jersey will use
HttpUrlConnection
as a default backend. 如果没有显式后端,Jersey将使用
HttpUrlConnection
作为默认后端。
Jersey with HttpUrlConnection backend example: 泽西与HttpUrlConnection后端示例:
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/path");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
Jersey with Apache Http Client backend example: 泽西使用Apache Http Client后端示例:
HttpClient apacheClient = HttpClientBuilder.create().build();
Client client = new Client(new ApacheHttpClient4Handler(apacheClient,
new BasicCookieStore(),
true));
WebResource webResource = client.resource("http://localhost:8080/path");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
Please note usage of Handler in the last example. 请注意最后一个示例中Handler的用法。 This is a key integration abstraction for Jersey to incorporate and utilize various backends.
这是泽西岛的一个关键整合抽象,可以整合和利用各种后端。 First example uses
URLConnectionClientHandler
deep under the hood. 第一个例子深入使用
URLConnectionClientHandler
。
Speaking about performance and features it makes little sense to compare Apache Http Client with Jersey. 谈到性能和功能,将Apache Http Client与Jersey进行比较毫无意义。 One may want to compare different Jersey backends here, as Jersey itself is merely a wrapping API.
人们可能想在这里比较不同的泽西后端,因为泽西岛本身只是一个包装API。 I'd like to highlight some key differencies between HttpUrlConnection and Apache Http Client based on my own experience:
我想根据自己的经验强调HttpUrlConnection和Apache Http Client之间的一些关键差异:
HttpUrlConnection HttpURLConnection的
HttpUrlConnection
-based implementation is difficult to maintain and extend. HttpUrlConnection
的实现很难维护和扩展。 Apache Http Client Apache Http客户端
HttpUrlConnection
. HttpUrlConnection
。 Version 4.1 contains lots of performance enchancements and performs way better than it's counterpart HttpUrlConnection
also has an internal pooling, but you have no tools to customize what or when to pool, no monitoring facilities to check the pool state. HttpUrlConnection
还有一个内部池,但是你没有工具可以自定义什么或什么时候池,没有监控工具来检查池状态。 Keep in mind, that it also possible to use other backends (eg for non-blocking clients) with Jersey if you have an appropriate com.sun.jersey.api.client.ClientHandler
implementation. 请记住,如果您有适当的
com.sun.jersey.api.client.ClientHandler
实现,也可以使用Jersey的其他后端(例如,对于非阻塞客户端)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.