Consistent use of IllegalStateException instead of InternalError for UnsupportedEncodingException cause
This commit is contained in:
@@ -81,7 +81,7 @@ public class MockHttpOutputMessage implements HttpOutputMessage {
|
|||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException ex) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// should not occur
|
// should not occur
|
||||||
throw new InternalError(ex.getMessage());
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -35,6 +35,7 @@ public abstract class HttpStatusCodeException extends RestClientException {
|
|||||||
|
|
||||||
private static final String DEFAULT_CHARSET = "ISO-8859-1";
|
private static final String DEFAULT_CHARSET = "ISO-8859-1";
|
||||||
|
|
||||||
|
|
||||||
private final HttpStatus statusCode;
|
private final HttpStatus statusCode;
|
||||||
|
|
||||||
private final String statusText;
|
private final String statusText;
|
||||||
@@ -74,10 +75,9 @@ public abstract class HttpStatusCodeException extends RestClientException {
|
|||||||
* @param responseCharset the response body charset, may be {@code null}
|
* @param responseCharset the response body charset, may be {@code null}
|
||||||
* @since 3.0.5
|
* @since 3.0.5
|
||||||
*/
|
*/
|
||||||
protected HttpStatusCodeException(HttpStatus statusCode,
|
protected HttpStatusCodeException(
|
||||||
String statusText,
|
HttpStatus statusCode, String statusText, byte[] responseBody, Charset responseCharset) {
|
||||||
byte[] responseBody,
|
|
||||||
Charset responseCharset) {
|
|
||||||
this(statusCode, statusText, null, responseBody, responseCharset);
|
this(statusCode, statusText, null, responseBody, responseCharset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +93,7 @@ public abstract class HttpStatusCodeException extends RestClientException {
|
|||||||
*/
|
*/
|
||||||
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
|
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
|
||||||
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
|
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;
|
||||||
@@ -126,11 +127,10 @@ public abstract class HttpStatusCodeException extends RestClientException {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
return responseBody;
|
return this.responseBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,11 +139,11 @@ public abstract class HttpStatusCodeException extends RestClientException {
|
|||||||
*/
|
*/
|
||||||
public String getResponseBodyAsString() {
|
public String getResponseBodyAsString() {
|
||||||
try {
|
try {
|
||||||
return new String(responseBody, responseCharset);
|
return new String(this.responseBody, this.responseCharset);
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException ex) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// should not occur
|
// should not occur
|
||||||
throw new InternalError(ex.getMessage());
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.client;
|
package org.springframework.web.client;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@@ -64,6 +65,7 @@ public class UnknownHttpStatusCodeException extends RestClientException {
|
|||||||
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
|
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the raw HTTP status code value.
|
* Return the raw HTTP status code value.
|
||||||
*/
|
*/
|
||||||
@@ -89,7 +91,7 @@ public class UnknownHttpStatusCodeException extends RestClientException {
|
|||||||
* Return the response body as a byte array.
|
* Return the response body as a byte array.
|
||||||
*/
|
*/
|
||||||
public byte[] getResponseBodyAsByteArray() {
|
public byte[] getResponseBodyAsByteArray() {
|
||||||
return responseBody;
|
return this.responseBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,11 +99,11 @@ public class UnknownHttpStatusCodeException extends RestClientException {
|
|||||||
*/
|
*/
|
||||||
public String getResponseBodyAsString() {
|
public String getResponseBodyAsString() {
|
||||||
try {
|
try {
|
||||||
return new String(responseBody, responseCharset);
|
return new String(this.responseBody, this.responseCharset);
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException ex) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// should not occur
|
// should not occur
|
||||||
throw new InternalError(ex.getMessage());
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
|||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an immutable collection of URI components, mapping component type to string
|
* Represents an immutable collection of URI components, mapping component type to String
|
||||||
* values. Contains convenience getters for all components. Effectively similar to {@link
|
* values. Contains convenience getters for all components. Effectively similar to {@link
|
||||||
* java.net.URI}, but with more powerful encoding options and support for URI template
|
* java.net.URI}, but with more powerful encoding options and support for URI template
|
||||||
* variables.
|
* variables.
|
||||||
@@ -119,14 +119,15 @@ public abstract class UriComponents implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Encode all URI components using their specific encoding rules, and returns the
|
* Encode all URI components using their specific encoding rules, and returns the
|
||||||
* result as a new {@code UriComponents} instance. This method uses UTF-8 to encode.
|
* result as a new {@code UriComponents} instance. This method uses UTF-8 to encode.
|
||||||
* @return the encoded uri components
|
* @return the encoded URI components
|
||||||
*/
|
*/
|
||||||
public final UriComponents encode() {
|
public final UriComponents encode() {
|
||||||
try {
|
try {
|
||||||
return encode(DEFAULT_ENCODING);
|
return encode(DEFAULT_ENCODING);
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
throw new InternalError("\"" + DEFAULT_ENCODING + "\" not supported");
|
// should not occur
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ public abstract class UriComponents implements Serializable {
|
|||||||
public abstract UriComponents encode(String encoding) throws UnsupportedEncodingException;
|
public abstract UriComponents encode(String encoding) throws UnsupportedEncodingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all URI template variables with the values from a given map. The map keys
|
* Replace all URI template variables with the values from a given map. The map keys
|
||||||
* represent variable names; the values variable values. The order of variables is not
|
* represent variable names; the values variable values. The order of variables is not
|
||||||
* significant.
|
* significant.
|
||||||
* @param uriVariables the map of URI variables
|
* @param uriVariables the map of URI variables
|
||||||
@@ -152,7 +153,7 @@ public abstract class UriComponents implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all URI template variables with the values from a given array. The array
|
* Replace all URI template variables with the values from a given array. The array
|
||||||
* represent variable values. The order of variables is significant.
|
* represent variable values. The order of variables is significant.
|
||||||
* @param uriVariableValues URI variable values
|
* @param uriVariableValues URI variable values
|
||||||
* @return the expanded uri components
|
* @return the expanded uri components
|
||||||
@@ -163,7 +164,7 @@ public abstract class UriComponents implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all URI template variables with the values obtained through the
|
* Replace all URI template variables with the values obtained through the
|
||||||
* given {@link UriTemplateVariables} instance.
|
* given {@link UriTemplateVariables} instance.
|
||||||
* @param uriTemplateVars resolves URI template variable values
|
* @param uriTemplateVars resolves URI template variable values
|
||||||
* @return the expanded uri components
|
* @return the expanded uri components
|
||||||
@@ -174,7 +175,7 @@ public abstract class UriComponents implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces all URI template variables with the values from the given {@link
|
* Replace all URI template variables with the values from the given {@link
|
||||||
* UriTemplateVariables}
|
* UriTemplateVariables}
|
||||||
* @param uriVariables URI template values
|
* @param uriVariables URI template values
|
||||||
* @return the expanded uri components
|
* @return the expanded uri components
|
||||||
@@ -188,12 +189,12 @@ public abstract class UriComponents implements Serializable {
|
|||||||
public abstract UriComponents normalize();
|
public abstract UriComponents normalize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a URI string from this {@code UriComponents} instance.
|
* Return a URI string from this {@code UriComponents} instance.
|
||||||
*/
|
*/
|
||||||
public abstract String toUriString();
|
public abstract String toUriString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@code URI} from this {@code UriComponents} instance.
|
* Return a {@code URI} from this {@code UriComponents} instance.
|
||||||
*/
|
*/
|
||||||
public abstract URI toUri();
|
public abstract URI toUri();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user