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?
You do not need to explicitly close the HttpClient, however, (you may be doing this already but worth noting) you should ensure that connections are released after method execution. Edit: The ClientConnectionManager within the HttpClient is going to be responsible for maintaining the state of connections.
Is there any way to use it in java 8? No, because the jdk. incubator. http module has been added since Java 9.
URLConnection is the base class. HttpURLConnection is a derived class which you can use when you need the extra API and you are dealing with HTTP or HTTPS only. HttpsURLConnection is a 'more derived' class which you can use when you need the 'more extra' API and you are dealing with HTTPS only.
The method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance. The method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.
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).
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, ...).
* This was fixed in Java 1.5; Java 1.5 and higher support timeouts in HttpUrlConnection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With