2727import java .util .logging .Logger ;
2828
2929import javax .net .ssl .HttpsURLConnection ;
30- import javax .net .ssl .SSLSocketFactory ;
30+ import javax .net .ssl .SSLContext ;
3131
3232import com .google .gson .JsonArray ;
3333import com .google .gson .JsonElement ;
@@ -70,8 +70,7 @@ class IOConnection implements IOCallback {
7070 public static final String SOCKET_IO_1 = "/socket.io/1/" ;
7171
7272 /** The SSL socket factory for HTTPS connections */
73- private static SSLSocketFactory sslSocketFactory = (SSLSocketFactory ) SSLSocketFactory
74- .getDefault ();
73+ private static SSLContext sslContext = null ;
7574
7675 /** All available connections. */
7776 private static HashMap <String , List <IOConnection >> connections = new HashMap <String , List <IOConnection >>();
@@ -209,10 +208,19 @@ public void run() {
209208 /**
210209 * Set the socket factory used for SSL connections.
211210 *
212- * @param socketFactory
211+ * @param sslContext
213212 */
214- public static void setDefaultSSLSocketFactory (SSLSocketFactory socketFactory ) {
215- sslSocketFactory = socketFactory ;
213+ public static void setSslContext (SSLContext sslContext ) {
214+ IOConnection .sslContext = sslContext ;
215+ }
216+
217+ /**
218+ * Get the socket factory used for SSL connections.
219+ *
220+ * @return socketFactory
221+ */
222+ public static SSLContext getSslContext () {
223+ return sslContext ;
216224 }
217225
218226 /**
@@ -294,7 +302,7 @@ private void handshake() {
294302 connection = url .openConnection ();
295303 if (connection instanceof HttpsURLConnection ) {
296304 ((HttpsURLConnection ) connection )
297- .setSSLSocketFactory (sslSocketFactory );
305+ .setSSLSocketFactory (sslContext . getSocketFactory () );
298306 }
299307 connection .setConnectTimeout (connectTimeout );
300308 connection .setReadTimeout (connectTimeout );
@@ -355,17 +363,20 @@ else if (_id.endsWith("+") == false)
355363 final String id = _id ;
356364 final String endPoint = message .getEndpoint ();
357365 return new IOAcknowledge () {
366+ @ Override
358367 public void ack (JsonElement ... args ) {
359368 JsonArray array = new JsonArray ();
360369 for (JsonElement o : args ) {
361370 try {
362371 array .add (o );
363- // array.put(o == null ? JSONObject.NULL : o);
364372 } catch (Exception e ) {
365- error (new SocketIOException ( "You can only put values in IOAcknowledge.ack() which can be handled by JSONArray.put()" , e ));
373+ error (new SocketIOException (
374+ "You can only put values in IOAcknowledge.ack() which can be handled by JSONArray.put()" ,
375+ e ));
366376 }
367377 }
368- IOMessage ackMsg = new IOMessage (IOMessage .TYPE_ACK , endPoint , id + array .toString ());
378+ IOMessage ackMsg = new IOMessage (IOMessage .TYPE_ACK , endPoint ,
379+ id + array .toString ());
369380 sendPlain (ackMsg .toString ());
370381 }
371382 };
@@ -686,7 +697,8 @@ public void transportMessage(String text) {
686697 argsArray = new JsonElement [0 ];
687698 String eventName = event .get ("name" ).getAsString ();
688699 try {
689- findCallback (message ).on (eventName , remoteAcknowledge (message ), argsArray );
700+ findCallback (message ).on (eventName ,
701+ remoteAcknowledge (message ), argsArray );
690702 } catch (Exception e ) {
691703 error (new SocketIOException (
692704 "Exception was thrown in on(String, JSONObject[]).\n "
@@ -724,7 +736,8 @@ public void transportMessage(String text) {
724736 break ;
725737 case IOMessage .TYPE_ERROR :
726738 try {
727- findCallback (message ).onError ( new SocketIOException (message .getData ()));
739+ findCallback (message ).onError (
740+ new SocketIOException (message .getData ()));
728741 } catch (SocketIOException e ) {
729742 error (e );
730743 }
@@ -824,6 +837,7 @@ public void emit(SocketIO socket, String event, IOAcknowledge ack, Object... arg
824837 }
825838 }
826839
840+
827841 JsonObject jobj = new JsonObject ();
828842 jobj .add ("name" , new JsonPrimitive (event ));
829843 jobj .add ("args" , jarray );
@@ -833,7 +847,7 @@ public void emit(SocketIO socket, String event, IOAcknowledge ack, Object... arg
833847 sendPlain (message .toString ());
834848
835849 } catch (JsonParseException e ) {
836- error (new SocketIOException ("Error while emitting an event. Make sure you only try to send arguments, which can be serialized into JSON." ) );
850+ error (new SocketIOException ("Error while emitting an event. Make sure you only try to send arguments, which can be serialized into JSON." ));
837851 }
838852
839853 }
0 commit comments