Include response headers in RestTemplate exceptions
Default HTTP error exceptions thrown from RestTemplate now include response headers in addition to the response body. In particular, this enables inspection of the Content-Type header allowing manual deserialization of the response body without guessing as to the content type. - introduce HttpStatusCodeException#getResponseHeaders - add constructor with headers param for HttpStatusCodeException, HttpClientErrorException and HttpServerErrorException - preserve exsisting constructor signatures - mark HttpHeaders as Serializable - generate new serialVersionUID where needed Issue: SPR-7938
This commit is contained in:
committed by
Chris Beams
parent
bca2357be7
commit
b992c3d3f2
@@ -68,7 +68,7 @@ public class DefaultResponseErrorHandlerTests {
|
||||
verify(response);
|
||||
}
|
||||
|
||||
@Test(expected = HttpClientErrorException.class)
|
||||
@Test
|
||||
public void handleError() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||
@@ -80,7 +80,13 @@ public class DefaultResponseErrorHandlerTests {
|
||||
|
||||
replay(response);
|
||||
|
||||
handler.handleError(response);
|
||||
try {
|
||||
handler.handleError(response);
|
||||
fail("expected HttpClientErrorException");
|
||||
}
|
||||
catch (HttpClientErrorException e) {
|
||||
assertSame(headers, e.getResponseHeaders());
|
||||
}
|
||||
|
||||
verify(response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user