Polishing
This commit is contained in:
parent
45c20e34e4
commit
cf75a09011
|
@ -330,7 +330,7 @@ public class BeanPropertyRowMapper<T> implements Function<Readable, T> {
|
||||||
bw.setPropertyValue(pd.getName(), value);
|
bw.setPropertyValue(pd.getName(), value);
|
||||||
}
|
}
|
||||||
catch (TypeMismatchException ex) {
|
catch (TypeMismatchException ex) {
|
||||||
if (value == null && this.primitivesDefaultedForNullValue) {
|
if (value == null && isPrimitivesDefaultedForNullValue()) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType());
|
String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType());
|
||||||
//here too, we miss the rowNumber information
|
//here too, we miss the rowNumber information
|
||||||
|
|
|
@ -51,25 +51,6 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
|
|
||||||
private static final Set<String> DISALLOWED_HEADERS = disallowedHeaders();
|
private static final Set<String> DISALLOWED_HEADERS = disallowedHeaders();
|
||||||
|
|
||||||
/**
|
|
||||||
* By default, {@link HttpRequest} does not allow {@code Connection},
|
|
||||||
* {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
|
|
||||||
* headers to be set, but this can be overriden with the
|
|
||||||
* {@code jdk.httpclient.allowRestrictedHeaders} system property.
|
|
||||||
* @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
|
|
||||||
*/
|
|
||||||
private static Set<String> disallowedHeaders() {
|
|
||||||
TreeSet<String> headers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
|
||||||
headers.addAll(Set.of("connection", "content-length", "expect", "host", "upgrade"));
|
|
||||||
|
|
||||||
String headersToAllow = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
|
|
||||||
if (headersToAllow != null) {
|
|
||||||
Set<String> toAllow = StringUtils.commaDelimitedListToSet(headersToAllow);
|
|
||||||
headers.removeAll(toAllow);
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableSet(headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
|
|
||||||
|
@ -85,6 +66,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
|
|
||||||
public JdkClientHttpRequest(HttpClient httpClient, URI uri, HttpMethod method, Executor executor,
|
public JdkClientHttpRequest(HttpClient httpClient, URI uri, HttpMethod method, Executor executor,
|
||||||
@Nullable Duration readTimeout) {
|
@Nullable Duration readTimeout) {
|
||||||
|
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
@ -92,6 +74,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
this.timeout = readTimeout;
|
this.timeout = readTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpMethod getMethod() {
|
public HttpMethod getMethod() {
|
||||||
return this.method;
|
return this.method;
|
||||||
|
@ -107,7 +90,8 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
||||||
try {
|
try {
|
||||||
HttpRequest request = buildRequest(headers, body);
|
HttpRequest request = buildRequest(headers, body);
|
||||||
HttpResponse<InputStream> response = this.httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
HttpResponse<InputStream> response =
|
||||||
|
this.httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||||
return new JdkClientHttpResponse(response);
|
return new JdkClientHttpResponse(response);
|
||||||
}
|
}
|
||||||
catch (UncheckedIOException ex) {
|
catch (UncheckedIOException ex) {
|
||||||
|
@ -121,9 +105,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
|
|
||||||
|
|
||||||
private HttpRequest buildRequest(HttpHeaders headers, @Nullable Body body) {
|
private HttpRequest buildRequest(HttpHeaders headers, @Nullable Body body) {
|
||||||
HttpRequest.Builder builder = HttpRequest.newBuilder()
|
HttpRequest.Builder builder = HttpRequest.newBuilder().uri(this.uri);
|
||||||
.uri(this.uri);
|
|
||||||
|
|
||||||
if (this.timeout != null) {
|
if (this.timeout != null) {
|
||||||
builder.timeout(this.timeout);
|
builder.timeout(this.timeout);
|
||||||
}
|
}
|
||||||
|
@ -144,8 +126,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
Flow.Publisher<ByteBuffer> outputStreamPublisher = OutputStreamPublisher.create(
|
Flow.Publisher<ByteBuffer> outputStreamPublisher = OutputStreamPublisher.create(
|
||||||
outputStream -> body.writeTo(StreamUtils.nonClosing(outputStream)),
|
outputStream -> body.writeTo(StreamUtils.nonClosing(outputStream)),
|
||||||
BYTE_MAPPER,
|
BYTE_MAPPER, this.executor);
|
||||||
this.executor);
|
|
||||||
|
|
||||||
long contentLength = headers.getContentLength();
|
long contentLength = headers.getContentLength();
|
||||||
if (contentLength != -1) {
|
if (contentLength != -1) {
|
||||||
|
@ -160,6 +141,25 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, {@link HttpRequest} does not allow {@code Connection},
|
||||||
|
* {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
|
||||||
|
* headers to be set, but this can be overriden with the
|
||||||
|
* {@code jdk.httpclient.allowRestrictedHeaders} system property.
|
||||||
|
* @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
|
||||||
|
*/
|
||||||
|
private static Set<String> disallowedHeaders() {
|
||||||
|
TreeSet<String> headers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
headers.addAll(Set.of("connection", "content-length", "expect", "host", "upgrade"));
|
||||||
|
|
||||||
|
String headersToAllow = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
|
||||||
|
if (headersToAllow != null) {
|
||||||
|
Set<String> toAllow = StringUtils.commaDelimitedListToSet(headersToAllow);
|
||||||
|
headers.removeAll(toAllow);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class ByteBufferMapper implements OutputStreamPublisher.ByteMapper<ByteBuffer> {
|
private static final class ByteBufferMapper implements OutputStreamPublisher.ByteMapper<ByteBuffer> {
|
||||||
|
|
||||||
|
@ -178,7 +178,6 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||||
byteBuffer.flip();
|
byteBuffer.flip();
|
||||||
return byteBuffer;
|
return byteBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ClientHttpRequestFactory} implementation based on the Java
|
* {@link ClientHttpRequestFactory} implementation based on the Java
|
||||||
* {@link HttpClient}.
|
* {@link HttpClient}.
|
||||||
|
|
|
@ -52,7 +52,7 @@ class JdkClientHttpResponse implements ClientHttpResponse {
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.headers = adaptHeaders(response);
|
this.headers = adaptHeaders(response);
|
||||||
InputStream inputStream = response.body();
|
InputStream inputStream = response.body();
|
||||||
this.body = (inputStream != null) ? inputStream : InputStream.nullInputStream();
|
this.body = (inputStream != null ? inputStream : InputStream.nullInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpHeaders adaptHeaders(HttpResponse<?> response) {
|
private static HttpHeaders adaptHeaders(HttpResponse<?> response) {
|
||||||
|
@ -103,4 +103,5 @@ class JdkClientHttpResponse implements ClientHttpResponse {
|
||||||
catch (IOException ignored) {
|
catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,12 +141,10 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||||
|
|
||||||
private final ByteBufAllocator allocator;
|
private final ByteBufAllocator allocator;
|
||||||
|
|
||||||
|
|
||||||
public ByteBufMapper(ByteBufAllocator allocator) {
|
public ByteBufMapper(ByteBufAllocator allocator) {
|
||||||
this.allocator = allocator;
|
this.allocator = allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf map(int b) {
|
public ByteBuf map(int b) {
|
||||||
ByteBuf byteBuf = this.allocator.buffer(1);
|
ByteBuf byteBuf = this.allocator.buffer(1);
|
||||||
|
@ -161,4 +159,5 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||||
return byteBuf;
|
return byteBuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,11 @@ public class ReactorNettyClientRequestFactory implements ClientHttpRequestFactor
|
||||||
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
|
|
||||||
|
|
||||||
private Duration exchangeTimeout = Duration.ofSeconds(5);
|
private Duration exchangeTimeout = Duration.ofSeconds(5);
|
||||||
|
|
||||||
private Duration readTimeout = Duration.ofSeconds(10);
|
private Duration readTimeout = Duration.ofSeconds(10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the {@code ReactorNettyClientRequestFactory}
|
* Create a new instance of the {@code ReactorNettyClientRequestFactory}
|
||||||
* with a default {@link HttpClient} that has compression enabled.
|
* with a default {@link HttpClient} that has compression enabled.
|
||||||
|
@ -61,6 +59,7 @@ public class ReactorNettyClientRequestFactory implements ClientHttpRequestFactor
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the underlying connect timeout in milliseconds.
|
* Set the underlying connect timeout in milliseconds.
|
||||||
* A value of 0 specifies an infinite timeout.
|
* A value of 0 specifies an infinite timeout.
|
||||||
|
@ -125,9 +124,9 @@ public class ReactorNettyClientRequestFactory implements ClientHttpRequestFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
return new ReactorNettyClientRequest(this.httpClient, uri, httpMethod, this.exchangeTimeout, this.readTimeout);
|
return new ReactorNettyClientRequest(this.httpClient, uri, httpMethod, this.exchangeTimeout, this.readTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||||
private volatile InputStream body;
|
private volatile InputStream body;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ReactorNettyClientResponse(HttpClientResponse response, Connection connection, Duration readTimeout) {
|
public ReactorNettyClientResponse(HttpClientResponse response, Connection connection, Duration readTimeout) {
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
@ -56,6 +55,7 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||||
this.headers = HttpHeaders.readOnlyHttpHeaders(new Netty4HeadersAdapter(response.responseHeaders()));
|
this.headers = HttpHeaders.readOnlyHttpHeaders(new Netty4HeadersAdapter(response.responseHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpStatusCode getStatusCode() {
|
public HttpStatusCode getStatusCode() {
|
||||||
return HttpStatusCode.valueOf(this.response.status().code());
|
return HttpStatusCode.valueOf(this.response.status().code());
|
||||||
|
@ -73,21 +73,23 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
if (this.body == null) {
|
InputStream body = this.body;
|
||||||
InputStream body = this.connection.inbound().receive()
|
if (body != null) {
|
||||||
.aggregate().asInputStream().block(this.readTimeout);
|
return body;
|
||||||
if (body != null) {
|
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IOException("Could not receive body");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this.body;
|
|
||||||
|
body = this.connection.inbound().receive()
|
||||||
|
.aggregate().asInputStream().block(this.readTimeout);
|
||||||
|
if (body == null) {
|
||||||
|
throw new IOException("Could not receive body");
|
||||||
|
}
|
||||||
|
this.body = body;
|
||||||
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
this.connection.dispose();
|
this.connection.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue