Skip to content

Commit 14c468b

Browse files
committed
Fix SSL
1 parent 81916e9 commit 14c468b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/src/main/java/ua/naiksoftware/stomp/WebSocketsConnectionProvider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ua.naiksoftware.stomp;
22

3+
import android.os.Looper;
34
import android.util.Log;
45

56
import org.java_websocket.WebSocket;
@@ -17,6 +18,9 @@
1718
import java.util.Map;
1819
import java.util.TreeMap;
1920

21+
import javax.net.ssl.SSLContext;
22+
import javax.net.ssl.SSLSocketFactory;
23+
2024
import rx.Observable;
2125
import rx.Subscriber;
2226

@@ -112,6 +116,17 @@ public void onError(Exception ex) {
112116
}
113117
};
114118

119+
if(mUri.startsWith("wss")) {
120+
try {
121+
SSLContext sc = SSLContext.getInstance("TLS");
122+
sc.init(null, null, null);
123+
SSLSocketFactory factory = sc.getSocketFactory();
124+
mWebSocketClient.setSocket(factory.createSocket());
125+
} catch (Exception e) {
126+
e.printStackTrace();
127+
}
128+
}
129+
115130
mWebSocketClient.connect();
116131
haveConnection = true;
117132
}

0 commit comments

Comments
 (0)