Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpClientErrorException missing response body if callback is registered [SPR-12887] #17485

spring-issuemaster opened this issue Apr 3, 2015 · 1 comment


Copy link

commented Apr 3, 2015

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 = "";
        ListenableFuture<ResponseEntity<Object>> responseEntity =, HttpMethod.GET, HttpEntity.EMPTY, Object.class);
        final String[] listenerExceptionBody = new String[1];
        String getExceptionBody = null;
        try {
            responseEntity.addCallback(new ListenableFutureCallback<ResponseEntity<Object>>() {
                public void onFailure(Throwable throwable) {
                    if (throwable instanceof HttpClientErrorException) {
                        HttpClientErrorException exception = (HttpClientErrorException) throwable;
                        listenerExceptionBody[0] = exception.getResponseBodyAsString();

                public void onSuccess(ResponseEntity<Object> objectResponseEntity) {

        } 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


Issue Links:

  • #17992 AsyncRestTemplate should wrap RuntimeExceptions in ExecutionException

Referenced from: commits b119a9c, de0f3ae, 3402c13, b18053f


This comment has been minimized.

Copy link
Collaborator Author

commented Apr 10, 2015

Arjen Poutsma commented

Fixed. PR at #776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.