Simplify API: remove HttpConnectionProvider
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
package io.socket.engineio.client;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Eugene.Kudelevsky
|
|
||||||
*/
|
|
||||||
public interface HttpConnectionProvider {
|
|
||||||
HttpURLConnection openConnection(URL url) throws IOException;
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,7 @@ import org.json.JSONException;
|
|||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -128,11 +129,9 @@ public class Socket extends Emitter {
|
|||||||
private Future pingIntervalTimer;
|
private Future pingIntervalTimer;
|
||||||
private SSLContext sslContext;
|
private SSLContext sslContext;
|
||||||
private HostnameVerifier hostnameVerifier;
|
private HostnameVerifier hostnameVerifier;
|
||||||
public String proxyHost;
|
public Proxy proxy;
|
||||||
public int proxyPort = -1;
|
|
||||||
public String proxyLogin;
|
public String proxyLogin;
|
||||||
public String proxyPassword;
|
public String proxyPassword;
|
||||||
private HttpConnectionProvider httpConnectionProvider;
|
|
||||||
|
|
||||||
private ReadyState readyState;
|
private ReadyState readyState;
|
||||||
private ScheduledExecutorService heartbeatScheduler;
|
private ScheduledExecutorService heartbeatScheduler;
|
||||||
@@ -210,11 +209,9 @@ public class Socket extends Emitter {
|
|||||||
this.policyPort = opts.policyPort != 0 ? opts.policyPort : 843;
|
this.policyPort = opts.policyPort != 0 ? opts.policyPort : 843;
|
||||||
this.rememberUpgrade = opts.rememberUpgrade;
|
this.rememberUpgrade = opts.rememberUpgrade;
|
||||||
this.hostnameVerifier = opts.hostnameVerifier != null ? opts.hostnameVerifier : defaultHostnameVerifier;
|
this.hostnameVerifier = opts.hostnameVerifier != null ? opts.hostnameVerifier : defaultHostnameVerifier;
|
||||||
this.proxyHost = opts.proxyHost;
|
this.proxy = opts.proxy;
|
||||||
this.proxyPort = opts.proxyPort;
|
|
||||||
this.proxyLogin = opts.proxyLogin;
|
this.proxyLogin = opts.proxyLogin;
|
||||||
this.proxyPassword = opts.proxyPassword;
|
this.proxyPassword = opts.proxyPassword;
|
||||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDefaultSSLContext(SSLContext sslContext) {
|
public static void setDefaultSSLContext(SSLContext sslContext) {
|
||||||
@@ -281,11 +278,9 @@ public class Socket extends Emitter {
|
|||||||
opts.policyPort = this.policyPort;
|
opts.policyPort = this.policyPort;
|
||||||
opts.socket = this;
|
opts.socket = this;
|
||||||
opts.hostnameVerifier = this.hostnameVerifier;
|
opts.hostnameVerifier = this.hostnameVerifier;
|
||||||
opts.proxyHost = this.proxyHost;
|
opts.proxy = this.proxy;
|
||||||
opts.proxyPort = this.proxyPort;
|
|
||||||
opts.proxyLogin = this.proxyLogin;
|
opts.proxyLogin = this.proxyLogin;
|
||||||
opts.proxyPassword = this.proxyPassword;
|
opts.proxyPassword = this.proxyPassword;
|
||||||
opts.httpConnectionProvider = this.httpConnectionProvider;
|
|
||||||
|
|
||||||
Transport transport;
|
Transport transport;
|
||||||
if (WebSocket.NAME.equals(name)) {
|
if (WebSocket.NAME.equals(name)) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.socket.utf8.UTF8Exception;
|
|||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class Transport extends Emitter {
|
public abstract class Transport extends Emitter {
|
||||||
@@ -43,11 +44,9 @@ public abstract class Transport extends Emitter {
|
|||||||
protected SSLContext sslContext;
|
protected SSLContext sslContext;
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected HostnameVerifier hostnameVerifier;
|
protected HostnameVerifier hostnameVerifier;
|
||||||
protected String proxyHost;
|
protected Proxy proxy;
|
||||||
protected int proxyPort;
|
|
||||||
protected String proxyLogin;
|
protected String proxyLogin;
|
||||||
protected String proxyPassword;
|
protected String proxyPassword;
|
||||||
protected HttpConnectionProvider httpConnectionProvider;
|
|
||||||
|
|
||||||
protected ReadyState readyState;
|
protected ReadyState readyState;
|
||||||
|
|
||||||
@@ -62,11 +61,9 @@ public abstract class Transport extends Emitter {
|
|||||||
this.sslContext = opts.sslContext;
|
this.sslContext = opts.sslContext;
|
||||||
this.socket = opts.socket;
|
this.socket = opts.socket;
|
||||||
this.hostnameVerifier = opts.hostnameVerifier;
|
this.hostnameVerifier = opts.hostnameVerifier;
|
||||||
this.proxyHost = opts.proxyHost;
|
this.proxy = opts.proxy;
|
||||||
this.proxyPort = opts.proxyPort;
|
|
||||||
this.proxyLogin = opts.proxyLogin;
|
this.proxyLogin = opts.proxyLogin;
|
||||||
this.proxyPassword = opts.proxyPassword;
|
this.proxyPassword = opts.proxyPassword;
|
||||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Transport onError(String msg, Exception desc) {
|
protected Transport onError(String msg, Exception desc) {
|
||||||
@@ -162,10 +159,8 @@ public abstract class Transport extends Emitter {
|
|||||||
public SSLContext sslContext;
|
public SSLContext sslContext;
|
||||||
public HostnameVerifier hostnameVerifier;
|
public HostnameVerifier hostnameVerifier;
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
public String proxyHost;
|
public Proxy proxy;
|
||||||
public int proxyPort = -1;
|
|
||||||
public String proxyLogin;
|
public String proxyLogin;
|
||||||
public String proxyPassword;
|
public String proxyPassword;
|
||||||
public HttpConnectionProvider httpConnectionProvider;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.socket.engineio.client.transports;
|
|||||||
|
|
||||||
|
|
||||||
import io.socket.emitter.Emitter;
|
import io.socket.emitter.Emitter;
|
||||||
import io.socket.engineio.client.HttpConnectionProvider;
|
|
||||||
import io.socket.engineio.client.Transport;
|
import io.socket.engineio.client.Transport;
|
||||||
import io.socket.thread.EventThread;
|
import io.socket.thread.EventThread;
|
||||||
|
|
||||||
@@ -11,6 +10,7 @@ import javax.net.ssl.HttpsURLConnection;
|
|||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -38,7 +38,7 @@ public class PollingXHR extends Polling {
|
|||||||
opts.uri = this.uri();
|
opts.uri = this.uri();
|
||||||
opts.sslContext = this.sslContext;
|
opts.sslContext = this.sslContext;
|
||||||
opts.hostnameVerifier = this.hostnameVerifier;
|
opts.hostnameVerifier = this.hostnameVerifier;
|
||||||
opts.httpConnectionProvider = this.httpConnectionProvider;
|
opts.proxy = this.proxy;
|
||||||
|
|
||||||
Request req = new Request(opts);
|
Request req = new Request(opts);
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ public class PollingXHR extends Polling {
|
|||||||
private SSLContext sslContext;
|
private SSLContext sslContext;
|
||||||
private HttpURLConnection xhr;
|
private HttpURLConnection xhr;
|
||||||
private HostnameVerifier hostnameVerifier;
|
private HostnameVerifier hostnameVerifier;
|
||||||
private HttpConnectionProvider httpConnectionProvider;
|
private Proxy proxy;
|
||||||
|
|
||||||
public Request(Options opts) {
|
public Request(Options opts) {
|
||||||
this.method = opts.method != null ? opts.method : "GET";
|
this.method = opts.method != null ? opts.method : "GET";
|
||||||
@@ -159,7 +159,7 @@ public class PollingXHR extends Polling {
|
|||||||
this.data = opts.data;
|
this.data = opts.data;
|
||||||
this.sslContext = opts.sslContext;
|
this.sslContext = opts.sslContext;
|
||||||
this.hostnameVerifier = opts.hostnameVerifier;
|
this.hostnameVerifier = opts.hostnameVerifier;
|
||||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
this.proxy = opts.proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
@@ -167,12 +167,8 @@ public class PollingXHR extends Polling {
|
|||||||
try {
|
try {
|
||||||
logger.fine(String.format("xhr open %s: %s", this.method, this.uri));
|
logger.fine(String.format("xhr open %s: %s", this.method, this.uri));
|
||||||
URL url = new URL(this.uri);
|
URL url = new URL(this.uri);
|
||||||
if (httpConnectionProvider != null) {
|
xhr = proxy != null ? (HttpURLConnection) url.openConnection(proxy)
|
||||||
xhr = httpConnectionProvider.openConnection(url);
|
: (HttpURLConnection) url.openConnection();
|
||||||
}
|
|
||||||
if (xhr == null) {
|
|
||||||
xhr = (HttpURLConnection) url.openConnection();
|
|
||||||
}
|
|
||||||
xhr.setRequestMethod(this.method);
|
xhr.setRequestMethod(this.method);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.onError(e);
|
this.onError(e);
|
||||||
@@ -331,7 +327,7 @@ public class PollingXHR extends Polling {
|
|||||||
public byte[] data;
|
public byte[] data;
|
||||||
public SSLContext sslContext;
|
public SSLContext sslContext;
|
||||||
public HostnameVerifier hostnameVerifier;
|
public HostnameVerifier hostnameVerifier;
|
||||||
public HttpConnectionProvider httpConnectionProvider;
|
public Proxy proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import okio.Buffer;
|
|||||||
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Proxy;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -59,8 +57,8 @@ public class WebSocket extends Transport {
|
|||||||
if (this.hostnameVerifier != null) {
|
if (this.hostnameVerifier != null) {
|
||||||
clientBuilder.hostnameVerifier(this.hostnameVerifier);
|
clientBuilder.hostnameVerifier(this.hostnameVerifier);
|
||||||
}
|
}
|
||||||
if (proxyHost != null && !proxyHost.isEmpty() && proxyPort >= 0) {
|
if (proxy != null) {
|
||||||
clientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
|
clientBuilder.proxy(proxy);
|
||||||
}
|
}
|
||||||
if (proxyLogin != null && !proxyLogin.isEmpty()) {
|
if (proxyLogin != null && !proxyLogin.isEmpty()) {
|
||||||
final String credentials = Credentials.basic(proxyLogin, proxyPassword);
|
final String credentials = Credentials.basic(proxyLogin, proxyPassword);
|
||||||
|
|||||||
Reference in New Issue
Block a user