Skip to content

Commit fd7045a

Browse files
committed
Polishing
(cherry picked from commit 9b57437)
1 parent e26d350 commit fd7045a

File tree

4 files changed

+72
-69
lines changed

4 files changed

+72
-69
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,12 +73,11 @@ protected void assertNotExecuted() {
7373
protected abstract OutputStream getBodyInternal(HttpHeaders headers) throws IOException;
7474

7575
/**
76-
* Abstract template method that writes the given headers and content to the HTTP
77-
* request.
76+
* Abstract template method that writes the given headers and content to the HTTP request.
7877
* @param headers the HTTP headers
7978
* @return the response object for the executed request
8079
*/
81-
protected abstract ListenableFuture<ClientHttpResponse> executeInternal(
82-
HttpHeaders headers) throws IOException;
80+
protected abstract ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers)
81+
throws IOException;
8382

8483
}

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

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ public URI getURI() {
7979
return this.uri;
8080
}
8181

82+
@Override
83+
public ClientHttpResponse execute() throws IOException {
84+
try {
85+
return executeAsync().get();
86+
}
87+
catch (InterruptedException ex) {
88+
throw new IOException(ex.getMessage(), ex);
89+
}
90+
catch (ExecutionException ex) {
91+
if (ex.getCause() instanceof IOException) {
92+
throw (IOException) ex.getCause();
93+
}
94+
else {
95+
throw new IOException(ex.getMessage(), ex.getCause());
96+
}
97+
}
98+
}
99+
82100
@Override
83101
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
84102
return this.body;
@@ -105,26 +123,24 @@ public void operationComplete(ChannelFuture future) throws Exception {
105123
};
106124

107125
this.bootstrap.connect(this.uri.getHost(), getPort(this.uri)).addListener(connectionListener);
108-
109126
return responseFuture;
110127
}
111128

112-
@Override
113-
public ClientHttpResponse execute() throws IOException {
114-
try {
115-
return executeAsync().get();
116-
}
117-
catch (InterruptedException ex) {
118-
throw new IOException(ex.getMessage(), ex);
119-
}
120-
catch (ExecutionException ex) {
121-
if (ex.getCause() instanceof IOException) {
122-
throw (IOException) ex.getCause();
123-
}
124-
else {
125-
throw new IOException(ex.getMessage(), ex);
126-
}
129+
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
130+
io.netty.handler.codec.http.HttpMethod nettyMethod =
131+
io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());
132+
133+
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(
134+
HttpVersion.HTTP_1_1, nettyMethod, this.uri.toString(), this.body.buffer());
135+
136+
nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost());
137+
nettyRequest.headers().set(HttpHeaders.CONNECTION, "close");
138+
139+
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
140+
nettyRequest.headers().add(entry.getKey(), entry.getValue());
127141
}
142+
143+
return nettyRequest;
128144
}
129145

130146
private static int getPort(URI uri) {
@@ -140,23 +156,6 @@ else if ("https".equalsIgnoreCase(uri.getScheme())) {
140156
return port;
141157
}
142158

143-
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
144-
io.netty.handler.codec.http.HttpMethod nettyMethod =
145-
io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());
146-
147-
FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
148-
nettyMethod, this.uri.toString(), this.body.buffer());
149-
150-
nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost());
151-
nettyRequest.headers().set(HttpHeaders.CONNECTION, "close");
152-
153-
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
154-
nettyRequest.headers().add(entry.getKey(), entry.getValue());
155-
}
156-
157-
return nettyRequest;
158-
}
159-
160159

161160
/**
162161
* A SimpleChannelInboundHandler to update the given SettableListenableFuture.

spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,17 +34,17 @@ public class HttpClientErrorException extends HttpStatusCodeException {
3434

3535

3636
/**
37-
* Construct a new instance of {@code HttpClientErrorException} based on an
38-
* {@link HttpStatus}.
37+
* Construct a new instance of {@code HttpClientErrorException} based on
38+
* an {@link HttpStatus}.
3939
* @param statusCode the status code
4040
*/
4141
public HttpClientErrorException(HttpStatus statusCode) {
4242
super(statusCode);
4343
}
4444

4545
/**
46-
* Construct a new instance of {@code HttpClientErrorException} based on an
47-
* {@link HttpStatus} and status text.
46+
* Construct a new instance of {@code HttpClientErrorException} based on
47+
* an {@link HttpStatus} and status text.
4848
* @param statusCode the status code
4949
* @param statusText the status text
5050
*/
@@ -53,30 +53,32 @@ public HttpClientErrorException(HttpStatus statusCode, String statusText) {
5353
}
5454

5555
/**
56-
* Construct a new instance of {@code HttpClientErrorException} based on an
57-
* {@link HttpStatus}, status text, and response body content.
56+
* Construct a new instance of {@code HttpClientErrorException} based on
57+
* an {@link HttpStatus}, status text, and response body content.
5858
* @param statusCode the status code
5959
* @param statusText the status text
60-
* @param responseBody the response body content, may be {@code null}
61-
* @param responseCharset the response body charset, may be {@code null}
60+
* @param responseBody the response body content (may be {@code null})
61+
* @param responseCharset the response body charset (may be {@code null})
6262
*/
6363
public HttpClientErrorException(HttpStatus statusCode, String statusText,
6464
byte[] responseBody, Charset responseCharset) {
65+
6566
super(statusCode, statusText, responseBody, responseCharset);
6667
}
6768

6869
/**
69-
* Construct a new instance of {@code HttpClientErrorException} based on an
70-
* {@link HttpStatus}, status text, and response body content.
70+
* Construct a new instance of {@code HttpClientErrorException} based on
71+
* an {@link HttpStatus}, status text, and response body content.
7172
* @param statusCode the status code
7273
* @param statusText the status text
73-
* @param responseHeaders the response headers, may be {@code null}
74-
* @param responseBody the response body content, may be {@code null}
75-
* @param responseCharset the response body charset, may be {@code null}
74+
* @param responseHeaders the response headers (may be {@code null})
75+
* @param responseBody the response body content (may be {@code null})
76+
* @param responseCharset the response body charset (may be {@code null})
7677
* @since 3.1.2
7778
*/
7879
public HttpClientErrorException(HttpStatus statusCode, String statusText,
7980
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
81+
8082
super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
8183
}
8284

spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,26 +25,26 @@
2525
* Exception thrown when an HTTP 5xx is received.
2626
*
2727
* @author Arjen Poutsma
28-
* @see DefaultResponseErrorHandler
2928
* @since 3.0
29+
* @see DefaultResponseErrorHandler
3030
*/
3131
public class HttpServerErrorException extends HttpStatusCodeException {
3232

3333
private static final long serialVersionUID = -2915754006618138282L;
3434

3535

3636
/**
37-
* Construct a new instance of {@code HttpServerErrorException} based on an
38-
* {@link HttpStatus}.
37+
* Construct a new instance of {@code HttpServerErrorException} based on
38+
* an {@link HttpStatus}.
3939
* @param statusCode the status code
4040
*/
4141
public HttpServerErrorException(HttpStatus statusCode) {
4242
super(statusCode);
4343
}
4444

4545
/**
46-
* Construct a new instance of {@code HttpServerErrorException} based on an
47-
* {@link HttpStatus} and status text.
46+
* Construct a new instance of {@code HttpServerErrorException} based on
47+
* an {@link HttpStatus} and status text.
4848
* @param statusCode the status code
4949
* @param statusText the status text
5050
*/
@@ -53,31 +53,34 @@ public HttpServerErrorException(HttpStatus statusCode, String statusText) {
5353
}
5454

5555
/**
56-
* Construct a new instance of {@code HttpServerErrorException} based on an
57-
* {@link HttpStatus}, status text, and response body content.
58-
* @param statusCode the status code
59-
* @param statusText the status text
60-
* @param responseBody the response body content, may be {@code null}
61-
* @param responseCharset the response body charset, may be {@code null}
56+
* Construct a new instance of {@code HttpServerErrorException} based on
57+
* an {@link HttpStatus}, status text, and response body content.
58+
* @param statusCode the status code
59+
* @param statusText the status text
60+
* @param responseBody the response body content (may be {@code null})
61+
* @param responseCharset the response body charset (may be {@code null})
6262
* @since 3.0.5
6363
*/
6464
public HttpServerErrorException(HttpStatus statusCode, String statusText,
6565
byte[] responseBody, Charset responseCharset) {
66+
6667
super(statusCode, statusText, responseBody, responseCharset);
6768
}
6869

6970
/**
70-
* Construct a new instance of {@code HttpServerErrorException} based on a
71-
* {@link HttpStatus}, status text, and response body content.
71+
* Construct a new instance of {@code HttpServerErrorException} based on
72+
* an {@link HttpStatus}, status text, and response body content.
7273
* @param statusCode the status code
7374
* @param statusText the status text
74-
* @param responseHeaders the response headers, may be {@code null}
75-
* @param responseBody the response body content, may be {@code null}
76-
* @param responseCharset the response body charset, may be {@code null}
75+
* @param responseHeaders the response headers (may be {@code null})
76+
* @param responseBody the response body content (may be {@code null})
77+
* @param responseCharset the response body charset (may be {@code null})
7778
* @since 3.1.2
7879
*/
7980
public HttpServerErrorException(HttpStatus statusCode, String statusText,
8081
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
82+
8183
super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
8284
}
85+
8386
}

0 commit comments

Comments
 (0)