0

I'm trying to import and use the interface HttpRequest.BodyPublisher

import jdk.incubator.http.HttpRequest.BodyPublisher;
...

HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = null;
try {
    response = client.send(
            HttpRequest
                    .newBuilder(configuration.getPostFileRequest())
                    .headers("Content-MD5", md5)
                    .POST(HttpRequest.BodyPublisher.fromFile(Paths.get(file.getPath())))
                    .build(),
            HttpResponse.BodyHandler.asString()
    );

And I got error when compiling

Error:(5, 38) java: cannot find symbol 
symbol:   class BodyPublisher  
location: class jdk.incubator.http.HttpRequest 
Error:(49, 35) java: cannot find symbol  
symbol:   variable BodyPublisher

How can I fix error or correct use?

module-info.java

module file.exchange.client {
    requires jdk.incubator.httpclient;
    requires java.logging;
}

Java version 10.0.1

Update: Compiled and ran fine when I used JDK11 and module java.net.http

  • Could you specify which IDE(intelliJ, eclipse etc) or build tool(maven, gradle etc) you are using to compile? Any of those relying on the classpath had to add `--add-modules jdk.incubator.httpclient `. Side note - That would [no more be required after migration to Java-11](https://stackoverflow.com/a/50122697/1746118) – Naman Jun 09 '18 at 02:30
  • Also, the above code compiles fine for me using the *module path* with **intelliJ 2018.2 CE EAP**. – Naman Jun 09 '18 at 02:37
  • @nullpointer I'm using intelliJ 2018.1.4 and `--add-modules jdk.incubator.httpclient` added to VM options – Alexandr Korzhenko Jun 11 '18 at 15:10

0 Answers0