import org.glassfish.grizzly.http.*;
import org.glassfish.grizzly.http.client.*;
import org.glassfish.grizzly.EmptyCompletionHandler;
public class GrizzlyHttpClientExample {
public static void main(String[] args) {
HttpClient httpClient = HttpClient.createInstance();
String url = "https://example.com/api/data";
HttpRequestPacket.Builder requestBuilder = HttpRequestPacket.builder()
.method(HttpMethod.GET)
.uri(url);
httpClient.send(requestBuilder.build(), new EmptyCompletionHandler<HttpContent>() {
@Override
public void completed(HttpContent result) {
String response = result.getContent().toStringContent();
System.out.println(response);
}
@Override
public void failed(Throwable throwable) {
throwable.printStackTrace();
}
});
httpClient.waitForPendingRequests();
httpClient.shutdownNow();
}
}
httpClient.setReadTimeout(5000);
httpClient.setConnectTimeout(5000);
httpClient.getOptions().setKeepAlive(true);
httpClient.getOptions().setMaxPoolSize(100);
Disclaimer: The code provided is a simplified example for demonstration purposes only, and may not include certain error handling and production-ready best practices. It is recommended to further enhance the code as per the specific application requirements and follow the official Grizzly Async HTTP Client documentation.