-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Closed
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
Fedor Bartosh opened SPR-12887 and commented
AsyncRestTemplate.execute returns ListenableFuture that allows to register callbacks. Let's say we have following example:
public void test() throws InterruptedException, ExecutionException {
AsyncRestTemplate restTemplate = new AsyncRestTemplate();
String url = "http://graph.facebook.com/some-non-existing-resource";
ListenableFuture<ResponseEntity<Object>> responseEntity = restTemplate.exchange(url, HttpMethod.GET, HttpEntity.EMPTY, Object.class);
final String[] listenerExceptionBody = new String[1];
String getExceptionBody = null;
try {
responseEntity.addCallback(new ListenableFutureCallback<ResponseEntity<Object>>() {
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof HttpClientErrorException) {
HttpClientErrorException exception = (HttpClientErrorException) throwable;
listenerExceptionBody[0] = exception.getResponseBodyAsString();
}
}
@Override
public void onSuccess(ResponseEntity<Object> objectResponseEntity) {
System.out.println("onSuccess");
}
});
Thread.sleep(100);
responseEntity.get();
} catch (HttpClientErrorException e) {
getExceptionBody = e.getResponseBodyAsString();
}
Assert.assertEquals(listenerExceptionBody[0], getExceptionBody);
}
If 4xx error occurs during REST call, two HttpClientErrorException will be created, one of them containing response body and another one missing.
Sample maven project is attached.
Affects: 4.1.6
Attachments:
- client-error-body-test.tar (20.00 kB)
Issue Links:
- AsyncRestTemplate should wrap RuntimeExceptions in ExecutionException [SPR-13413] #17992 AsyncRestTemplate should wrap RuntimeExceptions in ExecutionException
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug