Skip to content

Commit

Permalink
Merge pull request #2394 from anshlykov/gh-2357
Browse files Browse the repository at this point in the history
  • Loading branch information
fusesource-ci committed Aug 10, 2020
2 parents d147bec + c0b6700 commit e8c47dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -228,14 +229,8 @@ public void onOpen(final WebSocket webSocket, Response response) {
@Override
public void onMessage(WebSocket webSocket, String text) {
LOG.debug("{}: onMessage(String)", logPrefix);
try {
onMessage(webSocket, ByteBuffer.wrap(text.getBytes("UTF-8")));
} catch (IOException e) {
serverThrowables.add(e);
LOG.error("Error while converting string to byte buffer", e);
closeBothWays(webSocket, 1002, "Protocol error");
}
}
onMessage(webSocket, ByteBuffer.wrap(text.getBytes(StandardCharsets.UTF_8)));
}

@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class URLUtils {

Expand Down Expand Up @@ -152,6 +153,6 @@ public static boolean isValidURL(String url) {
}

public static String encodeToUTF(String url) throws UnsupportedEncodingException {
return URLEncoder.encode(url, "UTF-8");
return URLEncoder.encode(url, StandardCharsets.UTF_8.displayName());
}
}
Expand Up @@ -30,6 +30,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.Arrays;
Expand Down Expand Up @@ -333,7 +334,7 @@ public static String getProperty(Map<String, Object> properties, String property
*/
public static final String toUrlEncoded(String str) {
try {
return URLEncoder.encode(str, "UTF-8");
return URLEncoder.encode(str, StandardCharsets.UTF_8.displayName());
} catch (UnsupportedEncodingException exception) {
// Ignore
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -508,7 +509,7 @@ public void testPortForwardWithChannel() throws InterruptedException, IOExceptio
}
}

String got = new String(out.toByteArray(), "UTF-8");
String got = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertEquals("Hello World!", got);
}

Expand Down Expand Up @@ -581,11 +582,11 @@ public void testListFromServer() {

private static String portForwardEncode(boolean dataChannel, String str) {
try {
byte[] data = str.getBytes("UTF-8");
byte[] data = str.getBytes(StandardCharsets.UTF_8);
byte[] msg = new byte[data.length + 1];
System.arraycopy(data, 0, msg, 1, data.length);
msg[0] = dataChannel ? (byte) 0 : (byte) 1;
return new String(msg, "UTF-8");
return new String(msg, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IllegalStateException(e);
}
Expand Down

0 comments on commit e8c47dc

Please sign in to comment.