File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ This repository contains Java examples that are designed to track and document t
1111## Specifications & Practices
1212
1313* [ Java 26] ( java-26/ ) (March, 2026)
14+ * [ JEP 517] ( java-26/src/main/java/JEP517HTTP3ForTheHTTPClientAPI.java ) : HTTP/3 for the HTTP Client API
1415 * [ JEP 500] ( java-26/src/main/java/JEP500PrepareToMakeFinalMeanFinal.java ) : Prepare to Make Final Mean Final
1516* [ Java 25] ( java-25/ ) (September, 2025)
1617 * [ JEP 513] ( java-25/src/main/java/JEP513FlexibleConstructorBodies.java ) : Flexible Constructor Bodies
Original file line number Diff line number Diff line change 1+ import java .net .URI ;
2+ import java .net .http .HttpClient ;
3+ import java .net .http .HttpRequest ;
4+ import java .net .http .HttpResponse ;
5+ import java .net .http .HttpClient .Version ;
6+
7+ public class JEP517HTTP3ForTheHTTPClientAPI {
8+ static void main () {
9+ try {
10+ // 1. Configure the HttpClient to prefer HTTP/3
11+ // If the server does not support HTTP/3, it will automatically fallback to HTTP/2
12+ HttpClient client = HttpClient .newBuilder ()
13+ .version (Version .HTTP_3 )
14+ .build ();
15+
16+ // 2. Create the request for an HTTP/3 enabled endpoint
17+ HttpRequest request = HttpRequest .newBuilder ()
18+ .uri (URI .create ("https://quic.rocks:4433/" ))
19+ .GET ()
20+ .build ();
21+
22+ // 3. Send the request and receive the response synchronously
23+ HttpResponse <String > response = client .send (request , HttpResponse .BodyHandlers .ofString ());
24+
25+ // 4. Output the results to the console
26+ System .out .println ("Protocol Used: " + response .version ());
27+ System .out .println ("Status Code: " + response .statusCode ());
28+ System .out .println ("Response Body (Preview): " + response .body ().substring (0 , 100 ) + "..." );
29+
30+ } catch (Exception e ) {
31+ // Handle potential network or protocol exceptions
32+ System .err .println ("Error during HTTP/3 request: " + e .getMessage ());
33+ e .printStackTrace ();
34+ }
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments