|
26 | 26 | import java.util.concurrent.ConcurrentLinkedQueue;
|
27 | 27 | import java.util.logging.Logger;
|
28 | 28 |
|
| 29 | +import javax.net.ssl.HttpsURLConnection; |
| 30 | +import javax.net.ssl.SSLSocketFactory; |
| 31 | + |
29 | 32 | import org.json.JSONArray;
|
30 | 33 | import org.json.JSONException;
|
31 | 34 | import org.json.JSONObject;
|
@@ -63,6 +66,9 @@ class IOConnection implements IOCallback {
|
63 | 66 | /** Socket.io path. */
|
64 | 67 | public static final String SOCKET_IO_1 = "/socket.io/1/";
|
65 | 68 |
|
| 69 | + /** The SSL socket factory for HTTPS connections */ |
| 70 | + private static SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault(); |
| 71 | + |
66 | 72 | /** All available connections. */
|
67 | 73 | private static HashMap<String, List<IOConnection>> connections = new HashMap<String, List<IOConnection>>();
|
68 | 74 |
|
@@ -198,6 +204,14 @@ public void run() {
|
198 | 204 |
|
199 | 205 | };
|
200 | 206 |
|
| 207 | + /** |
| 208 | + * Set the socket factory used for SSL connections. |
| 209 | + * @param socketFactory |
| 210 | + */ |
| 211 | + public static void setDefaultSSLSocketFactory(SSLSocketFactory socketFactory) { |
| 212 | + sslSocketFactory = socketFactory; |
| 213 | + } |
| 214 | + |
201 | 215 | /**
|
202 | 216 | * Creates a new connection or returns the corresponding one.
|
203 | 217 | *
|
@@ -273,6 +287,9 @@ private void handshake() {
|
273 | 287 | setState(STATE_HANDSHAKE);
|
274 | 288 | url = new URL(IOConnection.this.url.toString() + SOCKET_IO_1);
|
275 | 289 | connection = url.openConnection();
|
| 290 | + if(connection instanceof HttpsURLConnection) { |
| 291 | + ((HttpsURLConnection)connection).setSSLSocketFactory(sslSocketFactory); |
| 292 | + } |
276 | 293 | connection.setConnectTimeout(connectTimeout);
|
277 | 294 | connection.setReadTimeout(connectTimeout);
|
278 | 295 |
|
|
0 commit comments