use of java.net.http.HttpClient in project feign by OpenFeign.
the class Http2Client method execute.
@Override
public CompletableFuture<Response> execute(Request request, Options options, Optional<Object> requestContext) {
HttpRequest httpRequest;
try {
httpRequest = newRequestBuilder(request, options).build();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid uri " + request.url(), e);
}
HttpClient clientForRequest = getOrCreateClient(options);
CompletableFuture<HttpResponse<byte[]>> future = clientForRequest.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofByteArray());
return future.thenApply(httpResponse -> toFeignResponse(request, httpResponse));
}
use of java.net.http.HttpClient in project eclipse.jdt.ls by eclipse.
the class MavenCentralIdentifier method find.
private ArtifactKey find(String searchUrl, IProgressMonitor monitor) throws IOException, InterruptedException {
Duration timeout = Duration.ofSeconds(10);
HttpClient client = HttpClient.newBuilder().connectTimeout(timeout).proxy(ProxySelector.getDefault()).version(Version.HTTP_2).build();
HttpRequest httpRequest = HttpRequest.newBuilder().timeout(timeout).uri(URI.create(searchUrl)).GET().build();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
if (monitor.isCanceled()) {
return null;
}
// TODO implement request cancellation, according to monitor status
HttpResponse<String> response = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
JsonElement jsonElement = new JsonParser().parse(response.body());
if (jsonElement != null && jsonElement.isJsonObject()) {
return extractKey(jsonElement.getAsJsonObject());
}
return null;
}
Aggregations