Search in sources :

Example 41 with HttpClient

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));
}
Also used : HttpRequest(java.net.http.HttpRequest) HttpClient(java.net.http.HttpClient) HttpResponse(java.net.http.HttpResponse) URISyntaxException(java.net.URISyntaxException)

Example 42 with HttpClient

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;
}
Also used : HttpRequest(java.net.http.HttpRequest) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JsonElement(com.google.gson.JsonElement) HttpClient(java.net.http.HttpClient) Duration(java.time.Duration) JsonParser(com.google.gson.JsonParser)

Aggregations

HttpClient (java.net.http.HttpClient)42 Authenticator (java.net.Authenticator)11 HttpRequest (java.net.http.HttpRequest)8 HttpResponse (java.net.http.HttpResponse)6 URI (java.net.URI)4 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)4 RDFFormat (org.apache.jena.riot.RDFFormat)4 Context (org.apache.jena.sparql.util.Context)4 SerializedClassRunner (io.pravega.test.common.SerializedClassRunner)3 TestUtils (io.pravega.test.common.TestUtils)3 URISyntaxException (java.net.URISyntaxException)3 Duration (java.time.Duration)3 Pattern (java.util.regex.Pattern)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 Cleanup (lombok.Cleanup)3 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 Counter (io.pravega.shared.metrics.Counter)2