Top Description Fields Constructors Methods
org.springframework.web.client

public Class RestClientResponseException

extends RestClientException
Class Inheritance
Known Direct Subclasses
org.springframework.web.client.UnknownHttpStatusCodeException, org.springframework.web.client.HttpStatusCodeException
Imports
java.io.UnsupportedEncodingException, java.nio.charset.Charset, .StandardCharsets, java.util.Locale, java.util.function.Function, org.springframework.core.ParameterizedTypeReference, .ResolvableType, org.springframework.http.HttpHeaders, .HttpStatusCode, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedCaseInsensitiveMap, .MultiValueMap

Common base class for exceptions that contain actual HTTP response data.
Author
Rossen Stoyanchev
Since
4.3

Field Summary

Modifier and TypeField and Description
private transient Function<ResolvableType, ?>
private static final Charset
private final byte[]
private final String
private final HttpHeaders
private static final long
private final HttpStatusCode
private final String

Constructor Summary

AccessConstructor and Description
public
RestClientResponseException(String message, int
the raw status code value
statusCode
,
String
the status text
statusText
,
HttpHeaders
the response headers (may be null)
headers
,
byte[]
the response body content (may be null)
responseBody
,
Charset
the response body charset (may be null)
responseCharset
)

Construct a new instance of with the given response data.

public
RestClientResponseException(String message, HttpStatusCode
the raw status code value
statusCode
,
String
the status text
statusText
,
HttpHeaders
the response headers (may be null)
headers
,
byte[]
the response body content (may be null)
responseBody
,
Charset
the response body charset (may be null)
responseCharset
)

Construct a new instance of with the given response data.

Method Summary

Modifier and TypeMethod and Description
private static HttpHeaders
copyHeaders(HttpHeaders headers)

Copies the given headers, because the backing map might not be serializable.

public int
getRawStatusCode()

Deprecated since 6.0. as of 6.0, in favor of getStatusCode()
Return the raw HTTP status code value.
public <
the expected target type
E
>
E

Returns:

the converted object, or null if there is no content
getResponseBodyAs
(Class<E>
the type to convert to
targetType
)

Convert the error response content to the specified type.

public <E> E
private <E> E
public byte[]
getResponseBodyAsByteArray()

Return the response body as a byte array.

public String
getResponseBodyAsString()

Return the response body converted to String.

public String
getResponseBodyAsString(Charset
the charset to use on if the response doesn't specify.
fallbackCharset
)

Return the response body converted to String.

public HttpHeaders
getResponseHeaders()

Return the HTTP response headers.

public HttpStatusCode
getStatusCode()

Return the HTTP status code.

public String
getStatusText()

Return the HTTP status text.

public void
setBodyConvertFunction(Function<ResolvableType, ?>
the function to use
bodyConvertFunction
)

Provide a function to use to decode the response error content via getResponseBodyAs(Class).

Field Detail

bodyConvertFunctionback to summary
private transient Function<ResolvableType, ?> bodyConvertFunction
Annotations
@Nullable
DEFAULT_CHARSETback to summary
private static final Charset DEFAULT_CHARSET
responseBodyback to summary
private final byte[] responseBody
responseCharsetback to summary
private final String responseCharset
Annotations
@Nullable
responseHeadersback to summary
private final HttpHeaders responseHeaders
Annotations
@Nullable
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.springframework.web.client.RestClientException.serialVersionUID.

statusCodeback to summary
private final HttpStatusCode statusCode
statusTextback to summary
private final String statusText

Constructor Detail

RestClientResponseExceptionback to summary
public RestClientResponseException(String message, int statusCode, String statusText, HttpHeaders headers, byte[] responseBody, Charset responseCharset)

Construct a new instance of with the given response data.

Parameters
statusCode:int

the raw status code value

statusText:String

the status text

headers:HttpHeaders

the response headers (may be null)

responseBody:byte[]

the response body content (may be null)

responseCharset:Charset

the response body charset (may be null)

RestClientResponseExceptionback to summary
public RestClientResponseException(String message, HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] responseBody, Charset responseCharset)

Construct a new instance of with the given response data.

Parameters
statusCode:HttpStatusCode

the raw status code value

statusText:String

the status text

headers:HttpHeaders

the response headers (may be null)

responseBody:byte[]

the response body content (may be null)

responseCharset:Charset

the response body charset (may be null)

Since
6.0

Method Detail

copyHeadersback to summary
private static HttpHeaders copyHeaders(HttpHeaders headers)

Copies the given headers, because the backing map might not be serializable.

Annotations
@Nullable
getRawStatusCodeback to summary
public int getRawStatusCode()

Deprecated

since 6.0.

as of 6.0, in favor of getStatusCode()

Return the raw HTTP status code value.

Annotations
@Deprecated
since:6.0
getResponseBodyAsback to summary
public <E> E getResponseBodyAs(Class<E> targetType)

Convert the error response content to the specified type.

Parameters
<E>
the expected target type
targetType:Class<E>

the type to convert to

Returns:E

the converted object, or null if there is no content

Annotations
@Nullable
Since
6.0
getResponseBodyAsback to summary
public <E> E getResponseBodyAs(ParameterizedTypeReference<E> targetType)

Variant of getResponseBodyAs(Class) with ParameterizedTypeReference.

Annotations
@Nullable
Since
6.0
getResponseBodyAsback to summary
private <E> E getResponseBodyAs(ResolvableType targetType)
Annotations
@SuppressWarnings:unchecked
@Nullable
getResponseBodyAsByteArrayback to summary
public byte[] getResponseBodyAsByteArray()

Return the response body as a byte array.

getResponseBodyAsStringback to summary
public String getResponseBodyAsString()

Return the response body converted to String. The charset used is that of the response "Content-Type" or otherwise "UTF-8".

getResponseBodyAsStringback to summary
public String getResponseBodyAsString(Charset fallbackCharset)

Return the response body converted to String. The charset used is that of the response "Content-Type" or otherwise the one given.

Parameters
fallbackCharset:Charset

the charset to use on if the response doesn't specify.

Since
5.1.11
getResponseHeadersback to summary
public HttpHeaders getResponseHeaders()

Return the HTTP response headers.

Annotations
@Nullable
getStatusCodeback to summary
public HttpStatusCode getStatusCode()

Return the HTTP status code.

Since
6.0
getStatusTextback to summary
public String getStatusText()

Return the HTTP status text.

setBodyConvertFunctionback to summary
public void setBodyConvertFunction(Function<ResolvableType, ?> bodyConvertFunction)

Provide a function to use to decode the response error content via getResponseBodyAs(Class).

Parameters
bodyConvertFunction:Function<ResolvableType, ?>

the function to use

Since
6.0