Skip to content

Commit 856561f

Browse files
committed
AsyncRestTemplate and FutureAdapter consistently throw ExecutionException
Issue: SPR-13413 (cherry picked from commit 2bb7164)
1 parent c4a9abb commit 856561f

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -59,27 +59,27 @@ protected FutureAdapter(Future<S> adaptee) {
5959
* Returns the adaptee.
6060
*/
6161
protected Future<S> getAdaptee() {
62-
return adaptee;
62+
return this.adaptee;
6363
}
6464

6565
@Override
6666
public boolean cancel(boolean mayInterruptIfRunning) {
67-
return adaptee.cancel(mayInterruptIfRunning);
67+
return this.adaptee.cancel(mayInterruptIfRunning);
6868
}
6969

7070
@Override
7171
public boolean isCancelled() {
72-
return adaptee.isCancelled();
72+
return this.adaptee.isCancelled();
7373
}
7474

7575
@Override
7676
public boolean isDone() {
77-
return adaptee.isDone();
77+
return this.adaptee.isDone();
7878
}
7979

8080
@Override
8181
public T get() throws InterruptedException, ExecutionException {
82-
return adaptInternal(adaptee.get());
82+
return adaptInternal(this.adaptee.get());
8383
}
8484

8585
@Override
@@ -107,6 +107,12 @@ final T adaptInternal(S adapteeResult) throws ExecutionException {
107107
this.state = State.FAILURE;
108108
throw ex;
109109
}
110+
catch (Throwable ex) {
111+
ExecutionException execEx = new ExecutionException(ex);
112+
this.result = execEx;
113+
this.state = State.FAILURE;
114+
throw execEx;
115+
}
110116
default:
111117
throw new IllegalStateException();
112118
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -115,7 +115,9 @@ public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory) {
115115
* @param asyncRequestFactory the asynchronous request factory
116116
* @param syncRequestFactory the synchronous request factory
117117
*/
118-
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) {
118+
public AsyncRestTemplate(
119+
AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) {
120+
119121
this(asyncRequestFactory, new RestTemplate(syncRequestFactory));
120122
}
121123

@@ -126,7 +128,7 @@ public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, Clie
126128
* @param restTemplate the synchronous template to use
127129
*/
128130
public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate) {
129-
Assert.notNull(restTemplate, "'restTemplate' must not be null");
131+
Assert.notNull(restTemplate, "RestTemplate must not be null");
130132
this.syncTemplate = restTemplate;
131133
setAsyncRequestFactory(requestFactory);
132134
}
@@ -141,7 +143,9 @@ public void setErrorHandler(ResponseErrorHandler errorHandler) {
141143
this.syncTemplate.setErrorHandler(errorHandler);
142144
}
143145

144-
/** Return the error handler. */
146+
/**
147+
* Return the error handler.
148+
*/
145149
public ResponseErrorHandler getErrorHandler() {
146150
return this.syncTemplate.getErrorHandler();
147151
}
@@ -163,7 +167,7 @@ public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters
163167
* Return the message body converters.
164168
*/
165169
public List<HttpMessageConverter<?>> getMessageConverters() {
166-
return syncTemplate.getMessageConverters();
170+
return this.syncTemplate.getMessageConverters();
167171
}
168172

169173

@@ -215,6 +219,7 @@ public ListenableFuture<HttpHeaders> headForHeaders(URI url) throws RestClientEx
215219
return execute(url, HttpMethod.HEAD, null, headersExtractor);
216220
}
217221

222+
218223
// POST
219224

220225
@Override
@@ -639,7 +644,7 @@ protected final T adapt(ClientHttpResponse response) throws ExecutionException {
639644
}
640645
return convertResponse(response);
641646
}
642-
catch (IOException ex) {
647+
catch (Throwable ex) {
643648
throw new ExecutionException(ex);
644649
}
645650
finally {

0 commit comments

Comments
 (0)