Skip to content

Commit 45dbfe0

Browse files
author
Alexander
committed
add possibility to override ssl socket factory
for single client
1 parent 044c170 commit 45dbfe0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/tech/gusavila92/websocketclient/WebSocketClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public abstract class WebSocketClient {
134134
*/
135135
private volatile Thread reconnectionThread;
136136

137+
138+
private SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
139+
137140
/**
138141
* Initialize all the variables
139142
*
@@ -152,6 +155,11 @@ public WebSocketClient(URI uri) {
152155
webSocketConnection = new WebSocketConnection();
153156
}
154157

158+
159+
public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
160+
socketFactory = sslSocketFactory;
161+
}
162+
155163
/**
156164
* Called when the WebSocket handshake has been accepted and the WebSocket
157165
* is ready to send and receive data
@@ -648,7 +656,6 @@ private boolean createAndConnectTCPSocket() throws IOException {
648656
socket.connect(new InetSocketAddress(uri.getHost(), 80), connectTimeout);
649657
}
650658
} else if (scheme.equals("wss")) {
651-
SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
652659
socket = socketFactory.createSocket();
653660
socket.setSoTimeout(readTimeout);
654661

0 commit comments

Comments
 (0)