All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.http.client.JdkHttp2ClientHttpRequest Maven / Gradle / Ivy

The newest version!
package org.springframework.http.client;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.Objects;

class JdkHttp2ClientHttpRequest extends AbstractBufferingClientHttpRequest {

    private final HttpClient client;
    private final URI uri;
    private final HttpMethod method;
    private final Duration readTimeout;

    public JdkHttp2ClientHttpRequest(final HttpClient client, final URI uri, final Duration readTimeout) {
        this(client, uri, HttpMethod.GET, readTimeout);
    }

    public JdkHttp2ClientHttpRequest(final HttpClient client, final URI uri, final HttpMethod method,
        final Duration readTimeout) {
        this.client = Objects.requireNonNull(client, "client");
        this.uri = Objects.requireNonNull(uri, "uri");
        this.method = Objects.requireNonNull(method, "method");
        this.readTimeout = readTimeout;
    }

    @Override
    public HttpMethod getMethod() {
        return this.method;
    }

    @Override
    public String getMethodValue() {
        return this.method.name();
    }

    @Override
    public URI getURI() {
        return this.uri;
    }

    @Override
    protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
        HttpRequest request = JdkHttp2ClientHttpRequestFactory.buildRequest(headers, bufferedOutput, getURI(),
            getMethodValue(), readTimeout);
        try {
            HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            return new JdkHttp2ClientHttpResponse(response);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOException(e);
        } finally {
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy