bump engine.io-client
This commit is contained in:
@@ -2,6 +2,9 @@ package io.socket.client;
|
||||
|
||||
|
||||
import io.socket.parser.Parser;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.WebSocket;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -23,12 +26,12 @@ public class IO {
|
||||
*/
|
||||
public static int protocol = Parser.protocol;
|
||||
|
||||
public static void setDefaultSSLContext(SSLContext sslContext) {
|
||||
Manager.defaultSSLContext = sslContext;
|
||||
public static void setDefaultOkHttpWebSocketFactory(WebSocket.Factory factory) {
|
||||
Manager.defaultWebSocketFactory = factory;
|
||||
}
|
||||
|
||||
public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
Manager.defaultHostnameVerifier = hostnameVerifier;
|
||||
public static void setDefaultOkHttpCallFactory(Call.Factory factory) {
|
||||
Manager.defaultCallFactory = factory;
|
||||
}
|
||||
|
||||
private IO() {}
|
||||
|
||||
@@ -5,6 +5,8 @@ import io.socket.emitter.Emitter;
|
||||
import io.socket.parser.Packet;
|
||||
import io.socket.parser.Parser;
|
||||
import io.socket.thread.EventThread;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.WebSocket;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -73,8 +75,8 @@ public class Manager extends Emitter {
|
||||
*/
|
||||
public static final String EVENT_TRANSPORT = Engine.EVENT_TRANSPORT;
|
||||
|
||||
/*package*/ static SSLContext defaultSSLContext;
|
||||
/*package*/ static HostnameVerifier defaultHostnameVerifier;
|
||||
/*package*/ static WebSocket.Factory defaultWebSocketFactory;
|
||||
/*package*/ static Call.Factory defaultCallFactory;
|
||||
|
||||
/*package*/ ReadyState readyState;
|
||||
|
||||
@@ -123,11 +125,11 @@ public class Manager extends Emitter {
|
||||
if (opts.path == null) {
|
||||
opts.path = "/socket.io";
|
||||
}
|
||||
if (opts.sslContext == null) {
|
||||
opts.sslContext = defaultSSLContext;
|
||||
if (opts.webSocketFactory == null) {
|
||||
opts.webSocketFactory = defaultWebSocketFactory;
|
||||
}
|
||||
if (opts.hostnameVerifier == null) {
|
||||
opts.hostnameVerifier = defaultHostnameVerifier;
|
||||
if (opts.callFactory == null) {
|
||||
opts.callFactory = defaultCallFactory;
|
||||
}
|
||||
this.opts = opts;
|
||||
this.nsps = new ConcurrentHashMap<String, Socket>();
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ExecutionTest extends Connection {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ExecutionTest.class.getName());
|
||||
|
||||
final static int TIMEOUT = 60 * 1000;
|
||||
final static int TIMEOUT = 100 * 1000;
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void execConnection() throws InterruptedException, IOException {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.socket.client;
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -9,7 +10,9 @@ import org.junit.runners.JUnit4;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -21,15 +24,20 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
@RunWith(JUnit4.class)
|
||||
public class SSLConnectionTest extends Connection {
|
||||
|
||||
// for test on localhost
|
||||
static HostnameVerifier hostnameVerifier = new javax.net.ssl.HostnameVerifier(){
|
||||
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
|
||||
return hostname.equals("localhost");
|
||||
}
|
||||
};
|
||||
private static OkHttpClient sOkHttpClient;
|
||||
|
||||
private Socket socket;
|
||||
|
||||
static {
|
||||
try {
|
||||
prepareOkHttpClient();
|
||||
} catch(GeneralSecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
String uri() {
|
||||
return "https://localhost:" + PORT;
|
||||
@@ -47,7 +55,7 @@ public class SSLConnectionTest extends Connection {
|
||||
return new String[] {"DEBUG=socket.io:*", "PORT=" + PORT, "SSL=1"};
|
||||
}
|
||||
|
||||
SSLContext createSSLContext() throws GeneralSecurityException, IOException {
|
||||
private static void prepareOkHttpClient() throws GeneralSecurityException, IOException {
|
||||
KeyStore ks = KeyStore.getInstance("JKS");
|
||||
File file = new File("src/test/resources/keystore.jks");
|
||||
ks.load(new FileInputStream(file), "password".toCharArray());
|
||||
@@ -60,21 +68,30 @@ public class SSLConnectionTest extends Connection {
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLSv1");
|
||||
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
return sslContext;
|
||||
|
||||
sOkHttpClient = new OkHttpClient.Builder()
|
||||
.hostnameVerifier(new HostnameVerifier(){
|
||||
public boolean verify(String hostname, SSLSession sslSession) {
|
||||
return hostname.equals("localhost");
|
||||
}
|
||||
})
|
||||
.sslSocketFactory(sslContext.getSocketFactory(),
|
||||
(X509TrustManager) tmf.getTrustManagers()[0])
|
||||
.build();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IO.setDefaultSSLContext(null);
|
||||
IO.setDefaultHostnameVerifier(null);
|
||||
IO.setDefaultOkHttpCallFactory(null);
|
||||
IO.setDefaultOkHttpWebSocketFactory(null);
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void connect() throws Exception {
|
||||
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
|
||||
IO.Options opts = createOptions();
|
||||
opts.sslContext = createSSLContext();
|
||||
opts.hostnameVerifier = hostnameVerifier;
|
||||
opts.callFactory = sOkHttpClient;
|
||||
opts.webSocketFactory = sOkHttpClient;
|
||||
socket = client(opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
@@ -96,8 +113,8 @@ public class SSLConnectionTest extends Connection {
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void defaultSSLContext() throws Exception {
|
||||
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
|
||||
IO.setDefaultSSLContext(createSSLContext());
|
||||
IO.setDefaultHostnameVerifier(hostnameVerifier);
|
||||
IO.setDefaultOkHttpWebSocketFactory(sOkHttpClient);
|
||||
IO.setDefaultOkHttpCallFactory(sOkHttpClient);
|
||||
socket = client();
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user