Class HTTP2

java.lang.Object
com.storedobject.common.HTTP2

public class HTTP2 extends Object
The HTTP2 class facilitates HTTP/2 client-server communication with helper methods and a builder pattern for request customization. It leverages Java's HttpClient for synchronous and asynchronous HTTP calls and provides utilities for handling and parsing responses.

Note: This utility class can transparently handle chunked and compressed (zipped or deflated) content as well.

Features:

  • Connection pooling optimization with custom client caching
  • Automatic retry mechanism for transient failures
  • Configurable debug logging with custom log destinations
  • Proper handling of chunked transfer encoding
  • Automatic decompression of gzip/deflate responses
  • Virtual threads executor for async operations (Java 21+)
     Typical usage:
     String s = HTTP2.build("https://www.google.com").string();
     System.out.println("Google's default page's content is: " + s);

     JSON json = HTTP2.build("https://www.example.com?api=xxx").json(); // Get the JSON content

     // With retry and custom logger
     HTTP2.setLogWriter(new PrintWriter(System.out));
     String data = HTTP2.builder("https://api.example.com/data")
         .retry(3, Duration.ofMillis(500))
         .debug()
         .string();
 
Author:
Syam