Browse Source

Rename MimeType's getCharSet() to getCharset()

Issue: SPR-14172
pull/1035/head
Juergen Hoeller 10 years ago
parent
commit
f1cb793ccb
  1. 145
      spring-core/src/main/java/org/springframework/util/MimeType.java
  2. 6
      spring-core/src/test/java/org/springframework/util/MimeTypeTests.java
  3. 4
      spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java
  4. 4
      spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java
  5. 2
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java
  6. 4
      spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
  7. 4
      spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java
  8. 4
      spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java
  9. 2
      spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java
  10. 4
      spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
  11. 4
      spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java
  12. 2
      spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
  13. 4
      spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java
  14. 4
      spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java
  15. 4
      spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java
  16. 4
      spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java
  17. 2
      spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
  18. 4
      spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java
  19. 2
      spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java
  20. 2
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java
  21. 2
      spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
  22. 2
      spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java
  23. 2
      spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java
  24. 4
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
  25. 4
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

145
spring-core/src/main/java/org/springframework/util/MimeType.java

@ -51,19 +51,12 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -51,19 +51,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
private static final long serialVersionUID = 4085923477777865903L;
protected static final String WILDCARD_TYPE = "*";
private static final BitSet TOKEN;
protected static final String WILDCARD_TYPE = "*";
private static final String PARAM_CHARSET = "charset";
private final String type;
private final String subtype;
private final Map<String, String> parameters;
private static final BitSet TOKEN;
static {
// variable names refer to RFC 2616, section 2.2
@ -101,6 +94,13 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -101,6 +94,13 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
private final String type;
private final String subtype;
private final Map<String, String> parameters;
/**
* Create a new {@code MimeType} for the given primary type.
* <p>The {@linkplain #getSubtype() subtype} is set to <code>"&#42;"</code>,
@ -140,17 +140,12 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -140,17 +140,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
* @param other the other media type
* @param charset the character set
* @throws IllegalArgumentException if any of the parameters contains illegal characters
* @since 4.3
*/
public MimeType(MimeType other, Charset charset) {
this(other.getType(), other.getSubtype(), addCharsetParameter(charset, other.getParameters()));
}
private static Map<String, String> addCharsetParameter(Charset charset, Map<String, String> parameters) {
Map<String, String> map = new LinkedHashMap<String, String>(parameters);
map.put(PARAM_CHARSET, charset.name());
return map;
}
/**
* Copy-constructor that copies the type and subtype of the given {@code MimeType},
* and allows for different parameter.
@ -279,12 +274,24 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -279,12 +274,24 @@ public class MimeType implements Comparable<MimeType>, Serializable {
/**
* Return the character set, as indicated by a {@code charset} parameter, if any.
* @return the character set, or {@code null} if not available
* @since 4.3
*/
public Charset getCharSet() {
public Charset getCharset() {
String charSet = getParameter(PARAM_CHARSET);
return (charSet != null ? Charset.forName(unquote(charSet)) : null);
}
/**
* Return the character set, as indicated by a {@code charset} parameter, if any.
* @return the character set, or {@code null} if not available
* @deprecated as of Spring 4.3, in favor of {@link #getCharset()} with its name
* aligned with the Java return type name
*/
@Deprecated
public Charset getCharSet() {
return getCharset();
}
/**
* Return a generic parameter value, given a parameter name.
* @param name the parameter name
@ -392,50 +399,6 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -392,50 +399,6 @@ public class MimeType implements Comparable<MimeType>, Serializable {
return false;
}
/**
* Compares this {@code MediaType} to another alphabetically.
* @param other media type to compare to
* @see MimeTypeUtils#sortBySpecificity(List)
*/
@Override
public int compareTo(MimeType other) {
int comp = getType().compareToIgnoreCase(other.getType());
if (comp != 0) {
return comp;
}
comp = getSubtype().compareToIgnoreCase(other.getSubtype());
if (comp != 0) {
return comp;
}
comp = getParameters().size() - other.getParameters().size();
if (comp != 0) {
return comp;
}
TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
thisAttributes.addAll(getParameters().keySet());
TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
otherAttributes.addAll(other.getParameters().keySet());
Iterator<String> thisAttributesIterator = thisAttributes.iterator();
Iterator<String> otherAttributesIterator = otherAttributes.iterator();
while (thisAttributesIterator.hasNext()) {
String thisAttribute = thisAttributesIterator.next();
String otherAttribute = otherAttributesIterator.next();
comp = thisAttribute.compareToIgnoreCase(otherAttribute);
if (comp != 0) {
return comp;
}
String thisValue = getParameters().get(thisAttribute);
String otherValue = other.getParameters().get(otherAttribute);
if (otherValue == null) {
otherValue = "";
}
comp = thisValue.compareTo(otherValue);
if (comp != 0) {
return comp;
}
}
return 0;
}
@Override
public boolean equals(Object other) {
@ -457,22 +420,22 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -457,22 +420,22 @@ public class MimeType implements Comparable<MimeType>, Serializable {
* for {@link Charset}s.
* @since 4.2
*/
private boolean parametersAreEqual(MimeType that) {
if (this.parameters.size() != that.parameters.size()) {
private boolean parametersAreEqual(MimeType other) {
if (this.parameters.size() != other.parameters.size()) {
return false;
}
for (String key : this.parameters.keySet()) {
if (!that.parameters.containsKey(key)) {
if (!other.parameters.containsKey(key)) {
return false;
}
if (PARAM_CHARSET.equals(key)) {
if (!ObjectUtils.nullSafeEquals(this.getCharSet(), that.getCharSet())) {
if (!ObjectUtils.nullSafeEquals(getCharset(), other.getCharset())) {
return false;
}
}
else if (!ObjectUtils.nullSafeEquals(this.parameters.get(key), that.parameters.get(key))) {
else if (!ObjectUtils.nullSafeEquals(this.parameters.get(key), other.parameters.get(key))) {
return false;
}
}
@ -511,6 +474,52 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -511,6 +474,52 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
}
/**
* Compares this {@code MediaType} to another alphabetically.
* @param other media type to compare to
* @see MimeTypeUtils#sortBySpecificity(List)
*/
@Override
public int compareTo(MimeType other) {
int comp = getType().compareToIgnoreCase(other.getType());
if (comp != 0) {
return comp;
}
comp = getSubtype().compareToIgnoreCase(other.getSubtype());
if (comp != 0) {
return comp;
}
comp = getParameters().size() - other.getParameters().size();
if (comp != 0) {
return comp;
}
TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
thisAttributes.addAll(getParameters().keySet());
TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
otherAttributes.addAll(other.getParameters().keySet());
Iterator<String> thisAttributesIterator = thisAttributes.iterator();
Iterator<String> otherAttributesIterator = otherAttributes.iterator();
while (thisAttributesIterator.hasNext()) {
String thisAttribute = thisAttributesIterator.next();
String otherAttribute = otherAttributesIterator.next();
comp = thisAttribute.compareToIgnoreCase(otherAttribute);
if (comp != 0) {
return comp;
}
String thisValue = getParameters().get(thisAttribute);
String otherValue = other.getParameters().get(otherAttribute);
if (otherValue == null) {
otherValue = "";
}
comp = thisValue.compareTo(otherValue);
if (comp != 0) {
return comp;
}
}
return 0;
}
/**
* Parse the given String value into a {@code MimeType} object,
* with this method name following the 'valueOf' naming convention
@ -521,6 +530,12 @@ public class MimeType implements Comparable<MimeType>, Serializable { @@ -521,6 +530,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
return MimeTypeUtils.parseMimeType(value);
}
private static Map<String, String> addCharsetParameter(Charset charset, Map<String, String> parameters) {
Map<String, String> map = new LinkedHashMap<String, String>(parameters);
map.put(PARAM_CHARSET, charset.name());
return map;
}
public static class SpecificityComparator<T extends MimeType> implements Comparator<T> {

6
spring-core/src/test/java/org/springframework/util/MimeTypeTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -75,7 +75,7 @@ public class MimeTypeTests { @@ -75,7 +75,7 @@ public class MimeTypeTests {
MimeType mimeType = MimeType.valueOf(s);
assertEquals("Invalid type", "text", mimeType.getType());
assertEquals("Invalid subtype", "html", mimeType.getSubtype());
assertEquals("Invalid charset", Charset.forName("ISO-8859-1"), mimeType.getCharSet());
assertEquals("Invalid charset", Charset.forName("ISO-8859-1"), mimeType.getCharset());
}
@Test
@ -84,7 +84,7 @@ public class MimeTypeTests { @@ -84,7 +84,7 @@ public class MimeTypeTests {
MimeType mimeType = MimeType.valueOf(s);
assertEquals("Invalid type", "application", mimeType.getType());
assertEquals("Invalid subtype", "xml", mimeType.getSubtype());
assertEquals("Invalid charset", Charset.forName("UTF-8"), mimeType.getCharSet());
assertEquals("Invalid charset", Charset.forName("UTF-8"), mimeType.getCharset());
}
@Test

4
spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java

@ -300,8 +300,8 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { @@ -300,8 +300,8 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
* @return the JSON encoding to use (never {@code null})
*/
protected JsonEncoding getJsonEncoding(MimeType contentType) {
if ((contentType != null) && (contentType.getCharSet() != null)) {
Charset charset = contentType.getCharSet();
if ((contentType != null) && (contentType.getCharset() != null)) {
Charset charset = contentType.getCharset();
for (JsonEncoding encoding : JsonEncoding.values()) {
if (charset.name().equals(encoding.getJavaName())) {
return encoding;

4
spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java

@ -66,8 +66,8 @@ public class StringMessageConverter extends AbstractMessageConverter { @@ -66,8 +66,8 @@ public class StringMessageConverter extends AbstractMessageConverter {
}
private Charset getContentTypeCharset(MimeType mimeType) {
if (mimeType != null && mimeType.getCharSet() != null) {
return mimeType.getCharSet();
if (mimeType != null && mimeType.getCharset() != null) {
return mimeType.getCharset();
}
else {
return this.defaultCharset;

2
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

@ -440,7 +440,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { @@ -440,7 +440,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
if (bytes.length == 0 || getContentType() == null || !isReadableContentType()) {
return contentType;
}
Charset charset = getContentType().getCharSet();
Charset charset = getContentType().getCharset();
charset = (charset != null ? charset : StompDecoder.UTF8_CHARSET);
return (bytes.length < 80) ?
contentType + " payload=" + new String(bytes, charset) :

4
spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java

@ -501,7 +501,7 @@ public class MessageHeaderAccessor { @@ -501,7 +501,7 @@ public class MessageHeaderAccessor {
else if (payload instanceof byte[]) {
byte[] bytes = (byte[]) payload;
if (isReadableContentType()) {
Charset charset = getContentType().getCharSet();
Charset charset = getContentType().getCharset();
charset = (charset != null ? charset : DEFAULT_CHARSET);
return (bytes.length < 80) ?
" payload=" + new String(bytes, charset) :
@ -526,7 +526,7 @@ public class MessageHeaderAccessor { @@ -526,7 +526,7 @@ public class MessageHeaderAccessor {
else if (payload instanceof byte[]) {
byte[] bytes = (byte[]) payload;
if (isReadableContentType()) {
Charset charset = getContentType().getCharSet();
Charset charset = getContentType().getCharset();
charset = (charset != null ? charset : DEFAULT_CHARSET);
return " payload=" + new String(bytes, charset);
}

4
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

@ -390,8 +390,8 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -390,8 +390,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
if (contentType != null) {
try {
MediaType mediaType = MediaType.parseMediaType(contentType);
if (mediaType.getCharSet() != null) {
this.characterEncoding = mediaType.getCharSet().name();
if (mediaType.getCharset() != null) {
this.characterEncoding = mediaType.getCharset().name();
}
}
catch (Exception ex) {

4
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

@ -236,8 +236,8 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -236,8 +236,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
if (contentType != null) {
try {
MediaType mediaType = MediaType.parseMediaType(contentType);
if (mediaType.getCharSet() != null) {
this.characterEncoding = mediaType.getCharSet().name();
if (mediaType.getCharset() != null) {
this.characterEncoding = mediaType.getCharset().name();
this.charset = true;
}
}

2
spring-web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java

@ -246,7 +246,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv @@ -246,7 +246,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
contentTypeToUse = (mediaType != null ? mediaType : contentTypeToUse);
}
if (contentTypeToUse != null) {
if (contentTypeToUse.getCharSet() == null && this.defaultCharset != null) {
if (contentTypeToUse.getCharset() == null && this.defaultCharset != null) {
contentTypeToUse = new MediaType(contentTypeToUse, this.defaultCharset);
}
headers.setContentType(contentTypeToUse);

4
spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

@ -202,7 +202,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue @@ -202,7 +202,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = (contentType.getCharSet() != null ? contentType.getCharSet() : this.charset);
Charset charset = (contentType.getCharset() != null ? contentType.getCharset() : this.charset);
String body = StreamUtils.copyToString(inputMessage.getBody(), charset);
String[] pairs = StringUtils.tokenizeToStringArray(body, "&");
@ -255,7 +255,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue @@ -255,7 +255,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
Charset charset;
if (contentType != null) {
outputMessage.getHeaders().setContentType(contentType);
charset = contentType.getCharSet() != null ? contentType.getCharSet() : this.charset;
charset = contentType.getCharset() != null ? contentType.getCharset() : this.charset;
}
else {
outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);

4
spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java

@ -118,8 +118,8 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str @@ -118,8 +118,8 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
}
private Charset getContentTypeCharset(MediaType contentType) {
if (contentType != null && contentType.getCharSet() != null) {
return contentType.getCharSet();
if (contentType != null && contentType.getCharset() != null) {
return contentType.getCharset();
}
else {
return this.getDefaultCharset();

2
spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java

@ -66,7 +66,7 @@ public abstract class AbstractWireFeedHttpMessageConverter<T extends WireFeed> e @@ -66,7 +66,7 @@ public abstract class AbstractWireFeedHttpMessageConverter<T extends WireFeed> e
WireFeedInput feedInput = new WireFeedInput();
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset =
(contentType != null && contentType.getCharSet() != null? contentType.getCharSet() : DEFAULT_CHARSET);
(contentType != null && contentType.getCharset() != null? contentType.getCharset() : DEFAULT_CHARSET);
try {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
return (T) feedInput.build(reader);

4
spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java

@ -348,8 +348,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener @@ -348,8 +348,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
* @return the JSON encoding to use (never {@code null})
*/
protected JsonEncoding getJsonEncoding(MediaType contentType) {
if (contentType != null && contentType.getCharSet() != null) {
Charset charset = contentType.getCharSet();
if (contentType != null && contentType.getCharset() != null) {
Charset charset = contentType.getCharset();
for (JsonEncoding encoding : JsonEncoding.values()) {
if (charset.name().equals(encoding.getJavaName())) {
return encoding;

4
spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java

@ -178,10 +178,10 @@ public class GsonHttpMessageConverter extends AbstractGenericHttpMessageConverte @@ -178,10 +178,10 @@ public class GsonHttpMessageConverter extends AbstractGenericHttpMessageConverte
}
private Charset getCharset(HttpHeaders headers) {
if (headers == null || headers.getContentType() == null || headers.getContentType().getCharSet() == null) {
if (headers == null || headers.getContentType() == null || headers.getContentType().getCharset() == null) {
return DEFAULT_CHARSET;
}
return headers.getContentType().getCharSet();
return headers.getContentType().getCharset();
}
@Override

4
spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java

@ -116,7 +116,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M @@ -116,7 +116,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
if (contentType == null) {
contentType = PROTOBUF;
}
Charset charset = contentType.getCharSet();
Charset charset = contentType.getCharset();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
@ -160,7 +160,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M @@ -160,7 +160,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
if (contentType == null) {
contentType = getDefaultContentType(message);
}
Charset charset = contentType.getCharSet();
Charset charset = contentType.getCharset();
if (charset == null) {
charset = DEFAULT_CHARSET;
}

4
spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java

@ -195,8 +195,8 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa @@ -195,8 +195,8 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
}
private void setCharset(MediaType contentType, Marshaller marshaller) throws PropertyException {
if (contentType != null && contentType.getCharSet() != null) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, contentType.getCharSet().name());
if (contentType != null && contentType.getCharset() != null) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, contentType.getCharset().name());
}
}

2
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

@ -121,7 +121,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest { @@ -121,7 +121,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
this.headers.setContentType(contentType);
}
}
if (contentType != null && contentType.getCharSet() == null) {
if (contentType != null && contentType.getCharset() == null) {
String requestEncoding = this.servletRequest.getCharacterEncoding();
if (StringUtils.hasLength(requestEncoding)) {
Charset charSet = Charset.forName(requestEncoding);

4
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java

@ -114,8 +114,8 @@ public class ServletServerHttpResponse implements ServerHttpResponse { @@ -114,8 +114,8 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
this.servletResponse.setContentType(this.headers.getContentType().toString());
}
if (this.servletResponse.getCharacterEncoding() == null && this.headers.getContentType() != null &&
this.headers.getContentType().getCharSet() != null) {
this.servletResponse.setCharacterEncoding(this.headers.getContentType().getCharSet().name());
this.headers.getContentType().getCharset() != null) {
this.servletResponse.setCharacterEncoding(this.headers.getContentType().getCharset().name());
}
this.headersWritten = true;
}

2
spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java

@ -113,7 +113,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler { @@ -113,7 +113,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
private Charset getCharset(ClientHttpResponse response) {
HttpHeaders headers = response.getHeaders();
MediaType contentType = headers.getContentType();
return contentType != null ? contentType.getCharSet() : null;
return contentType != null ? contentType.getCharset() : null;
}
}

2
spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

@ -735,7 +735,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -735,7 +735,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
List<MediaType> supportedMediaTypes = messageConverter.getSupportedMediaTypes();
List<MediaType> result = new ArrayList<MediaType>(supportedMediaTypes.size());
for (MediaType supportedMediaType : supportedMediaTypes) {
if (supportedMediaType.getCharSet() != null) {
if (supportedMediaType.getCharset() != null) {
supportedMediaType =
new MediaType(supportedMediaType.getType(), supportedMediaType.getSubtype());
}

2
spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java

@ -304,7 +304,7 @@ public abstract class CommonsFileUploadSupport { @@ -304,7 +304,7 @@ public abstract class CommonsFileUploadSupport {
return defaultEncoding;
}
MediaType contentType = MediaType.parseMediaType(contentTypeHeader);
Charset charset = contentType.getCharSet();
Charset charset = contentType.getCharset();
return (charset != null ? charset.name() : defaultEncoding);
}

2
spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java

@ -103,7 +103,7 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques @@ -103,7 +103,7 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques
private String determineEncoding() {
MediaType contentType = getHeaders().getContentType();
if (contentType != null) {
Charset charset = contentType.getCharSet();
Charset charset = contentType.getCharset();
if (charset != null) {
return charset.name();
}

2
spring-web/src/test/java/org/springframework/http/converter/FormHttpMessageConverterTests.java

@ -261,7 +261,7 @@ public class FormHttpMessageConverterTests { @@ -261,7 +261,7 @@ public class FormHttpMessageConverterTests {
@Override
public String getCharacterEncoding() {
MediaType type = this.outputMessage.getHeaders().getContentType();
return (type != null && type.getCharSet() != null ? type.getCharSet().name() : null);
return (type != null && type.getCharset() != null ? type.getCharset().name() : null);
}
@Override

4
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java

@ -390,8 +390,8 @@ public class MockHttpServletRequest implements HttpServletRequest { @@ -390,8 +390,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
if (contentType != null) {
try {
MediaType mediaType = MediaType.parseMediaType(contentType);
if (mediaType.getCharSet() != null) {
this.characterEncoding = mediaType.getCharSet().name();
if (mediaType.getCharset() != null) {
this.characterEncoding = mediaType.getCharset().name();
}
}
catch (Exception ex) {

4
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

@ -236,8 +236,8 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -236,8 +236,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
if (contentType != null) {
try {
MediaType mediaType = MediaType.parseMediaType(contentType);
if (mediaType.getCharSet() != null) {
this.characterEncoding = mediaType.getCharSet().name();
if (mediaType.getCharset() != null) {
this.characterEncoding = mediaType.getCharset().name();
this.charset = true;
}
}

Loading…
Cancel
Save