What is the main Java way to create an HTTP connection in 2016?

I look at the HttpURLConnection , existing with JDK 1.1 , 1997 (almost 20 years), and I am very surprised that it is still the main Java core for creating HTTP connections.

Since it was published, many libraries tried to simplify (/ upgrade) the use of HTTP connections, such as Apache HttpClient .

Other libraries have tried to simplify REST HTTP calls, such as Jersey .

As far as I could find, the HttpURLConnection wrapper was not added to the HttpURLConnection .

Is HttpURLConnection still the main Java core for creating an HTTP connection?

If not, what is the official way?

+8
source share
2 answers

The old HttpURLConnection is currently the standard way to make HTTP requests in Java SE.

Java EE 7 introduced the JAX-RS Client API , which is the standard way to use REST web services built on top of the HTTP protocol.

And Java SE 9, to be released in 2017, will bring a new HTTP client API that implements HTTP / 2 and WebSocket and can replace the deprecated HttpURLConnection API. The motivation for the new API is described in JEP 110 :

The existing HttpURLConnection API and its implementation have numerous problems:

  • The base URLConnection API has been designed with several protocols in mind, almost all of which are now down (ftp, gopher, etc.)
  • The API precedes HTTP / 1.1 and is too abstract.
  • Difficult to use, with many undocumented behavior.
  • It only works in blocking mode (i.e., one thread per request / response).
  • It is very difficult to maintain.
+6
source

Yes. HTTPUrlConnection is currently official. (If by "official" you mean "a method supported by standard Java class libraries".)

Many people / groups have tried to come up with alternative ways to work with the HTTP client protocol with varying degrees of success. However, the old ("official") method still works, and for many cases it works well enough that there is no need for an alternative.

Java has a strong backward compatibility culture. If the function works, it remains at rest. Even functions that do not work properly are usually designated as "deprecated" 1 if they cannot be fixed in a backward compatible way. There is a good reason for this. Oracle makes money in Java from support contracts and specialized products. Their main customers are computer scientists. Computer scientists want the applications they wrote 20 years ago to continue to work ... without constantly interfering with things that break when the platform is updated (i.e. Java).

See @ CΓ‘ssio for information on what happens in Java 9 (next year).

1 - There are Java APIs that are deprecated in JDK 1.1 ... and are still supported.

+4
source

All Articles