net.pennix.http.client.JavaNetHttpClientHttpHttpResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-net-http-request-factory Show documentation
Show all versions of java-net-http-request-factory Show documentation
Spring ClientHttpRequestFactory implementation using java 11 java.net.http
The newest version!
package net.pennix.http.client;
import java.io.IOException;
import java.io.InputStream;
import java.net.http.HttpResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.AbstractClientHttpResponse;
public class JavaNetHttpClientHttpHttpResponse extends AbstractClientHttpResponse {
private HttpResponse response;
public JavaNetHttpClientHttpHttpResponse(HttpResponse response) {
super();
this.response = response;
}
@Override
public int getRawStatusCode() throws IOException {
return response.statusCode();
}
@Override
public String getStatusText() throws IOException {
return HttpStatus.valueOf(getRawStatusCode()).getReasonPhrase();
}
@Override
public void close() {
try {
response.body().close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public InputStream getBody() throws IOException {
return response.body();
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
response.headers().map().forEach(headers::addAll);
return HttpHeaders.readOnlyHttpHeaders(headers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy