Consistent use of JDK 7 StandardCharsets over Charset.forName
Issue: SPR-14492
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -47,8 +47,6 @@ public abstract class MimeTypeUtils {
|
||||
|
||||
private static final Random RND = new Random();
|
||||
|
||||
private static Charset US_ASCII = Charset.forName("US-ASCII");
|
||||
|
||||
/**
|
||||
* Public constant mime type that includes all media ranges (i.e. "*/*").
|
||||
*/
|
||||
@@ -349,7 +347,7 @@ public abstract class MimeTypeUtils {
|
||||
* Generate a random MIME boundary as String, often used in multipart mime types.
|
||||
*/
|
||||
public static String generateMultipartBoundaryString() {
|
||||
return new String(generateMultipartBoundary(), US_ASCII);
|
||||
return new String(generateMultipartBoundary(), StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -76,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", StandardCharsets.ISO_8859_1, mimeType.getCharset());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.messaging.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -145,15 +144,14 @@ public class MappingJackson2MessageConverterTests {
|
||||
@Test
|
||||
public void toMessageUtf16() {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
Charset utf16 = Charset.forName("UTF-16BE");
|
||||
MimeType contentType = new MimeType("application", "json", utf16);
|
||||
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(MessageHeaders.CONTENT_TYPE, contentType);
|
||||
MessageHeaders headers = new MessageHeaders(map);
|
||||
String payload = "H\u00e9llo W\u00f6rld";
|
||||
Message<?> message = converter.toMessage(payload, headers);
|
||||
|
||||
assertEquals("\"" + payload + "\"", new String((byte[]) message.getPayload(), utf16));
|
||||
assertEquals("\"" + payload + "\"", new String((byte[]) message.getPayload(), StandardCharsets.UTF_16BE));
|
||||
assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
@@ -162,8 +160,7 @@ public class MappingJackson2MessageConverterTests {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
converter.setSerializedPayloadClass(String.class);
|
||||
|
||||
Charset utf16 = Charset.forName("UTF-16BE");
|
||||
MimeType contentType = new MimeType("application", "json", utf16);
|
||||
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(MessageHeaders.CONTENT_TYPE, contentType);
|
||||
MessageHeaders headers = new MessageHeaders(map);
|
||||
@@ -197,6 +194,20 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
public JacksonViewBean jsonViewResponse() {
|
||||
JacksonViewBean bean = new JacksonViewBean();
|
||||
bean.setWithView1("with");
|
||||
bean.setWithView2("with");
|
||||
bean.setWithoutView("with");
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
|
||||
}
|
||||
|
||||
|
||||
public static class MyBean {
|
||||
|
||||
private String string;
|
||||
@@ -260,9 +271,12 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface MyJacksonView1 {};
|
||||
|
||||
public interface MyJacksonView2 {};
|
||||
|
||||
|
||||
public static class JacksonViewBean {
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
@@ -298,16 +312,4 @@ public class MappingJackson2MessageConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
public JacksonViewBean jsonViewResponse() {
|
||||
JacksonViewBean bean = new JacksonViewBean();
|
||||
bean.setWithView1("with");
|
||||
bean.setWithView2("with");
|
||||
bean.setWithoutView("with");
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -70,10 +69,9 @@ public class StringMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void fromMessageCharset() {
|
||||
Charset iso88591 = Charset.forName("ISO-8859-1");
|
||||
String payload = "H\u00e9llo W\u00f6rld";
|
||||
Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(iso88591))
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain", iso88591)).build();
|
||||
Message<byte[]> message = MessageBuilder.withPayload(payload.getBytes(StandardCharsets.ISO_8859_1))
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, new MimeType("text", "plain", StandardCharsets.ISO_8859_1)).build();
|
||||
assertEquals(payload, this.converter.fromMessage(message, String.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,7 +40,7 @@ import org.springframework.util.StreamUtils;
|
||||
*/
|
||||
public class StringHttpMessageConverter extends AbstractHttpMessageConverter<String> {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.ISO_8859_1;
|
||||
|
||||
|
||||
private final List<Charset> availableCharsets;
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -56,8 +57,6 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||
|
||||
private static final String FILENAME_WITH_CHARSET_KEY = "filename*=";
|
||||
|
||||
private static final Charset US_ASCII = Charset.forName("us-ascii");
|
||||
|
||||
|
||||
private Set<String> multipartParameterNames;
|
||||
|
||||
@@ -161,7 +160,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||
filename = filename.substring(index + 1);
|
||||
}
|
||||
if (charset != null) {
|
||||
filename = new String(filename.getBytes(US_ASCII), charset);
|
||||
filename = new String(filename.getBytes(StandardCharsets.US_ASCII), charset);
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
|
||||
@@ -88,7 +88,7 @@ public class HttpHeadersTests {
|
||||
@Test
|
||||
public void acceptCharsets() {
|
||||
Charset charset1 = StandardCharsets.UTF_8;
|
||||
Charset charset2 = Charset.forName("ISO-8859-1");
|
||||
Charset charset2 = StandardCharsets.ISO_8859_1;
|
||||
List<Charset> charsets = new ArrayList<>(2);
|
||||
charsets.add(charset1);
|
||||
charsets.add(charset2);
|
||||
@@ -100,7 +100,7 @@ public class HttpHeadersTests {
|
||||
@Test
|
||||
public void acceptCharsetWildcard() {
|
||||
headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
|
||||
assertEquals("Invalid Accept header", Arrays.asList(Charset.forName("ISO-8859-1"), StandardCharsets.UTF_8),
|
||||
assertEquals("Invalid Accept header", Arrays.asList(StandardCharsets.ISO_8859_1, StandardCharsets.UTF_8),
|
||||
headers.getAcceptCharset());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import javax.xml.transform.Source;
|
||||
@@ -81,9 +80,8 @@ public class FormHttpMessageConverterTests {
|
||||
@Test
|
||||
public void readForm() throws Exception {
|
||||
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
|
||||
Charset iso88591 = Charset.forName("ISO-8859-1");
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(iso88591));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", iso88591));
|
||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
|
||||
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
|
||||
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
|
||||
|
||||
assertEquals("Invalid result", 3, result.size());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -97,9 +97,8 @@ public class ObjectToStringHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void defaultCharsetModified() throws IOException {
|
||||
Charset charset = Charset.forName("UTF-16");
|
||||
ConversionService cs = new DefaultConversionService();
|
||||
ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, charset);
|
||||
ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, StandardCharsets.UTF_16);
|
||||
converter.write((byte) 31, null, this.response);
|
||||
|
||||
assertEquals("UTF-16", this.servletResponse.getCharacterEncoding());
|
||||
@@ -123,28 +122,21 @@ public class ObjectToStringHttpMessageConverterTests {
|
||||
@Test
|
||||
public void read() throws IOException {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
request.setContentType(MediaType.TEXT_PLAIN_VALUE);
|
||||
|
||||
Short shortValue = Short.valueOf((short) 781);
|
||||
|
||||
request.setContent(shortValue.toString().getBytes(
|
||||
StringHttpMessageConverter.DEFAULT_CHARSET));
|
||||
|
||||
assertEquals(shortValue, this.converter.read(Short.class, new ServletServerHttpRequest(request)));
|
||||
|
||||
Float floatValue = Float.valueOf(123);
|
||||
|
||||
request.setCharacterEncoding("UTF-16");
|
||||
request.setContent(floatValue.toString().getBytes("UTF-16"));
|
||||
|
||||
assertEquals(floatValue, this.converter.read(Float.class, new ServletServerHttpRequest(request)));
|
||||
|
||||
Long longValue = Long.valueOf(55819182821331L);
|
||||
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
request.setContent(longValue.toString().getBytes("UTF-8"));
|
||||
|
||||
assertEquals(longValue, this.converter.read(Long.class, new ServletServerHttpRequest(request)));
|
||||
}
|
||||
|
||||
@@ -160,7 +152,7 @@ public class ObjectToStringHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void writeUtf16() throws IOException {
|
||||
MediaType contentType = new MediaType("text", "plain", Charset.forName("UTF-16"));
|
||||
MediaType contentType = new MediaType("text", "plain", StandardCharsets.UTF_16);
|
||||
this.converter.write(Integer.valueOf(958), contentType, this.response);
|
||||
|
||||
assertEquals("UTF-16", this.servletResponse.getCharacterEncoding());
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -73,14 +72,13 @@ public class StringHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void writeDefaultCharset() throws IOException {
|
||||
Charset iso88591 = Charset.forName("ISO-8859-1");
|
||||
String body = "H\u00e9llo W\u00f6rld";
|
||||
this.converter.write(body, null, this.outputMessage);
|
||||
|
||||
HttpHeaders headers = this.outputMessage.getHeaders();
|
||||
assertEquals(body, this.outputMessage.getBodyAsString(iso88591));
|
||||
assertEquals(new MediaType("text", "plain", iso88591), headers.getContentType());
|
||||
assertEquals(body.getBytes(iso88591).length, headers.getContentLength());
|
||||
assertEquals(body, this.outputMessage.getBodyAsString(StandardCharsets.ISO_8859_1));
|
||||
assertEquals(new MediaType("text", "plain", StandardCharsets.ISO_8859_1), headers.getContentType());
|
||||
assertEquals(body.getBytes(StandardCharsets.ISO_8859_1).length, headers.getContentLength());
|
||||
assertFalse(headers.getAcceptCharset().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -131,12 +131,11 @@ public class GsonHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void writeUTF16() throws IOException {
|
||||
Charset utf16 = Charset.forName("UTF-16BE");
|
||||
MediaType contentType = new MediaType("application", "json", utf16);
|
||||
MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE);
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
String body = "H\u00e9llo W\u00f6rld";
|
||||
this.converter.write(body, contentType, outputMessage);
|
||||
assertEquals("Invalid result", "\"" + body + "\"", outputMessage.getBodyAsString(utf16));
|
||||
assertEquals("Invalid result", "\"" + body + "\"", outputMessage.getBodyAsString(StandardCharsets.UTF_16BE));
|
||||
assertEquals("Invalid content-type", contentType, outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.http.converter.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -132,12 +131,11 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void writeUTF16() throws IOException {
|
||||
Charset utf16 = Charset.forName("UTF-16BE");
|
||||
MediaType contentType = new MediaType("application", "json", utf16);
|
||||
MediaType contentType = new MediaType("application", "json", StandardCharsets.UTF_16BE);
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
String body = "H\u00e9llo W\u00f6rld";
|
||||
converter.write(body, contentType, outputMessage);
|
||||
assertEquals("Invalid result", "\"" + body + "\"", outputMessage.getBodyAsString(utf16));
|
||||
assertEquals("Invalid result", "\"" + body + "\"", outputMessage.getBodyAsString(StandardCharsets.UTF_16BE));
|
||||
assertEquals("Invalid content-type", contentType, outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.web.client;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
@@ -50,14 +50,7 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -185,7 +178,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocation() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
Future<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
URI location = locationFuture.get();
|
||||
@@ -195,7 +188,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocationCallback() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
@@ -215,7 +208,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
@Test
|
||||
public void postForLocationCallbackWithLambdas() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -21,7 +21,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -40,12 +40,12 @@ public class HttpStatusCodeExceptionTests {
|
||||
/**
|
||||
* Corners bug SPR-9273, which reported the fact that following the changes made in
|
||||
* SPR-7591, {@link HttpStatusCodeException} and subtypes became no longer
|
||||
* serializable due to the addition of a non-serializable {@link Charset} field.
|
||||
* serializable due to the addition of a non-serializable {@code Charset} field.
|
||||
*/
|
||||
@Test
|
||||
public void testSerializability() throws IOException, ClassNotFoundException {
|
||||
HttpStatusCodeException ex1 = new HttpClientErrorException(
|
||||
HttpStatus.BAD_REQUEST, null, null, Charset.forName("US-ASCII"));
|
||||
HttpStatus.BAD_REQUEST, null, null, StandardCharsets.US_ASCII);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new ObjectOutputStream(out).writeObject(ex1);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.client;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
@@ -112,7 +111,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
@Test
|
||||
public void postForLocationEntity() throws URISyntaxException {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
|
||||
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
|
||||
URI location = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
|
||||
@@ -264,9 +263,12 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
assertTrue(content.contains("\"type\":\"bar\""));
|
||||
}
|
||||
|
||||
|
||||
public interface MyJacksonView1 {};
|
||||
|
||||
public interface MyJacksonView2 {};
|
||||
|
||||
|
||||
public static class MySampleBean {
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
@@ -311,6 +313,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
|
||||
public static class ParentClass {
|
||||
|
||||
@@ -332,6 +335,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeName("foo")
|
||||
public static class Foo extends ParentClass {
|
||||
|
||||
@@ -343,6 +347,7 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeName("bar")
|
||||
public static class Bar extends ParentClass {
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.springframework.web.multipart.support;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
@@ -33,9 +32,7 @@ import org.springframework.mock.web.test.MockMultipartHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -112,12 +109,12 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
@Override
|
||||
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(new MediaType("application", "octet-stream", Charset.forName("iso-8859-1")));
|
||||
headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
|
||||
return headers;
|
||||
}
|
||||
};
|
||||
byte[] bytes = {(byte) 0xC4};
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
|
||||
mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
@@ -136,7 +133,7 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
}
|
||||
};
|
||||
byte[] bytes = {(byte) 0xC4};
|
||||
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
|
||||
mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
|
||||
mockRequest.setCharacterEncoding("iso-8859-1");
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -30,7 +30,6 @@ import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -116,6 +115,13 @@ public class RequestPartIntegrationTests {
|
||||
baseUrl = "http://localhost:" + connector.getLocalPort();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopServer() throws Exception {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
|
||||
@@ -134,13 +140,6 @@ public class RequestPartIntegrationTests {
|
||||
restTemplate.setMessageConverters(Collections.singletonList(converter));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopServer() throws Exception {
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void commonsMultipartResolver() throws Exception {
|
||||
@@ -172,7 +171,7 @@ public class RequestPartIntegrationTests {
|
||||
RequestEntity<byte[]> requestEntity =
|
||||
RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
|
||||
.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
|
||||
.body(content.getBytes(Charset.forName("us-ascii")));
|
||||
.body(content.getBytes(StandardCharsets.US_ASCII));
|
||||
|
||||
ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
|
||||
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));
|
||||
@@ -189,7 +188,7 @@ public class RequestPartIntegrationTests {
|
||||
parts.add("empty-data", new HttpEntity<>(new byte[0])); // SPR-12860
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(new MediaType("application", "octet-stream", Charset.forName("ISO-8859-1")));
|
||||
headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
|
||||
parts.add("iso-8859-1-data", new HttpEntity<>(new byte[] {(byte) 0xC4}, headers)); // SPR-13096
|
||||
|
||||
URI location = restTemplate.postForLocation(url, parts);
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Principal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -1632,7 +1632,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
}
|
||||
}, TextRestController.class);
|
||||
|
||||
byte[] content = "alert('boo')".getBytes(Charset.forName("ISO-8859-1"));
|
||||
byte[] content = "alert('boo')".getBytes(StandardCharsets.ISO_8859_1);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/a1.html");
|
||||
request.setContent(content);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -1658,7 +1658,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
}
|
||||
}, TextRestController.class);
|
||||
|
||||
byte[] content = "alert('boo')".getBytes(Charset.forName("ISO-8859-1"));
|
||||
byte[] content = "alert('boo')".getBytes(StandardCharsets.ISO_8859_1);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/a2.html");
|
||||
request.setContent(content);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -1684,7 +1684,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
}
|
||||
}, TextRestController.class);
|
||||
|
||||
byte[] content = "alert('boo')".getBytes(Charset.forName("ISO-8859-1"));
|
||||
byte[] content = "alert('boo')".getBytes(StandardCharsets.ISO_8859_1);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/a3.html");
|
||||
request.setContent(content);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -1710,7 +1710,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
}
|
||||
}, TextRestController.class);
|
||||
|
||||
byte[] content = "body".getBytes(Charset.forName("ISO-8859-1"));
|
||||
byte[] content = "body".getBytes(StandardCharsets.ISO_8859_1);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/a4.css");
|
||||
request.setContent(content);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
Reference in New Issue
Block a user