@ -19,6 +19,7 @@ package org.springframework.web.client;
import java.io.UnsupportedEncodingException ;
import java.io.UnsupportedEncodingException ;
import java.nio.charset.Charset ;
import java.nio.charset.Charset ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.HttpStatus ;
/ * *
/ * *
@ -30,7 +31,7 @@ import org.springframework.http.HttpStatus;
* /
* /
public abstract class HttpStatusCodeException extends RestClientException {
public abstract class HttpStatusCodeException extends RestClientException {
private static final long serialVersionUID = 1549626836533638803 L;
private static final long serialVersionUID = - 5807494703720513267 L;
private static final String DEFAULT_CHARSET = "ISO-8859-1" ;
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 byte [ ] responseBody ;
private final HttpHeaders responseHeaders ;
private final String responseCharset ;
private final String responseCharset ;
@ -49,7 +52,7 @@ public abstract class HttpStatusCodeException extends RestClientException {
* @param statusCode the status code
* @param statusCode the status code
* /
* /
protected HttpStatusCodeException ( HttpStatus statusCode ) {
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
* @param statusText the status text
* /
* /
protected HttpStatusCodeException ( HttpStatus statusCode , String statusText ) {
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 ,
String statusText ,
byte [ ] responseBody ,
byte [ ] responseBody ,
Charset responseCharset ) {
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 ) ;
super ( statusCode . value ( ) + " " + statusText ) ;
this . statusCode = statusCode ;
this . statusCode = statusCode ;
this . statusText = statusText ;
this . statusText = statusText ;
this . responseHeaders = responseHeaders ;
this . responseBody = responseBody ! = null ? responseBody : new byte [ 0 ] ;
this . responseBody = responseBody ! = null ? responseBody : new byte [ 0 ] ;
this . responseCharset = responseCharset ! = null ? responseCharset . name ( ) : DEFAULT_CHARSET ;
this . responseCharset = responseCharset ! = null ? responseCharset . name ( ) : DEFAULT_CHARSET ;
}
}
@ -97,8 +116,17 @@ public abstract class HttpStatusCodeException extends RestClientException {
return this . statusText ;
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 .
* Return the response body as a byte array .
*
* @since 3 . 0 . 5
* @since 3 . 0 . 5
* /
* /
public byte [ ] getResponseBodyAsByteArray ( ) {
public byte [ ] getResponseBodyAsByteArray ( ) {