diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java index e7693d832e..92ea05d320 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java @@ -48,7 +48,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; *
Created via the {@link Netty4ClientHttpRequestFactory}. * * @author Arjen Poutsma - * @since 4.2 + * @since 4.1.2 */ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements ClientHttpRequest { @@ -61,7 +61,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements private final ByteBufOutputStream body; - Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) { + public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) { this.bootstrap = bootstrap; this.uri = uri; this.method = method; @@ -81,7 +81,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements @Override protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException { - return body; + return this.body; } @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java index eb6ca0ac28..fc3f5783ec 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java @@ -43,7 +43,7 @@ import org.springframework.util.Assert; * across multiple clients. * * @author Arjen Poutsma - * @since 4.2 + * @since 4.1.2 */ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, InitializingBean, DisposableBean { @@ -59,11 +59,11 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, private final boolean defaultEventLoopGroup; - private SslContext sslContext; - private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE; - private Bootstrap bootstrap; + private SslContext sslContext; + + private volatile Bootstrap bootstrap; /** @@ -79,13 +79,12 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, /** * Create a new {@code Netty4ClientHttpRequestFactory} with the given * {@link EventLoopGroup}. - * *
NOTE: the given group will not be - * {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory; doing - * so becomes the responsibility of the caller. + * {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory; + * doing so becomes the responsibility of the caller. */ public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) { - Assert.notNull(eventLoopGroup, "'eventLoopGroup' must not be null"); + Assert.notNull(eventLoopGroup, "EventLoopGroup must not be null"); this.eventLoopGroup = eventLoopGroup; this.defaultEventLoopGroup = false; } @@ -117,7 +116,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); - if (sslContext != null) { pipeline.addLast(sslContext.newHandler(channel.alloc())); } @@ -131,10 +129,11 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, } @Override - public void afterPropertiesSet() throws Exception { + public void afterPropertiesSet() { getBootstrap(); } + @Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { return createRequestInternal(uri, httpMethod); @@ -149,10 +148,11 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, return new Netty4ClientHttpRequest(getBootstrap(), uri, httpMethod, this.maxRequestSize); } + @Override public void destroy() throws InterruptedException { if (this.defaultEventLoopGroup) { - // clean up the EventLoopGroup if we created it in the constructor + // Clean up the EventLoopGroup if we created it in the constructor this.eventLoopGroup.shutdownGracefully().sync(); } } diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java index 2da9256abb..0963d25408 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java @@ -32,7 +32,7 @@ import org.springframework.util.Assert; * Netty 4 to execute requests. * * @author Arjen Poutsma - * @since 4.2 + * @since 4.1.2 */ class Netty4ClientHttpResponse extends AbstractClientHttpResponse { @@ -42,12 +42,12 @@ class Netty4ClientHttpResponse extends AbstractClientHttpResponse { private final ByteBufInputStream body; - private HttpHeaders headers; + private volatile HttpHeaders headers; - Netty4ClientHttpResponse(ChannelHandlerContext context, FullHttpResponse nettyResponse) { - Assert.notNull(context, "'context' must not be null"); - Assert.notNull(nettyResponse, "'nettyResponse' must not be null"); + public Netty4ClientHttpResponse(ChannelHandlerContext context, FullHttpResponse nettyResponse) { + Assert.notNull(context, "ChannelHandlerContext must not be null"); + Assert.notNull(nettyResponse, "FullHttpResponse must not be null"); this.context = context; this.nettyResponse = nettyResponse; this.body = new ByteBufInputStream(this.nettyResponse.content()); @@ -87,4 +87,5 @@ class Netty4ClientHttpResponse extends AbstractClientHttpResponse { this.nettyResponse.release(); this.context.close(); } + }