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 2f8f0d1eb9d..584a9da1e66 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 @@ -19,6 +19,7 @@ package org.springframework.http.client; import java.io.IOException; import java.net.URI; import java.util.concurrent.TimeUnit; +import javax.net.ssl.SSLException; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelConfig; @@ -32,6 +33,7 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.timeout.ReadTimeoutHandler; import org.springframework.beans.factory.DisposableBean; @@ -48,6 +50,7 @@ import org.springframework.util.Assert; * * @author Arjen Poutsma * @author Rossen Stoyanchev + * @author Brian Clozel * @since 4.1.2 */ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, @@ -74,6 +77,8 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, private volatile Bootstrap bootstrap; + private volatile Bootstrap sslBootstrap; + /** * Create a new {@code Netty4ClientHttpRequestFactory} with a default @@ -99,6 +104,15 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, } + private SslContext getDefaultClientSslContext() { + try { + return SslContextBuilder.forClient().build(); + } + catch (SSLException exc) { + throw new IllegalStateException("Could not create default client SslContext", exc); + } + } + /** * Set the default maximum response size. *
By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}. @@ -112,7 +126,7 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, /** * Set the SSL context. When configured it is used to create and insert an * {@link io.netty.handler.ssl.SslHandler} in the channel pipeline. - *
By default this is not set. + *
A default client SslContext is configured if none has been provided.
*/
public void setSslContext(SslContext sslContext) {
this.sslContext = sslContext;
@@ -136,29 +150,44 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
this.readTimeout = readTimeout;
}
- private Bootstrap getBootstrap() {
- if (this.bootstrap == null) {
- Bootstrap bootstrap = new Bootstrap();
- bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)
- .handler(new ChannelInitializer