Questions tagged [java-http-client]

This tag should be used for questions which relate specifically to the new JDK 11 `java.net.http` package which includes new classes and interfaces such as HttpClient, HttpRequest, HttpResponse, and WebSocket. This tag should not be used for questions which relate to HTTP handling with the older `java.net` package. This tag can be used for questions about the incubator versions of this package, but do make the JDK version clear in such cases.

This tag should be used for questions which relate specifically to the new Java HTTP Client and WebSocket APIs in package java.net.http which was formally introduced in JDK 11 and includes new classes and interfaces such as HttpClient, HttpRequest, HttpResponse, and WebSocket.

This tag should not be used for questions which relate to HTTP handling with the older java.net package, and it should not be used for questions about third-party HTTP libraries (such as Apache HttpClient, org.apache.http). Search the tags page for tags specific to third-party HTTP libraries.

Note that an incubator version of this new framework was included in JDK 9 and JDK 10. There are significant differences between the incubator versions and the finalised version which was released in JDK 11.

This tag can be used to ask questions about the incubator versions of this new package, but in such cases the question should clearly state the JDK version and make it clear that an incubator version of the framework is being discussed. Such questions should also be tagged with or to make it clear that an older JDK is being used.

179 questions
8
votes
2 answers

Java 9 HttpClient java.lang.NoClassDefFoundError: jdk/incubator/http/HttpClient

I am trying to use the HttpClient from incubator in Java 9 maven project. I am not getting any Compilation issue. The project builds successfully. But when I try to run the Main class, it gives me the following exception: Exception in thread "main"…
parth karia
  • 230
  • 2
  • 7
7
votes
1 answer

Can't make more than one request on java.net.http.HttpClient or will receive: javax.net.ssl.SSLHandshakeException

I was testing out the new HttpClient from Java 11 and came across the following behaviour: I am making two Async requests to a public REST API for testing and tried it with one client and two separate requests. This process didn't throw any…
7
votes
1 answer

Java9 HttpClient SSLHandshakeException

I am trying to test new HttpClient from Java 9. For test purpose I am using api provided by https://jsonplaceholder.typicode.com. However, I am receiving an handshake exception and do not know the reason. The code I am running: private final…
Adam
  • 884
  • 7
  • 29
7
votes
0 answers

How to suppress "using incubating module(s)" compiler warning?

I would like my build to break if any compiler warnings occur, so I enabled -Werror. At some point later on I decided to use Java 9 HttpClient which is an incubating module. Unfortunately, I now get the following compiler warning: using incubating…
Gili
  • 86,244
  • 97
  • 390
  • 689
6
votes
2 answers

How can I use JDK 11 HTTP packages in Android

I am a Web Applications developer using J2EE Technology. I have made extensive use of Oracle's / OpenJDK's HTTP packages, as I find them more comfortable fo…
Nandhan Thiravia
  • 360
  • 2
  • 12
6
votes
1 answer

How to create a custom BodyPublisher for Java 11 HttpRequest

I'm trying to create a custom BodyPublisher that would deserialize my JSON object. I could just deserialize the JSON when I'm creating the request and use the ofByteArray method of BodyPublishers but I would rather use a custom publisher. public…
Challe
  • 599
  • 4
  • 19
6
votes
1 answer

JDK11 HttpClient mutual tls

I'm looking to use the new HttpClient provided in java 11. It's not clear how to do mutual TLS (2 way auth, where both client and server present a certificate.) Could someone provide an example of mutual TLS with HttpClient?
fafrd
  • 1,017
  • 13
  • 17
6
votes
1 answer

Is there any handling of connection pooling on java.net.HttpClient?

I want to use Java 11 HttpClient and send multiple requests on the same address with the use of the Keep-Alive parameter of HTTP 1.1. I know that there is similar functionality for Apache HTTP Client, but is there anything like that for Java API's…
6
votes
1 answer

Connections leaking with state CLOSE_WAIT with java.net.HttpClient

We are using openJDK11.0.6 java.net.http HTTP (HTTP1.1) client to fetch content from websites. After a long execution time, we noticed a performance decrease. CPU is 100% used even when the app does nothing. We were able to determine that it comes…
Gregoire
  • 142
  • 8
6
votes
1 answer

How to download and process large data reactively?

I need to initiate download of some content over HTTP and then read the data as a reactive stream. So, even though the downloaded data are big, I can almost immediately read the first few bytes of the response body (no need to wait for the whole…
Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65
6
votes
2 answers

How can I use Http Client API(since java 9) in Java8 project

Java 9 imports a new HTTP/2 Client API which seems good to use but is there any way to use it in Java 8? OR Is there any shim/polyfill(from javascript) available to make it available in Java 8?
Ian Hu
  • 295
  • 3
  • 7
5
votes
0 answers

Is it a good practice to define java.net.http.HttpClient instance attributes?

I'm using JDK HttpClient to make some asynchronous HTTP requests. In particular I have a class similar to the following one: public class MyClass { private HttpClient client; public MyClass(){ client = HttpClient.newBuilder() …
caristu
  • 115
  • 1
  • 5
5
votes
1 answer

JDK 11 HttpClient: BindException: Cannot assign requested address

I am using the new HttpClient shipped with JDK 11 to make many requests (to Github's API, but I think that's irrelevant), especially GETs. For each request, I build and use an HttpClient, like this: final ExecutorService executor =…
amihaiemil
  • 623
  • 8
  • 19
5
votes
1 answer

Kotlin Coroutine Scope : Is return@runBlocking an issue if used in Controller Endpoint

Purpose: I want to code an Endpoint which consume another Endpoint taking advantage of light Coroutines assuming I am coding a light assyncronous EndPoint client. My background: first time trying to use Kotlin Coroutine. I have studied last days and…
Jim C
  • 3,957
  • 25
  • 85
  • 162
5
votes
1 answer

HttpClient close connection

I would like to ask if this code after execution is auto-closing the connection. Also if it fail and crash, is it still going to close connection? HttpClient.newHttpClient().send( HttpRequest.newBuilder() .uri(URI.create("url_website")) …
1 2
3
11 12