views:

1357

answers:

7

We're implementing a REST client on JRE 1.4.

Seems two good options for a client REST framework are HttpClient and HttpUrlConnection.

Is there a reason to use HttpClient over the JRE's HttpUrlConnection?

A: 

In my experience HttpClient is slightly easier and more intuitive to use than using HttpUrlConnection, but I think it's a very subjective decision and YMMV.

Aditya
+1  A: 

I'd go with the JRE version just so I would have one less dependency to ship around.

Eric
This comparison looks kinda dated
jitter
Some of us don't have the luxury of using the latest versions of **anything** :-(
Michael Rutherfurd
A: 

The HttpUrlConnection is easy to handle. REST implementations are quite simple.

Although you must consider the whole environment about this implementation and check what will work better for you.

jonaspp
+2  A: 

The Restlet Framework also has an API which works both server-side and client-side. We support pluggable client connectors, leveraging HttpURLConnection or Apache HTTP Client or our own internal HTTP client.

Our ClientResource class provides a higher level HTTP client API, with features like automatic redirection, transparent conversion between objects and representations, content negotiation and more.

Best regards,

Jerome Louvel

Restlet ~ Founder and Lead developer ~ http://www.restlet.org

Noelios Technologies ~ Co-founder ~ http://www.noelios.com

Jerome Louvel
We're on 1.4 - does Restlet work on 1.4?
Marcus
@Marcus: Yes, it does, I'm using Restlet's client right now in Java 1.6 and it's a dream. (We have it configured to sit on top of Apache HTTP Client, which is much better than java.net.HttpUrlConnection.)
Jim Ferrans
+1  A: 

I'll give you a single, concrete reason to favour Apache's HTTPClient over the JDK implementation: The JDK's HttpUrlConnection doesn't support timeouts, Apache's HTTPClient does.

Applications should always have the ability to set timeouts when calling into other systems (databases, remote services, your own server backend, ...).

hbunny
Not true! This was fixed in Java 1.5.
Jim Ferrans
I stand corrected. Good to know (it's on the URLConnection class).
hbunny
Good point. We're on 1.4 so this appears totally relevant.
Marcus
+1  A: 

I would recommend Jakarta Commons HTTP Client over java.net.HttpUrlConnection as it is more mature and has a richer feature set. For example you can ask it to set up multi-threaded connection pool (see MultiThreadedHttpConnectionManager), and it has full support for all the HTTP methods (GET, PUT, POST, DELETE, OPTIONS, TRACE).

Jim Ferrans
A: 

... httpclient does not support kerberos/ntlm authentication for proxies etc... java's httpurlconnection will do authentication out of the box...

helmut