Skip to content

Commit d260339

Browse files
hduelmegregturn
authored andcommitted
Use StandardCharsets.UTF_8 instead of a string value.
Resolves #1335.
1 parent 151ff28 commit d260339

File tree

12 files changed

+36
-25
lines changed

12 files changed

+36
-25
lines changed

spring-ws-core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121
import java.net.URI;
22+
import java.nio.charset.StandardCharsets;
2223
import java.util.List;
2324

2425
import javax.xml.transform.*;
@@ -619,7 +620,7 @@ private void sendRequest(WebServiceConnection connection, WebServiceMessage requ
619620
if (sentMessageTracingLogger.isTraceEnabled()) {
620621
ByteArrayOutputStream os = new ByteArrayOutputStream();
621622
request.writeTo(os);
622-
sentMessageTracingLogger.trace("Sent request [" + os.toString("UTF-8") + "]");
623+
sentMessageTracingLogger.trace("Sent request [" + os.toString(StandardCharsets.UTF_8) + "]");
623624
} else if (sentMessageTracingLogger.isDebugEnabled()) {
624625
sentMessageTracingLogger.debug("Sent request [" + request + "]");
625626
}
@@ -672,8 +673,8 @@ private void logResponse(MessageContext messageContext) throws IOException {
672673
messageContext.getRequest().writeTo(requestStream);
673674
ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
674675
messageContext.getResponse().writeTo(responseStream);
675-
receivedMessageTracingLogger.trace("Received response [" + responseStream.toString("UTF-8") + "] for request ["
676-
+ requestStream.toString("UTF-8") + "]");
676+
receivedMessageTracingLogger.trace("Received response [" + responseStream.toString(StandardCharsets.UTF_8) + "] for request ["
677+
+ requestStream.toString(StandardCharsets.UTF_8) + "]");
677678
} else if (receivedMessageTracingLogger.isDebugEnabled()) {
678679
receivedMessageTracingLogger.debug("Received response [" + messageContext.getResponse() + "] for request ["
679680
+ messageContext.getRequest() + "]");

spring-ws-core/src/main/java/org/springframework/ws/server/MessageDispatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.ArrayList;
2223
import java.util.List;
2324
import java.util.Map;
@@ -189,7 +190,7 @@ public void receive(MessageContext messageContext) throws Exception {
189190
private String getMessageContent(WebServiceMessage message) throws IOException {
190191
ByteArrayOutputStream bos = new ByteArrayOutputStream();
191192
message.writeTo(bos);
192-
return bos.toString("UTF-8");
193+
return bos.toString(StandardCharsets.UTF_8);
193194
}
194195

195196
/**

spring-ws-core/src/test/java/org/springframework/ws/AbstractWebServiceMessageTestCase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.InputStreamReader;
2525
import java.io.Reader;
2626
import java.io.StringWriter;
27+
import java.nio.charset.StandardCharsets;
2728

2829
import javax.xml.parsers.DocumentBuilder;
2930
import javax.xml.parsers.DocumentBuilderFactory;
@@ -71,7 +72,7 @@ public abstract class AbstractWebServiceMessageTestCase {
7172
private String getExpectedString() throws IOException {
7273

7374
StringWriter expectedWriter = new StringWriter();
74-
FileCopyUtils.copy(new InputStreamReader(payload.getInputStream(), "UTF-8"), expectedWriter);
75+
FileCopyUtils.copy(new InputStreamReader(payload.getInputStream(), StandardCharsets.UTF_8), expectedWriter);
7576
return expectedWriter.toString();
7677
}
7778

@@ -124,7 +125,7 @@ public void testEventReaderPayload() throws Exception {
124125
@Test
125126
public void testReaderPayload() throws Exception {
126127

127-
Reader reader = new InputStreamReader(payload.getInputStream(), "UTF-8");
128+
Reader reader = new InputStreamReader(payload.getInputStream(), StandardCharsets.UTF_8);
128129
StreamSource streamSource = new StreamSource(reader, payload.getURL().toString());
129130
transformer.transform(streamSource, webServiceMessage.getPayloadResult());
130131
StringWriter resultWriter = new StringWriter();
@@ -158,7 +159,7 @@ public void testStreamPayload() throws Exception {
158159
ByteArrayOutputStream expectedStream = new ByteArrayOutputStream();
159160
FileCopyUtils.copy(payload.getInputStream(), expectedStream);
160161

161-
assertThat(resultStream.toString("UTF-8")).and(expectedStream.toString("UTF-8")).ignoreWhitespace().areIdentical();
162+
assertThat(resultStream.toString(StandardCharsets.UTF_8)).and(expectedStream.toString(StandardCharsets.UTF_8)).ignoreWhitespace().areIdentical();
162163

163164
validateMessage();
164165
}

spring-ws-core/src/test/java/org/springframework/ws/pox/dom/DomPoxMessageTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.xmlunit.assertj.XmlAssert.*;
2020

2121
import java.io.ByteArrayOutputStream;
22+
import java.nio.charset.StandardCharsets;
2223

2324
import javax.xml.parsers.DocumentBuilder;
2425
import javax.xml.parsers.DocumentBuilderFactory;
@@ -83,6 +84,6 @@ public void testWriteTo() throws Exception {
8384
ByteArrayOutputStream os = new ByteArrayOutputStream();
8485
message.writeTo(os);
8586

86-
assertThat(os.toString("UTF-8")).and(content).ignoreWhitespace().areIdentical();
87+
assertThat(os.toString(StandardCharsets.UTF_8)).and(content).ignoreWhitespace().areIdentical();
8788
}
8889
}

spring-ws-core/src/test/java/org/springframework/ws/server/endpoint/AbstractEndpointTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.InputStream;
2121
import java.io.Reader;
2222
import java.io.StringReader;
23+
import java.nio.charset.StandardCharsets;
2324

2425
import javax.xml.parsers.DocumentBuilder;
2526
import javax.xml.parsers.DocumentBuilderFactory;
@@ -90,7 +91,7 @@ public void testStaxSourceStreamReader() throws Exception {
9091
@Test
9192
public void testStreamSourceInputStream() throws Exception {
9293

93-
InputStream is = new ByteArrayInputStream(REQUEST.getBytes("UTF-8"));
94+
InputStream is = new ByteArrayInputStream(REQUEST.getBytes(StandardCharsets.UTF_8));
9495
testSource(new StreamSource(is));
9596
}
9697

spring-ws-core/src/test/java/org/springframework/ws/soap/saaj/SaajSoap11MessageFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.ByteArrayOutputStream;
2626
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
2728
import java.util.Collections;
2829
import java.util.Map;
2930

@@ -49,7 +50,7 @@ public void properties() throws IOException {
4950
SoapMessage soapMessage = (SoapMessage) messageFactory.createWebServiceMessage();
5051
ByteArrayOutputStream os = new ByteArrayOutputStream();
5152
soapMessage.writeTo(os);
52-
String result = os.toString("UTF-8");
53+
String result = os.toString(StandardCharsets.UTF_8);
5354

5455
assertThat(result).startsWith("<?xml version=\"1.0\"");
5556
}

spring-ws-core/src/test/java/org/springframework/ws/soap/soap11/AbstractSoap11MessageTestCase.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.ByteArrayInputStream;
2222
import java.io.ByteArrayOutputStream;
23+
import java.nio.charset.StandardCharsets;
2324

2425
import javax.xml.parsers.DocumentBuilder;
2526
import javax.xml.parsers.DocumentBuilderFactory;
@@ -64,7 +65,7 @@ public void testWriteToTransportOutputStream() throws Exception {
6465
String soapAction = "http://springframework.org/spring-ws/Action";
6566
soapMessage.setSoapAction(soapAction);
6667
soapMessage.writeTo(tos);
67-
String result = bos.toString("UTF-8");
68+
String result = bos.toString(StandardCharsets.UTF_8);
6869

6970
XmlAssert.assertThat(result)
7071
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://schemas.xmlsoap.org/soap/envelope/'>"
@@ -88,7 +89,7 @@ public void testWriteToTransportOutputStream() throws Exception {
8889
@Override
8990
public void testWriteToTransportResponseAttachment() throws Exception {
9091

91-
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
92+
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes(StandardCharsets.UTF_8));
9293
soapMessage.addAttachment("contentId", inputStreamSource, "text/plain");
9394
ByteArrayOutputStream bos = new ByteArrayOutputStream();
9495
MockTransportOutputStream tos = new MockTransportOutputStream(bos);
@@ -140,7 +141,7 @@ public void testSetLiveDocument() throws Exception {
140141
ByteArrayOutputStream bos = new ByteArrayOutputStream();
141142
soapMessage.writeTo(bos);
142143

143-
String result = bos.toString("UTF-8");
144+
String result = bos.toString(StandardCharsets.UTF_8);
144145

145146
XmlAssert.assertThat(result)
146147
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://schemas.xmlsoap.org/soap/envelope/'>"
@@ -169,7 +170,7 @@ public void testSetOtherDocument() throws Exception {
169170
bos = new ByteArrayOutputStream();
170171
soapMessage.writeTo(bos);
171172

172-
String result = bos.toString("UTF-8");
173+
String result = bos.toString(StandardCharsets.UTF_8);
173174

174175
XmlAssert.assertThat(result)
175176
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://schemas.xmlsoap.org/soap/envelope/'>"

spring-ws-core/src/test/java/org/springframework/ws/soap/soap12/AbstractSoap12MessageTestCase.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.ByteArrayInputStream;
2222
import java.io.ByteArrayOutputStream;
23+
import java.nio.charset.StandardCharsets;
2324

2425
import javax.xml.parsers.DocumentBuilder;
2526
import javax.xml.parsers.DocumentBuilderFactory;
@@ -67,7 +68,7 @@ public void testWriteToTransportOutputStream() throws Exception {
6768
String soapAction = "http://springframework.org/spring-ws/Action";
6869
soapMessage.setSoapAction(soapAction);
6970
soapMessage.writeTo(tos);
70-
String result = bos.toString("UTF-8");
71+
String result = bos.toString(StandardCharsets.UTF_8);
7172

7273
XmlAssert.assertThat(result)
7374
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://www.w3.org/2003/05/soap-envelope'>" + getHeader()
@@ -89,7 +90,7 @@ public void testWriteToTransportOutputStream() throws Exception {
8990
@Override
9091
public void testWriteToTransportResponseAttachment() throws Exception {
9192

92-
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
93+
InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes(StandardCharsets.UTF_8));
9394
soapMessage.addAttachment("contentId", inputStreamSource, "text/plain");
9495
ByteArrayOutputStream bos = new ByteArrayOutputStream();
9596
MockTransportOutputStream tos = new MockTransportOutputStream(bos);
@@ -141,7 +142,7 @@ public void testSetLiveDocument() throws Exception {
141142
ByteArrayOutputStream bos = new ByteArrayOutputStream();
142143
soapMessage.writeTo(bos);
143144

144-
String result = bos.toString("UTF-8");
145+
String result = bos.toString(StandardCharsets.UTF_8);
145146

146147
XmlAssert.assertThat(result)
147148
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://www.w3.org/2003/05/soap-envelope'>" + getHeader()
@@ -170,7 +171,7 @@ public void testSetOtherDocument() throws Exception {
170171
bos = new ByteArrayOutputStream();
171172
soapMessage.writeTo(bos);
172173

173-
String result = bos.toString("UTF-8");
174+
String result = bos.toString(StandardCharsets.UTF_8);
174175

175176
XmlAssert.assertThat(result)
176177
.and("<" + getNS() + ":Envelope xmlns:" + getNS() + "='http://www.w3.org/2003/05/soap-envelope'>" + getHeader()

spring-ws-core/src/test/java/org/springframework/ws/transport/http/AbstractHttpWebServiceMessageSenderIntegrationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse
289289
assertThat(httpServletRequest.getHeader(REQUEST_HEADER_NAME)).isEqualTo(REQUEST_HEADER_VALUE);
290290

291291
String receivedRequest = new String(FileCopyUtils.copyToByteArray(httpServletRequest.getInputStream()),
292-
"UTF-8");
292+
StandardCharsets.UTF_8);
293293

294294
XmlAssert.assertThat(receivedRequest).and(SOAP_REQUEST).ignoreWhitespace().areIdentical();
295295

spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpServletConnectionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import jakarta.xml.soap.SOAPMessage;
2525

2626
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
2728

2829
import javax.xml.transform.Transformer;
2930
import javax.xml.transform.TransformerFactory;
@@ -75,7 +76,7 @@ public void setUp() throws Exception {
7576
@Test
7677
public void receive() throws Exception {
7778

78-
byte[] bytes = SOAP_CONTENT.getBytes("UTF-8");
79+
byte[] bytes = SOAP_CONTENT.getBytes(StandardCharsets.UTF_8);
7980
httpServletRequest.addHeader("Content-Type", "text/xml");
8081
httpServletRequest.addHeader("Content-Length", Integer.toString(bytes.length));
8182
httpServletRequest.addHeader(HEADER_NAME, HEADER_VALUE);

0 commit comments

Comments
 (0)