SPR-8713 - DefaultResponseErrorHandler IOException Bug

This commit is contained in:
Arjen Poutsma
2011-09-27 08:16:33 +00:00
parent aa7a100807
commit 67fda70cb8
2 changed files with 110 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
HttpStatus statusCode = response.getStatusCode();
MediaType contentType = response.getHeaders().getContentType();
Charset charset = contentType != null ? contentType.getCharSet() : null;
byte[] body = FileCopyUtils.copyToByteArray(response.getBody());
byte[] body = getResponseBody(response);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset);
@@ -80,5 +80,14 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
}
}
private byte[] getResponseBody(ClientHttpResponse response) {
try {
return FileCopyUtils.copyToByteArray(response.getBody());
}
catch (IOException e) {
return new byte[0];
}
}
}