Home » Java » java 10 httpclient incubator GET request fails on node.js server

java 10 httpclient incubator GET request fails on node.js server

Posted by: admin May 17, 2018 Leave a comment


I’ve been experimenting with the HttpClient stuff in the Java 9/10 incubator, and have the following trivial code (virtually stolen from the project home page!):

URI uri = URI.create("");

HttpRequest getRequest = HttpRequest.newBuilder()

HttpResponse<String> response = client.send(getRequest,
System.out.println("response to get: " + response.body());

I find it works fine if it’s pointed at a URL that is not the localhost, but fails if I ask for the localhost (whether by the name “localhost”, by, or by the actual IP address of the local host). The error is very strange, and the entire stack trace does not mention any of my code.

WARNING: Using incubator modules: jdk.incubator.httpclient
Exception in thread "main" java.io.EOFException: EOF reached while reading
    at jdk.incubator.httpclient/jdk.incubator.http.Http1AsyncReceiver$Http1TubeSubscriber.onComplete(Http1AsyncReceiver.java:507)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:551)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:728)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowTask.run(SocketTube.java:171)
    at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
    at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:271)
    at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:224)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:675)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:829)
    at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:243)
    at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:769)
    at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:731)

There is a server running locally, and I can connect to it just fine using a simple request from a web browser.

Any thoughts?

[EDIT]I found, I beleive, the mail list for this project. It’s “obfuscated” (which fooled me completely!) but shown as: net dash dev at openjdk dot java dot net I’ll post there too, and see if they have any input.

[EDIT 2]I’m pretty sure that this has nothing to do with localhost (per original title) but is something in the protocol negotiation with node.js/express (which is the server I’m using because it’s easy to experiment with). Node occasionally (e.g. with a last line of text that’s not LF terminated) seems to report the wrong content-length, but this isn’t the problem, as the failure still occurs with correct length. I think it’s possibly a bug in the attempt to upgrade the connection to HTTP/2.0 but don’t know yet…

[EDIT 3]After wasting way too much of my life experimenting, I’m fairly sure that there’s something in the way node.js 8.11.1 (and express 4.13.4 and body-parser 1.15.1) handle a request to upgrade a to HTTP 2.0 that’s causing the problem. But I have no idea what. I’m giving up, and will continue the learning process for httpClient using a different server.