|
|
|
@ -48,6 +48,9 @@ import org.springframework.util.Assert; |
|
|
|
* <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for |
|
|
|
* <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for |
|
|
|
* sharing across multiple clients. |
|
|
|
* sharing across multiple clients. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Note that this implementation consistently closes the HTTP connection on each |
|
|
|
|
|
|
|
* request. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
@ -78,8 +81,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, |
|
|
|
|
|
|
|
|
|
|
|
private volatile Bootstrap bootstrap; |
|
|
|
private volatile Bootstrap bootstrap; |
|
|
|
|
|
|
|
|
|
|
|
private volatile Bootstrap sslBootstrap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@code Netty4ClientHttpRequestFactory} with a default |
|
|
|
* Create a new {@code Netty4ClientHttpRequestFactory} with a default |
|
|
|
@ -177,20 +178,17 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, |
|
|
|
private Bootstrap getBootstrap(URI uri) { |
|
|
|
private Bootstrap getBootstrap(URI uri) { |
|
|
|
boolean isSecure = (uri.getPort() == 443 || "https".equalsIgnoreCase(uri.getScheme())); |
|
|
|
boolean isSecure = (uri.getPort() == 443 || "https".equalsIgnoreCase(uri.getScheme())); |
|
|
|
if (isSecure) { |
|
|
|
if (isSecure) { |
|
|
|
if (this.sslBootstrap == null) { |
|
|
|
return buildBootstrap(uri, true); |
|
|
|
this.sslBootstrap = buildBootstrap(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.sslBootstrap; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (this.bootstrap == null) { |
|
|
|
if (this.bootstrap == null) { |
|
|
|
this.bootstrap = buildBootstrap(false); |
|
|
|
this.bootstrap = buildBootstrap(uri, false); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.bootstrap; |
|
|
|
return this.bootstrap; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Bootstrap buildBootstrap(boolean isSecure) { |
|
|
|
private Bootstrap buildBootstrap(URI uri, boolean isSecure) { |
|
|
|
Bootstrap bootstrap = new Bootstrap(); |
|
|
|
Bootstrap bootstrap = new Bootstrap(); |
|
|
|
bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class) |
|
|
|
bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class) |
|
|
|
.handler(new ChannelInitializer<SocketChannel>() { |
|
|
|
.handler(new ChannelInitializer<SocketChannel>() { |
|
|
|
@ -200,7 +198,7 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, |
|
|
|
ChannelPipeline pipeline = channel.pipeline(); |
|
|
|
ChannelPipeline pipeline = channel.pipeline(); |
|
|
|
if (isSecure) { |
|
|
|
if (isSecure) { |
|
|
|
Assert.notNull(sslContext, "sslContext should not be null"); |
|
|
|
Assert.notNull(sslContext, "sslContext should not be null"); |
|
|
|
pipeline.addLast(sslContext.newHandler(channel.alloc())); |
|
|
|
pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort())); |
|
|
|
} |
|
|
|
} |
|
|
|
pipeline.addLast(new HttpClientCodec()); |
|
|
|
pipeline.addLast(new HttpClientCodec()); |
|
|
|
pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); |
|
|
|
pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); |
|
|
|
|