Revise encoding steps towards use of JDK Charset and StandardCharsets
Issue: SPR-14492
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
package org.springframework.web.socket.messaging;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -56,9 +56,6 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class WebSocketStompClientTests {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
|
||||
private TestWebSocketStompClient stompClient;
|
||||
|
||||
@Mock
|
||||
@@ -137,7 +134,7 @@ public class WebSocketStompClientTests {
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), UTF_8));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,14 +159,14 @@ public class WebSocketStompClientTests {
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), UTF_8));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void handleWebSocketMessageBinary() throws Exception {
|
||||
String text = "SEND\na:alpha\n\nMessage payload\0";
|
||||
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(UTF_8)));
|
||||
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
|
||||
verify(this.stompSession).handleMessage(captor.capture());
|
||||
@@ -180,7 +177,7 @@ public class WebSocketStompClientTests {
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), UTF_8));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,7 +190,7 @@ public class WebSocketStompClientTests {
|
||||
public void sendWebSocketMessage() throws Exception {
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
accessor.setDestination("/topic/foo");
|
||||
byte[] payload = "payload".getBytes(UTF_8);
|
||||
byte[] payload = "payload".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
getTcpConnection().send(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
|
||||
|
||||
@@ -209,7 +206,7 @@ public class WebSocketStompClientTests {
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
accessor.setDestination("/b");
|
||||
accessor.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
|
||||
byte[] payload = "payload".getBytes(UTF_8);
|
||||
byte[] payload = "payload".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
getTcpConnection().send(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));
|
||||
|
||||
@@ -218,7 +215,7 @@ public class WebSocketStompClientTests {
|
||||
BinaryMessage binaryMessage = binaryMessageCaptor.getValue();
|
||||
assertNotNull(binaryMessage);
|
||||
assertEquals("SEND\ndestination:/b\ncontent-type:application/octet-stream\ncontent-length:7\n\npayload\0",
|
||||
new String(binaryMessage.getPayload().array(), UTF_8));
|
||||
new String(binaryMessage.getPayload().array(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -109,7 +109,7 @@ public class RestTemplateXhrTransportTests {
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
accessor.setDestination("/destination");
|
||||
MessageHeaders headers = accessor.getMessageHeaders();
|
||||
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(Charset.forName("UTF-8")), headers);
|
||||
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers);
|
||||
byte[] bytes = new StompEncoder().encode(message);
|
||||
TextMessage textMessage = new TextMessage(bytes);
|
||||
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());
|
||||
@@ -197,7 +197,7 @@ public class RestTemplateXhrTransportTests {
|
||||
}
|
||||
|
||||
private InputStream getInputStream(String content) {
|
||||
byte[] bytes = content.getBytes(Charset.forName("UTF-8"));
|
||||
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user