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