From bca2357be784d62bbcc8f4e4d520fd5c778c712c Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 1 Jun 2012 16:08:01 +0200 Subject: [PATCH 1/2] Polish web.client exceptions and related classes The following style updates have been made in anticipation of substantive changes in subsequent commits: - organize imports - correct whitespace errors (leading spaces in code, tabs in Javadoc) - wrap Javadoc at 90 chars; make imperative ("Return" vs. "Returns") - use conventional constructor argument wrapping A serialVersionUID has also been added to RestClientException and its ResourceAccessException subclass for consistency with the rest of that same exception hierarchy. Issue: SPR-7938 --- .../org/springframework/http/HttpHeaders.java | 5 ++- .../client/DefaultResponseErrorHandler.java | 23 ++++++------- .../web/client/HttpClientErrorException.java | 25 ++++++++------- .../web/client/HttpServerErrorException.java | 21 ++++++------ .../web/client/HttpStatusCodeException.java | 32 +++++++++---------- .../web/client/ResourceAccessException.java | 5 ++- .../web/client/RestClientException.java | 11 +++++-- .../DefaultResponseErrorHandlerTests.java | 18 +++++++---- 8 files changed, 78 insertions(+), 62 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 2bc17bb2c7c..db44db0c80f 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -17,9 +17,12 @@ package org.springframework.http; import java.net.URI; + import java.nio.charset.Charset; + import java.text.ParseException; import java.text.SimpleDateFormat; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index 0615f7a823a..924f025384e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -28,10 +28,11 @@ import org.springframework.util.FileCopyUtils; /** * Default implementation of the {@link ResponseErrorHandler} interface. * - *

This error handler checks for the status code on the {@link ClientHttpResponse}: any code with series - * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or - * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR} is considered to be an error. - * This behavior can be changed by overriding the {@link #hasError(HttpStatus)} method. + *

This error handler checks for the status code on the {@link ClientHttpResponse}: any + * code with series {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR} or + * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR} is considered to be an + * error. This behavior can be changed by overriding the {@link #hasError(HttpStatus)} + * method. * * @author Arjen Poutsma * @since 3.0 @@ -83,15 +84,15 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler { private byte[] getResponseBody(ClientHttpResponse response) { try { - InputStream responseBody = response.getBody(); - if (responseBody != null) { - return FileCopyUtils.copyToByteArray(responseBody); - } + InputStream responseBody = response.getBody(); + if (responseBody != null) { + return FileCopyUtils.copyToByteArray(responseBody); + } } catch (IOException ex) { - // ignore + // ignore } - return new byte[0]; + return new byte[0]; } } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java index 99de72b1607..05126bf00c2 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java @@ -31,8 +31,10 @@ public class HttpClientErrorException extends HttpStatusCodeException { private static final long serialVersionUID = 6777393766937023392L; + /** - * Construct a new instance of {@code HttpClientErrorException} based on a {@link HttpStatus}. + * Construct a new instance of {@code HttpClientErrorException} based on an + * {@link HttpStatus}. * @param statusCode the status code */ public HttpClientErrorException(HttpStatus statusCode) { @@ -40,7 +42,8 @@ public class HttpClientErrorException extends HttpStatusCodeException { } /** - * Construct a new instance of {@code HttpClientErrorException} based on a {@link HttpStatus} and status text. + * Construct a new instance of {@code HttpClientErrorException} based on an + * {@link HttpStatus} and status text. * @param statusCode the status code * @param statusText the status text */ @@ -49,18 +52,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { } /** - * Construct a new instance of {@code HttpClientErrorException} based on a {@link HttpStatus}, status text, and - * response body content. - * - * @param statusCode the status code - * @param statusText the status text - * @param responseBody the response body content, may be {@code null} + * Construct a new instance of {@code HttpClientErrorException} based on an + * {@link HttpStatus}, status text, and response body content. + * @param statusCode the status code + * @param statusText the status text + * @param responseBody the response body content, may be {@code null} * @param responseCharset the response body charset, may be {@code null} */ - public HttpClientErrorException(HttpStatus statusCode, - String statusText, - byte[] responseBody, - Charset responseCharset) { + public HttpClientErrorException(HttpStatus statusCode, String statusText, + byte[] responseBody, Charset responseCharset) { super(statusCode, statusText, responseBody, responseCharset); } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java index 9549dcbd0e5..d6ad9653898 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java @@ -31,9 +31,10 @@ public class HttpServerErrorException extends HttpStatusCodeException { private static final long serialVersionUID = -2565832100451369997L; + /** - * Construct a new instance of {@code HttpServerErrorException} based on a {@link HttpStatus}. - * + * Construct a new instance of {@code HttpServerErrorException} based on an + * {@link HttpStatus}. * @param statusCode the status code */ public HttpServerErrorException(HttpStatus statusCode) { @@ -41,8 +42,8 @@ public class HttpServerErrorException extends HttpStatusCodeException { } /** - * Construct a new instance of {@code HttpServerErrorException} based on a {@link HttpStatus} and status text. - * + * Construct a new instance of {@code HttpServerErrorException} based on an + * {@link HttpStatus} and status text. * @param statusCode the status code * @param statusText the status text */ @@ -51,19 +52,17 @@ public class HttpServerErrorException extends HttpStatusCodeException { } /** - * Construct a new instance of {@code HttpServerErrorException} based on a {@link HttpStatus}, status text, and - * response body content. - * + * Construct a new instance of {@code HttpServerErrorException} based on an + * {@link HttpStatus}, status text, and response body content. * @param statusCode the status code * @param statusText the status text * @param responseBody the response body content, may be {@code null} * @param responseCharset the response body charset, may be {@code null} * @since 3.0.5 */ - public HttpServerErrorException(HttpStatus statusCode, - String statusText, - byte[] responseBody, - Charset responseCharset) { + public HttpServerErrorException(HttpStatus statusCode, String statusText, + byte[] responseBody, Charset responseCharset) { super(statusCode, statusText, responseBody, responseCharset); } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java index e2396e0683d..7ec048d4d10 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java @@ -42,9 +42,10 @@ public abstract class HttpStatusCodeException extends RestClientException { private final String responseCharset; + /** - * Construct a new instance of {@code HttpStatusCodeException} based on a {@link HttpStatus}. - * + * Construct a new instance of {@code HttpStatusCodeException} based on an + * {@link HttpStatus}. * @param statusCode the status code */ protected HttpStatusCodeException(HttpStatus statusCode) { @@ -52,8 +53,8 @@ public abstract class HttpStatusCodeException extends RestClientException { } /** - * Construct a new instance of {@code HttpStatusCodeException} based on a {@link HttpStatus} and status text. - * + * Construct a new instance of {@code HttpStatusCodeException} based on an + * {@link HttpStatus} and status text. * @param statusCode the status code * @param statusText the status text */ @@ -62,12 +63,11 @@ public abstract class HttpStatusCodeException extends RestClientException { } /** - * Construct a new instance of {@code HttpStatusCodeException} based on a {@link HttpStatus}, status text, and - * response body content. - * - * @param statusCode the status code - * @param statusText the status text - * @param responseBody the response body content, may be {@code null} + * Construct a new instance of {@code HttpStatusCodeException} based on an + * {@link HttpStatus}, status text, and response body content. + * @param statusCode the status code + * @param statusText the status text + * @param responseBody the response body content, may be {@code null} * @param responseCharset the response body charset, may be {@code null} * @since 3.0.5 */ @@ -82,23 +82,23 @@ public abstract class HttpStatusCodeException extends RestClientException { this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET; } + /** - * Returns the HTTP status code. + * Return the HTTP status code. */ public HttpStatus getStatusCode() { return this.statusCode; } /** - * Returns the HTTP status text. + * Return the HTTP status text. */ public String getStatusText() { return this.statusText; } /** - * Returns the response body as a byte array. - * + * Return the response body as a byte array. * @since 3.0.5 */ public byte[] getResponseBodyAsByteArray() { @@ -106,8 +106,7 @@ public abstract class HttpStatusCodeException extends RestClientException { } /** - * Returns the response body as a string. - * + * Return the response body as a string. * @since 3.0.5 */ public String getResponseBodyAsString() { @@ -119,4 +118,5 @@ public abstract class HttpStatusCodeException extends RestClientException { throw new InternalError(ex.getMessage()); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java b/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java index 8ef27842520..3472b82d599 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java +++ b/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 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. @@ -26,6 +26,9 @@ import java.io.IOException; */ public class ResourceAccessException extends RestClientException { + private static final long serialVersionUID = -8513182514355844870L; + + /** * Construct a new {@code HttpIOException} with the given message. * @param msg the message diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClientException.java b/spring-web/src/main/java/org/springframework/web/client/RestClientException.java index f772ada851d..a741e663a51 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClientException.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClientException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2012 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. @@ -19,13 +19,17 @@ package org.springframework.web.client; import org.springframework.core.NestedRuntimeException; /** - * Base class for exceptions thrown by {@link RestTemplate} whenever it encounters client-side HTTP errors. + * Base class for exceptions thrown by {@link RestTemplate} whenever it encounters + * client-side HTTP errors. * * @author Arjen Poutsma * @since 3.0 */ public class RestClientException extends NestedRuntimeException { + private static final long serialVersionUID = -4084444984163796577L; + + /** * Construct a new instance of {@code HttpClientException} with the given message. * @param msg the message @@ -35,7 +39,8 @@ public class RestClientException extends NestedRuntimeException { } /** - * Construct a new instance of {@code HttpClientException} with the given message and exception. + * Construct a new instance of {@code HttpClientException} with the given message and + * exception. * @param msg the message * @param ex the exception */ diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index 0c9866c19be..129a507543c 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -19,19 +19,23 @@ package org.springframework.web.client; import java.io.ByteArrayInputStream; import java.io.IOException; +import org.junit.Before; +import org.junit.Test; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; -import org.junit.Before; -import org.junit.Test; - import static org.easymock.EasyMock.*; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -/** @author Arjen Poutsma */ +import static org.junit.Assert.*; + +/** + * Unit tests for {@link DefaultResponseErrorHandler}. + * + * @author Arjen Poutsma + */ public class DefaultResponseErrorHandlerTests { private DefaultResponseErrorHandler handler; From b992c3d3f27b44fe3203012e636ac7dca3cf4858 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Thu, 31 May 2012 13:45:10 -0400 Subject: [PATCH 2/2] 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 --- .../org/springframework/http/HttpHeaders.java | 6 +++- .../client/DefaultResponseErrorHandler.java | 8 +++-- .../web/client/HttpClientErrorException.java | 18 +++++++++- .../web/client/HttpServerErrorException.java | 17 +++++++++- .../web/client/HttpStatusCodeException.java | 34 +++++++++++++++++-- .../DefaultResponseErrorHandlerTests.java | 10 ++++-- 6 files changed, 82 insertions(+), 11 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index db44db0c80f..052c1f3408c 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -16,6 +16,8 @@ package org.springframework.http; +import java.io.Serializable; + import java.net.URI; import java.nio.charset.Charset; @@ -57,7 +59,9 @@ import org.springframework.util.StringUtils; * @author Arjen Poutsma * @since 3.0 */ -public class HttpHeaders implements MultiValueMap { +public class HttpHeaders implements MultiValueMap, Serializable { + + private static final long serialVersionUID = -8578554704772377436L; private static final String ACCEPT = "Accept"; diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index 924f025384e..50b291cf4ec 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; @@ -69,14 +70,15 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler { */ public void handleError(ClientHttpResponse response) throws IOException { HttpStatus statusCode = response.getStatusCode(); - MediaType contentType = response.getHeaders().getContentType(); + HttpHeaders headers = response.getHeaders(); + MediaType contentType = headers.getContentType(); Charset charset = contentType != null ? contentType.getCharSet() : null; byte[] body = getResponseBody(response); switch (statusCode.series()) { case CLIENT_ERROR: - throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset); + throw new HttpClientErrorException(statusCode, response.getStatusText(), headers, body, charset); case SERVER_ERROR: - throw new HttpServerErrorException(statusCode, response.getStatusText(), body, charset); + throw new HttpServerErrorException(statusCode, response.getStatusText(), headers, body, charset); default: throw new RestClientException("Unknown status code [" + statusCode + "]"); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java index 05126bf00c2..5d5ef0b40e3 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java @@ -18,6 +18,7 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; /** @@ -29,7 +30,7 @@ import org.springframework.http.HttpStatus; */ public class HttpClientErrorException extends HttpStatusCodeException { - private static final long serialVersionUID = 6777393766937023392L; + private static final long serialVersionUID = 5177019431887513952L; /** @@ -64,4 +65,19 @@ public class HttpClientErrorException extends HttpStatusCodeException { super(statusCode, statusText, responseBody, responseCharset); } + /** + * Construct a new instance of {@code HttpClientErrorException} based on an + * {@link HttpStatus}, status text, and response body content. + * @param statusCode the status code + * @param statusText the status text + * @param responseHeaders the response headers, may be {@code null} + * @param responseBody the response body content, may be {@code null} + * @param responseCharset the response body charset, may be {@code null} + * @since 3.2 + */ + public HttpClientErrorException(HttpStatus statusCode, String statusText, + HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + super(statusCode, statusText, responseHeaders, responseBody, responseCharset); + } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java index d6ad9653898..07bd013a52d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java @@ -18,6 +18,7 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; /** @@ -29,7 +30,7 @@ import org.springframework.http.HttpStatus; */ public class HttpServerErrorException extends HttpStatusCodeException { - private static final long serialVersionUID = -2565832100451369997L; + private static final long serialVersionUID = -2915754006618138282L; /** @@ -65,4 +66,18 @@ public class HttpServerErrorException extends HttpStatusCodeException { super(statusCode, statusText, responseBody, responseCharset); } + /** + * Construct a new instance of {@code HttpServerErrorException} based on a + * {@link HttpStatus}, status text, and response body content. + * @param statusCode the status code + * @param statusText the status text + * @param responseHeaders the response headers, may be {@code null} + * @param responseBody the response body content, may be {@code null} + * @param responseCharset the response body charset, may be {@code null} + * @since 3.2 + */ + public HttpServerErrorException(HttpStatus statusCode, String statusText, + HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { + super(statusCode, statusText, responseHeaders, responseBody, responseCharset); + } } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java index 7ec048d4d10..106ec761d65 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpStatusCodeException.java @@ -19,6 +19,7 @@ package org.springframework.web.client; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; /** @@ -30,7 +31,7 @@ import org.springframework.http.HttpStatus; */ public abstract class HttpStatusCodeException extends RestClientException { - private static final long serialVersionUID = 1549626836533638803L; + private static final long serialVersionUID = -5807494703720513267L; private static final String DEFAULT_CHARSET = "ISO-8859-1"; @@ -40,6 +41,8 @@ public abstract class HttpStatusCodeException extends RestClientException { private final byte[] responseBody; + private final HttpHeaders responseHeaders; + private final String responseCharset; @@ -49,7 +52,7 @@ public abstract class HttpStatusCodeException extends RestClientException { * @param statusCode the status code */ protected HttpStatusCodeException(HttpStatus statusCode) { - this(statusCode, statusCode.name(), null, null); + this(statusCode, statusCode.name(), null, null, null); } /** @@ -59,7 +62,7 @@ public abstract class HttpStatusCodeException extends RestClientException { * @param statusText the status text */ protected HttpStatusCodeException(HttpStatus statusCode, String statusText) { - this(statusCode, statusText, null, null); + this(statusCode, statusText, null, null, null); } /** @@ -75,9 +78,25 @@ public abstract class HttpStatusCodeException extends RestClientException { String statusText, byte[] responseBody, Charset responseCharset) { + this(statusCode, statusText, null, responseBody, responseCharset); + } + + /** + * Construct a new instance of {@code HttpStatusCodeException} based on an + * {@link HttpStatus}, status text, and response body content. + * @param statusCode the status code + * @param statusText the status text + * @param responseHeaders the response headers, may be {@code null} + * @param responseBody the response body content, may be {@code null} + * @param responseCharset the response body charset, may be {@code null} + * @since 3.2 + */ + protected HttpStatusCodeException(HttpStatus statusCode, String statusText, + HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { super(statusCode.value() + " " + statusText); this.statusCode = statusCode; this.statusText = statusText; + this.responseHeaders = responseHeaders; this.responseBody = responseBody != null ? responseBody : new byte[0]; this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET; } @@ -97,8 +116,17 @@ public abstract class HttpStatusCodeException extends RestClientException { return this.statusText; } + /** + * Return the HTTP response headers. + * @since 3.2 + */ + public HttpHeaders getResponseHeaders() { + return this.responseHeaders; + } + /** * Return the response body as a byte array. + * * @since 3.0.5 */ public byte[] getResponseBodyAsByteArray() { diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index 129a507543c..13231a431a5 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -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); }