sentence
stringlengths
1
1.38k
label
stringclasses
3 values
We used COMET in conjunction with JMS using URL_http://www.ibm.com/developerwo rks/websphere/techjournal/0802%5Fhaverlock/0802%5Fhaverlock.html [WAS-Web-2.0 -Feature-Pack] ; in effect the server did the JMS subscribe and COMET-pushed the message to the browser.
o
as a developer it "felt" like the browser was subscribing to JMS.
o
This "just worked" so we didn't look further for alternatives.
o
I could imagine a pure JavaScript JMS implementation in the browser, using HTTP as a transport but my instict is that this would be very heavyweight.
n
I know of no such implementations.
o
The alternative approach to those already discussed (i.e.
o
Comet etc.
o
) is to implement polling in the client.
o
The downside of that approach is that you inevitably have a delay from the time of the message/event and until the client receives it.
n
If your application is very sensitive to such delays, polling is out.
o
If a certain amount of delay (at minimum in the order of a few seconds) is acceptable, polling is less of an abuse of the HTTP protocol.
n
It is also more robust against temporary network troubles as the server by default queues messages and wont get upset if the client isn't available on its schedule.
p
There is really no big difference between polling and long-lived connections.
o
In both cases you initate a poll, and it will return immediatelly, or with some delay.
o
The longer the delay is the less connections you have to open.
n
In all cases problems like terminated or unanswered calls are just lead to the next poll.
n
Inside the HTTP/1.1 the (TCP)connection typically stays open.
o
Alternatives to Apache HttpComponents?
o
So, I've come to the conclusion that Apache HttpComponents 4 is one of the most overwrought APIs I've ever come across.
n
Things that seem like they should be simple are taking hundreds of lines of code (and I'm _still_ not sure resources get cleaned up correctly).
p
Plus it wants me to do things like: CODESNIPPET_JAVA1 .
o
Which, just... no.
o
I know it's Java, and we're not into the whole brevity thing, but that's a little much.
n
Not to mention the jars are up to 700KB.
o
Anyway, enough ranting, I wanted to see what kind of experiences people have had with other HTTP client libraries?
o
The ones I'm aware of are: URL_http://docs.codehaus.org/display/JETTY/Jetty+HTTP+Client [Jetty] , URL_http://hotpotato.biasedbit.com/ [hotpotato] , and URL_https://github.com/sonatype/async-http-client [AsyncHttpClient] .
o
This is for server-side use, I'm mostly interested in performance for many concurrent gets and large file transfers.
o
Any recommendations?
o
PS I know the venerable HttpClient 3.1 is still there, but I'd like to use something that's supported.
p
Update @oleg: this is what the docs suggest: CODESNIPPET_JAVA2 .
o
I still get unexpected errors when consuming entity content when using CODETERM1 .
o
I'm sure it's my fault, but at this point I don't really want to have to figure it out.
n
Hey, I don't mean to disparage anyone's work here, but I've been making a good-faith effort to use HttpComponents since 4.0 came out and it's just not working for me.
n
While not flawless, have you considered the standard URLConnection/HTTPUrlConnection ?
o
Having to call InputStream#close() to release allocated resources is massively over-complex, isn't it?
o
I would really like to hear what you have discovered since posting this.
o
I'm in the same boat :).
o
Adding a comment since the Jetty http client link mentioned above is so so old, here is the actual client docs.
o
URL_https://www.eclipse.org/jetty/documentation/current/http-client.html .
o
Complexity of HttpClient API simply reflects the complexity of its problem domain.
o
Contrary to a popular misconception HTTP is a fairly complex protocol.
n
Being a low level transport library HC 4.0 API was primarily optimised for performance and flexibility rather than simplicity.
n
It is regrettable that you are not able to figure it out, but so be it.
o
You are welcome to use whatever library that suits your needs best.
p
I personally like Jetty HttpClient a lot.
o
It is a great alternative that might work better for you.
p
I agree with both you (+1) and the OP.
o
The power and flexibility is necessary, but there should also a set of facade methods somewhere that simplify the process.
o
Methods like public static InputStream httpGetAsStream(String baseUrl, Map<string, object=""> parameters).
o
HTTP is complex, but Apache's HttpComponents library ridiculously over- engineered and contains a lot of complexity not essential to protocol operation.
n
It objectively has a really bad API.
n
@Alex B: HttpComponents are being used in all sorts of different applications randing from simple URL fetchers to complex transports and web crawlers with different, often conflicting requirements.
n
What may seem as non-essential to some can be absolutely essential to others.
o
HttpClient has to deal with several dozen customization parameters and context specific strategies and objects.
o
So, flexibility has to come before simplicity.
o
For those who are not able to wrap their head around HttpClient API there is fluent facade API: URL_http://hc.apache.org/httpcomponents-client-dev/fluent-hc/index.html .
o
"Complexity of HttpClient API simply reflects the complexity of its problem domain.
o
" If HC 4.0 was perfect then that would be a good point, but it is not.
p
It has many problems and I imagine a lack of direction lead it into the mess it is today.
n
I think Alex B is right when he says that objectively the API is bad and could have been better.
n
Could have been.
o
Answering my own question since this got resurrected for some reason.
o
I ended up writing a few simple wrappers around CODETERM1 , seems it's come a long way since the last time I seriously considered it.
n
HttpComponents is great, but can be overkill for simple tasks.
p
Also, at least in my scenario, HUC is noticeably faster (mostly single-threaded, haven't done any testing under heavy load).
n
HttpURLConnection instances are significantly cheaper to create than due to the fact that they share one static JRE wide pool of connections.
n
Per default HttpClient always creates a new pool of connections and therefore is slower to start up and warm up.
n
One can address this problem by re-using the same instance of HttpClient for new requests.
o
This approach is used by HttpClient's fluent facade, for isntance: URL_http://hc.apache.org/httpcomponents-client-dev /fluent-hc/index.html.
o
In all other cases I can think of HttpClient should be comfortably faster.
p
Maybe I'm doing something wrong, this isn't exactly rigorous benchmarking.
n
I do always use a single HttpClient instance.
o
Just ran a quick test: fetching from localhost, very small document (150 bytes) x 5000 times takes roughly 10 seconds with HttpClient (4.1) and under 2 seconds with HUC.
o
This actually isn't just academic, my main use-case is lots of small lookups against services on the same machine.
o
I can only give you my (biased) perspective.
o
Any HTTP performance test that lasts 2 second is simply not representative.
o
One need to be running the benchmark for a few minutes to get more or less reliable numbers.
o
Here is the benchmark and some results that we use internally: URL_http://wiki.apache.org/HttpComponents/HttpClient3vsHttpClient4vsHttpCore .
o
HttpClient 4.x performance seems to be quite all right compared to HUC and other clients.
o
Of course.
o
Like I said, it's by no means a comprehensive benchmark.
o
Then again, in _my_ particular case, which is not covered by your benchmark, there is a noticeable difference.
o
I would not generalize from that (certainly isn't representative), but it does factor into my decision of what to use in my scenario.
o
For simple use cases you can use URL_http://hc.apache.org/httpcomponents- client-ga/fluent-hc/ [HttpClient-Fluent-API] .
p
See URL_https://hc.apache.org /httpcomponents-client-ga/tutorial/html/fluent.html [tutorials] .
o
This module provides an easy to use facade API for HttpClient based on the concept of a fluent interface.
p
Fluent facade API exposes only the most fundamental functions of HttpClient and is indended for simple use cases that do not require the full flexibility of HttpClient.
p
For instance, fluent facade API relieves the users from having to deal with connection management and resource deallocation CODESNIPPET_JAVA1 .
o
Maven artifact.
o
CODESNIPPET_JAVA2 .
o
You could use URL_http://www.jboss.org/netty [Netty] or URL_http://mina.apache.org/ [Apache-Mina] albeit they are very low level and I'm not sure you will end up with less verbose code.
n
HTTPUnit has a great interface (not much code needed), but the latest version of it submits duplicate requests.
p
HTMLUnit will work, but for me it has seemed to have limited support for Javascript.
o
I'vebeen able to use it for basic web pages though.
o
You could have a look at URL_http://www.restlet.org [Restlet] 's client capabilities.
o
It's a layer above that can be supported by Apache HttpComponents or Java's Net API for example.
o
I've used Jersey's client, which is conceptually pretty similar.
o
It is pretty convenient for a lot of cases.
o
How to send HTTP request in java?
o
I want to compose a HTTP request message in java and then want to send it to a HTTP WebServer.I also want the document content of the page recieved which I would have recieved if I had sent the same HTTP request from a webpage.
o