Skip to content

Commit a6e7044

Browse files
committed
Correct since declarations in Netty 4 client support
1 parent 015afef commit a6e7044

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* <p>Created via the {@link Netty4ClientHttpRequestFactory}.
4949
*
5050
* @author Arjen Poutsma
51-
* @since 4.2
51+
* @since 4.1.2
5252
*/
5353
class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements ClientHttpRequest {
5454

@@ -61,7 +61,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
6161
private final ByteBufOutputStream body;
6262

6363

64-
Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) {
64+
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) {
6565
this.bootstrap = bootstrap;
6666
this.uri = uri;
6767
this.method = method;
@@ -81,7 +81,7 @@ public URI getURI() {
8181

8282
@Override
8383
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
84-
return body;
84+
return this.body;
8585
}
8686

8787
@Override

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* across multiple clients.
4444
*
4545
* @author Arjen Poutsma
46-
* @since 4.2
46+
* @since 4.1.2
4747
*/
4848
public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
4949
AsyncClientHttpRequestFactory, InitializingBean, DisposableBean {
@@ -59,11 +59,11 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
5959

6060
private final boolean defaultEventLoopGroup;
6161

62-
private SslContext sslContext;
63-
6462
private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE;
6563

66-
private Bootstrap bootstrap;
64+
private SslContext sslContext;
65+
66+
private volatile Bootstrap bootstrap;
6767

6868

6969
/**
@@ -79,13 +79,12 @@ public Netty4ClientHttpRequestFactory() {
7979
/**
8080
* Create a new {@code Netty4ClientHttpRequestFactory} with the given
8181
* {@link EventLoopGroup}.
82-
*
8382
* <p><b>NOTE:</b> the given group will <strong>not</strong> be
84-
* {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory; doing
85-
* so becomes the responsibility of the caller.
83+
* {@linkplain EventLoopGroup#shutdownGracefully() shutdown} by this factory;
84+
* doing so becomes the responsibility of the caller.
8685
*/
8786
public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) {
88-
Assert.notNull(eventLoopGroup, "'eventLoopGroup' must not be null");
87+
Assert.notNull(eventLoopGroup, "EventLoopGroup must not be null");
8988
this.eventLoopGroup = eventLoopGroup;
9089
this.defaultEventLoopGroup = false;
9190
}
@@ -117,7 +116,6 @@ private Bootstrap getBootstrap() {
117116
@Override
118117
protected void initChannel(SocketChannel channel) throws Exception {
119118
ChannelPipeline pipeline = channel.pipeline();
120-
121119
if (sslContext != null) {
122120
pipeline.addLast(sslContext.newHandler(channel.alloc()));
123121
}
@@ -131,10 +129,11 @@ protected void initChannel(SocketChannel channel) throws Exception {
131129
}
132130

133131
@Override
134-
public void afterPropertiesSet() throws Exception {
132+
public void afterPropertiesSet() {
135133
getBootstrap();
136134
}
137135

136+
138137
@Override
139138
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
140139
return createRequestInternal(uri, httpMethod);
@@ -149,10 +148,11 @@ private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMe
149148
return new Netty4ClientHttpRequest(getBootstrap(), uri, httpMethod, this.maxRequestSize);
150149
}
151150

151+
152152
@Override
153153
public void destroy() throws InterruptedException {
154154
if (this.defaultEventLoopGroup) {
155-
// clean up the EventLoopGroup if we created it in the constructor
155+
// Clean up the EventLoopGroup if we created it in the constructor
156156
this.eventLoopGroup.shutdownGracefully().sync();
157157
}
158158
}

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Netty 4 to execute requests.
3333
*
3434
* @author Arjen Poutsma
35-
* @since 4.2
35+
* @since 4.1.2
3636
*/
3737
class Netty4ClientHttpResponse extends AbstractClientHttpResponse {
3838

@@ -42,12 +42,12 @@ class Netty4ClientHttpResponse extends AbstractClientHttpResponse {
4242

4343
private final ByteBufInputStream body;
4444

45-
private HttpHeaders headers;
45+
private volatile HttpHeaders headers;
4646

4747

48-
Netty4ClientHttpResponse(ChannelHandlerContext context, FullHttpResponse nettyResponse) {
49-
Assert.notNull(context, "'context' must not be null");
50-
Assert.notNull(nettyResponse, "'nettyResponse' must not be null");
48+
public Netty4ClientHttpResponse(ChannelHandlerContext context, FullHttpResponse nettyResponse) {
49+
Assert.notNull(context, "ChannelHandlerContext must not be null");
50+
Assert.notNull(nettyResponse, "FullHttpResponse must not be null");
5151
this.context = context;
5252
this.nettyResponse = nettyResponse;
5353
this.body = new ByteBufInputStream(this.nettyResponse.content());
@@ -87,4 +87,5 @@ public void close() {
8787
this.nettyResponse.release();
8888
this.context.close();
8989
}
90+
9091
}

0 commit comments

Comments
 (0)