import co.paralleluniverse.fibers.httpclient.FiberHttpClientBuilder;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
try (CloseableHttpAsyncClient httpClient = FiberHttpClientBuilder.create().build()) {
httpClient.start();
HttpGet request = new HttpGet("https://example.com");
httpClient.execute(request, new HttpResponseCallback());
}
}
static class HttpResponseCallback implements FutureCallback<HttpResponse> {
public void completed(HttpResponse response) {
System.out.println("Response received: " + response.getStatusLine());
}
public void failed(Exception ex) {
System.out.println("Request failed: " + ex.getMessage());
}
public void cancelled() {
System.out.println("Request cancelled.");
}
}
}
<dependency>
<groupId>co.paralleluniverse</groupId>
<artifactId>comsat-httpclient</artifactId>
<version>VERSION</version>
</dependency>