Skip to content

Commit d796504

Browse files
committed
Bug: 484264 - Null pointer in Paho Java client WebSocket classes
Added better error handling for invalid responses from Server. In this case when an open port is used that does not support WebSockets. Also Changed default ports used when ws(1883 -> 80) or wss(8883 -> 443) uris are used to better match WebSockets standards. Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent f21837e commit d796504

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ else if ((factory instanceof SSLSocketFactory) == false) {
411411
case MqttConnectOptions.URI_TYPE_WS:
412412
shortAddress = address.substring(5);
413413
host = getHostName(shortAddress);
414-
port = getPort(shortAddress, 1883);
414+
port = getPort(shortAddress, 80);
415415
if (factory == null) {
416416
factory = SocketFactory.getDefault();
417417
}
@@ -424,7 +424,7 @@ else if (factory instanceof SSLSocketFactory) {
424424
case MqttConnectOptions.URI_TYPE_WSS:
425425
shortAddress = address.substring(6);
426426
host = getHostName(shortAddress);
427-
port = getPort(shortAddress, 8883);
427+
port = getPort(shortAddress, 443);
428428
SSLSocketFactoryFactory wSSFactoryFactory = null;
429429
if (factory == null) {
430430
wSSFactoryFactory = new SSLSocketFactoryFactory();

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket/WebSocketHandshake.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ private void receiveHandshakeResponse(String key) throws IOException {
9494
BufferedReader in = new BufferedReader(new InputStreamReader(input));
9595
ArrayList responseLines = new ArrayList();
9696
String line = in.readLine();
97+
if(line == null){
98+
throw new IOException("WebSocket Response header: Invalid response from Server, It may not support WebSockets.");
99+
}
97100
while(!line.equals(EMPTY) ) {
98101
responseLines.add(line);
99102
line = in.readLine();

0 commit comments

Comments
 (0)