Become an early Java 9 expert: LJC + vJUG + JUGs Worldwide Hackday Feedback on JDK 9 EA
Chris Hegarty
chris.hegarty at oracle.com
Mon May 8 09:47:52 UTC 2017
Mani,
Expanding a little on Alex's comment regarding the new HTTP Client.
I added the following comment as a suggestion to the online doc.
On 06/05/17 05:42, Mani Sarkar wrote:
> ..
>> ➣ Query: HttpRequest cannot be used in JShell despite in documentation
>>
>> HttpRequest is an incubating feature, so the module that it lives in
>> will not be resolved by default, see http://openjdk.java.net/jeps/11
The new HTTP Client is being delivered in JDK 9 as an incubating
feature. It was previous proposed to be included in Java SE, but
later moved to incubating in JDK 9 b149. The link above to the
javadoc for HttpRequest clearly shows its previous package location.
This link is out of date. It is a bug in the documentation that this
link still works ( I’ll get that fixed ). JShell can be used with
the new HTTP Client as follows:
$ ./jdk-9_168/bin/java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+168)
Java HotSpot(TM) Server VM (build 9-ea+168, mixed mode)
$ ./jdk-9_168/bin/jshell --add-modules jdk.incubator.httpclient
| Welcome to JShell -- Version 9-ea
| For an introduction type: /help intro
jshell> import jdk.incubator.http.*;
jshell> import static jdk.incubator.http.HttpResponse.BodyHandler.*;
jshell> URI uri = new URI("http://openjdk.java.net/projects/jigsaw/");
uri ==> http://openjdk.java.net/projects/jigsaw/
jshell> HttpRequest request = HttpRequest.newBuilder(uri).build();
request ==> http://openjdk.java.net/projects/jigsaw/ GET
jshell> HttpResponse response =
HttpClient.newBuilder().build().send(request, discard(null));
response ==> jdk.incubator.http.HttpResponseImpl at 133814f
jshell> response.statusCode();
$6 ==> 200
-Chris.
More information about the jdk9-dev
mailing list