bump engine.io-client, add setDefaultHostnameVerifier method

This commit is contained in:
Naoyuki Kanezawa
2015-05-03 02:04:46 +09:00
parent 2bf706a211
commit e317dd0cf3
4 changed files with 21 additions and 10 deletions

View File

@@ -58,7 +58,7 @@
<dependency> <dependency>
<groupId>com.github.nkzawa</groupId> <groupId>com.github.nkzawa</groupId>
<artifactId>engine.io-client</artifactId> <artifactId>engine.io-client</artifactId>
<version>0.4.1</version> <version>0.5.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>

View File

@@ -3,6 +3,7 @@ package com.github.nkzawa.socketio.client;
import com.github.nkzawa.socketio.parser.Parser; import com.github.nkzawa.socketio.parser.Parser;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
@@ -27,6 +28,10 @@ public class IO {
Manager.defaultSSLContext = sslContext; Manager.defaultSSLContext = sslContext;
} }
public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier) {
Manager.defaultHostnameVerifier = hostnameVerifier;
}
private IO() {} private IO() {}
public static Socket socket(String uri) throws URISyntaxException { public static Socket socket(String uri) throws URISyntaxException {

View File

@@ -6,10 +6,11 @@ import com.github.nkzawa.socketio.parser.Packet;
import com.github.nkzawa.socketio.parser.Parser; import com.github.nkzawa.socketio.parser.Parser;
import com.github.nkzawa.thread.EventThread; import com.github.nkzawa.thread.EventThread;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.net.URI; import java.net.URI;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -70,6 +71,7 @@ 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 SSLContext defaultSSLContext;
/*package*/ static HostnameVerifier defaultHostnameVerifier;
/*package*/ ReadyState readyState = null; /*package*/ ReadyState readyState = null;
@@ -120,6 +122,9 @@ public class Manager extends Emitter {
if (opts.sslContext == null) { if (opts.sslContext == null) {
opts.sslContext = defaultSSLContext; opts.sslContext = defaultSSLContext;
} }
if (opts.hostnameVerifier == null) {
opts.hostnameVerifier = defaultHostnameVerifier;
}
this.opts = opts; this.opts = opts;
this.nsps = new ConcurrentHashMap<String, Socket>(); this.nsps = new ConcurrentHashMap<String, Socket>();
this.subs = new LinkedList<On.Handle>(); this.subs = new LinkedList<On.Handle>();

View File

@@ -6,6 +6,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
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.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
@@ -20,15 +21,12 @@ import java.util.concurrent.LinkedBlockingQueue;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class SSLConnectionTest extends Connection { public class SSLConnectionTest extends Connection {
static {
// for test on localhost // for test on localhost
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier( static HostnameVerifier hostnameVerifier = new javax.net.ssl.HostnameVerifier(){
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
return hostname.equals("localhost"); return hostname.equals("localhost");
} }
}); };
}
private Socket socket; private Socket socket;
@@ -68,6 +66,7 @@ public class SSLConnectionTest extends Connection {
@After @After
public void tearDown() { public void tearDown() {
IO.setDefaultSSLContext(null); IO.setDefaultSSLContext(null);
IO.setDefaultHostnameVerifier(null);
} }
@Test(timeout = TIMEOUT) @Test(timeout = TIMEOUT)
@@ -75,6 +74,7 @@ public class SSLConnectionTest extends Connection {
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.sslContext = createSSLContext();
opts.hostnameVerifier = hostnameVerifier;
socket = client(opts); socket = client(opts);
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override @Override
@@ -97,6 +97,7 @@ public class SSLConnectionTest extends Connection {
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.setDefaultSSLContext(createSSLContext());
IO.setDefaultHostnameVerifier(hostnameVerifier);
socket = client(); socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override @Override