Skip to content

Commit f053f60

Browse files
committed
Revised javadoc and related polishing
Issue: SPR-11383
1 parent d55c22e commit f053f60

9 files changed

+74
-85
lines changed

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

Lines changed: 8 additions & 8 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-2014 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.
@@ -23,24 +23,24 @@
2323
import org.springframework.util.concurrent.ListenableFuture;
2424

2525
/**
26-
* Represents a client-side asynchronous HTTP request. Created via an implementation of
27-
* the {@link AsyncClientHttpRequestFactory}.
28-
* <p>A {@code AsyncHttpRequest} can be {@linkplain #executeAsync() executed}, getting a
29-
* future {@link ClientHttpResponse} which can be read from.
26+
* Represents a client-side asynchronous HTTP request. Created via an
27+
* implementation of the {@link AsyncClientHttpRequestFactory}.
28+
*
29+
* <p>A {@code AsyncHttpRequest} can be {@linkplain #executeAsync() executed},
30+
* getting a future {@link ClientHttpResponse} which can be read from.
3031
*
3132
* @author Arjen Poutsma
3233
* @since 4.0
33-
* @see AsyncClientHttpRequestFactory#createAsyncRequest(java.net.URI, org.springframework.http.HttpMethod)
34+
* @see AsyncClientHttpRequestFactory#createAsyncRequest
3435
*/
3536
public interface AsyncClientHttpRequest extends HttpRequest, HttpOutputMessage {
3637

3738
/**
38-
* Execute this request asynchronously, resulting in a future
39+
* Execute this request asynchronously, resulting in a Future handle.
3940
* {@link ClientHttpResponse} that can be read.
4041
* @return the future response result of the execution
4142
* @throws java.io.IOException in case of I/O errors
4243
*/
4344
ListenableFuture<ClientHttpResponse> executeAsync() throws IOException;
4445

45-
4646
}

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

Lines changed: 6 additions & 7 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-2014 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.
@@ -22,25 +22,24 @@
2222
import org.springframework.http.HttpMethod;
2323

2424
/**
25-
* Factory for {@link AsyncClientHttpRequest} objects. Requests are created by the
26-
* {@link #createAsyncRequest(URI, HttpMethod)} method.
25+
* Factory for {@link AsyncClientHttpRequest} objects.
26+
* Requests are created by the {@link #createAsyncRequest(URI, HttpMethod)} method.
2727
*
2828
* @author Arjen Poutsma
2929
* @since 4.0
3030
*/
3131
public interface AsyncClientHttpRequestFactory {
3232

3333
/**
34-
* Create a new asynchronous {@link AsyncClientHttpRequest} for the specified URI and
35-
* HTTP method.
34+
* Create a new asynchronous {@link AsyncClientHttpRequest} for the specified URI
35+
* and HTTP method.
3636
* <p>The returned request can be written to, and then executed by calling
3737
* {@link AsyncClientHttpRequest#executeAsync()}.
3838
* @param uri the URI to create a request for
3939
* @param httpMethod the HTTP method to execute
4040
* @return the created request
4141
* @throws IOException in case of I/O errors
4242
*/
43-
AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
44-
throws IOException;
43+
AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException;
4544

4645
}

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

Lines changed: 17 additions & 21 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-2014 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.
@@ -44,9 +44,8 @@
4444
*
4545
* @author Oleg Kalnichevski
4646
* @author Arjen Poutsma
47-
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory#createRequest(java.net.URI,
48-
* org.springframework.http.HttpMethod)
49-
* @since 3.1
47+
* @since 4.0
48+
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory#createRequest
5049
*/
5150
final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest {
5251

@@ -56,13 +55,14 @@ final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncC
5655

5756
private final HttpContext httpContext;
5857

59-
public HttpComponentsAsyncClientHttpRequest(HttpAsyncClient httpClient,
60-
HttpUriRequest httpRequest, HttpContext httpContext) {
58+
59+
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient httpClient, HttpUriRequest httpRequest, HttpContext httpContext) {
6160
this.httpClient = httpClient;
6261
this.httpRequest = httpRequest;
6362
this.httpContext = httpContext;
6463
}
6564

65+
6666
@Override
6767
public HttpMethod getMethod() {
6868
return HttpMethod.valueOf(this.httpRequest.getMethod());
@@ -74,48 +74,46 @@ public URI getURI() {
7474
}
7575

7676
@Override
77-
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers,
78-
byte[] bufferedOutput) throws IOException {
77+
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, byte[] bufferedOutput)
78+
throws IOException {
79+
7980
HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers);
8081

8182
if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
82-
HttpEntityEnclosingRequest entityEnclosingRequest =
83-
(HttpEntityEnclosingRequest) this.httpRequest;
83+
HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
8484
HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput);
8585
entityEnclosingRequest.setEntity(requestEntity);
8686
}
8787

8888
final HttpResponseFutureCallback callback = new HttpResponseFutureCallback();
89-
9089
final Future<HttpResponse> futureResponse =
9190
this.httpClient.execute(this.httpRequest, this.httpContext, callback);
9291
return new ClientHttpResponseFuture(futureResponse, callback);
9392
}
9493

94+
9595
private static class HttpResponseFutureCallback implements FutureCallback<HttpResponse> {
9696

9797
private final ListenableFutureCallbackRegistry<ClientHttpResponse> callbacks =
9898
new ListenableFutureCallbackRegistry<ClientHttpResponse>();
9999

100-
public void addCallback(
101-
ListenableFutureCallback<? super ClientHttpResponse> callback) {
102-
callbacks.addCallback(callback);
100+
public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) {
101+
this.callbacks.addCallback(callback);
103102
}
104103

105104
@Override
106105
public void completed(HttpResponse result) {
107-
callbacks.success(new HttpComponentsAsyncClientHttpResponse(result));
106+
this.callbacks.success(new HttpComponentsAsyncClientHttpResponse(result));
108107
}
109108

110109
@Override
111110
public void failed(Exception ex) {
112-
callbacks.failure(ex);
111+
this.callbacks.failure(ex);
113112
}
114113

115114
@Override
116115
public void cancelled() {
117116
}
118-
119117
}
120118

121119

@@ -124,8 +122,7 @@ private static class ClientHttpResponseFuture extends FutureAdapter<ClientHttpRe
124122

125123
private final HttpResponseFutureCallback callback;
126124

127-
private ClientHttpResponseFuture(Future<HttpResponse> futureResponse,
128-
HttpResponseFutureCallback callback) {
125+
public ClientHttpResponseFuture(Future<HttpResponse> futureResponse, HttpResponseFutureCallback callback) {
129126
super(futureResponse);
130127
this.callback = callback;
131128
}
@@ -136,8 +133,7 @@ protected ClientHttpResponse adapt(HttpResponse response) {
136133
}
137134

138135
@Override
139-
public void addCallback(
140-
ListenableFutureCallback<? super ClientHttpResponse> callback) {
136+
public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) {
141137
this.callback.addCallback(callback);
142138
}
143139
}

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

Lines changed: 2 additions & 3 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-2014 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.
@@ -113,8 +113,7 @@ private void startAsyncClient() {
113113
}
114114

115115
@Override
116-
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
117-
throws IOException {
116+
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
118117
HttpAsyncClient asyncClient = getHttpAsyncClient();
119118
startAsyncClient();
120119
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);

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

Lines changed: 4 additions & 5 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-2014 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.
@@ -32,7 +32,7 @@
3232
*
3333
* @author Oleg Kalnichevski
3434
* @author Arjen Poutsma
35-
* @since 3.1
35+
* @since 4.0
3636
* @see HttpComponentsAsyncClientHttpRequest#executeAsync()
3737
*/
3838
final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse {
@@ -76,9 +76,8 @@ public InputStream getBody() throws IOException {
7676

7777
@Override
7878
public void close() {
79-
// HTTP responses returned by async HTTP client
80-
// are not bound to an active connection and
81-
// do not have to deallocate any resources
79+
// HTTP responses returned by async HTTP client are not bound to an
80+
// active connection and do not have to deallocate any resources...
8281
}
8382

8483
}

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

Lines changed: 6 additions & 6 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-2014 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.
@@ -29,6 +29,7 @@
2929
import org.apache.http.impl.client.CloseableHttpClient;
3030
import org.apache.http.protocol.HTTP;
3131
import org.apache.http.protocol.HttpContext;
32+
3233
import org.springframework.http.HttpHeaders;
3334
import org.springframework.http.HttpMethod;
3435

@@ -52,7 +53,7 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR
5253
private final HttpContext httpContext;
5354

5455

55-
public HttpComponentsClientHttpRequest(CloseableHttpClient httpClient, HttpUriRequest httpRequest, HttpContext httpContext) {
56+
HttpComponentsClientHttpRequest(CloseableHttpClient httpClient, HttpUriRequest httpRequest, HttpContext httpContext) {
5657
this.httpClient = httpClient;
5758
this.httpRequest = httpRequest;
5859
this.httpContext = httpContext;
@@ -80,14 +81,13 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] buffere
8081
HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
8182
entityEnclosingRequest.setEntity(requestEntity);
8283
}
83-
CloseableHttpResponse httpResponse =
84-
this.httpClient.execute(this.httpRequest, this.httpContext);
84+
CloseableHttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
8585
return new HttpComponentsClientHttpResponse(httpResponse);
8686
}
8787

88+
8889
/**
89-
* Adds the given headers to the given HTTP request.
90-
*
90+
* Add the given headers to the given HTTP request.
9191
* @param httpRequest the request to add the headers to
9292
* @param headers the headers to add
9393
*/

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

Lines changed: 3 additions & 1 deletion
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-2014 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.
@@ -48,6 +48,8 @@
4848
* <p>Allows to use a pre-configured {@link HttpClient} instance -
4949
* potentially with authentication, HTTP connection pooling, etc.
5050
*
51+
* <p><b>NOTE:</b> Requires Apache HttpComponents 4.3 or higher, as of Spring 4.0.
52+
*
5153
* @author Oleg Kalnichevski
5254
* @author Arjen Poutsma
5355
* @since 3.1

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

Lines changed: 6 additions & 5 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-2014 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,7 +73,7 @@ public HttpHeaders getHeaders() {
7373
@Override
7474
public InputStream getBody() throws IOException {
7575
HttpEntity entity = this.httpResponse.getEntity();
76-
return entity != null ? entity.getContent() : null;
76+
return (entity != null ? entity.getContent() : null);
7777
}
7878

7979
@Override
@@ -83,12 +83,13 @@ public void close() {
8383
try {
8484
// Attempt to keep connection alive by consuming its remaining content
8585
EntityUtils.consume(this.httpResponse.getEntity());
86-
} finally {
87-
// Paranoia
86+
}
87+
finally {
8888
this.httpResponse.close();
8989
}
9090
}
91-
catch (IOException ignore) {
91+
catch (IOException ex) {
92+
// Ignore exception on close...
9293
}
9394
}
9495

0 commit comments

Comments
 (0)