remove the dependency for apache httpclient
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -19,11 +19,6 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>httpclient</artifactId>
|
|
||||||
<version>4.2.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.github.nkzawa.engineio.client;
|
|
||||||
|
|
||||||
|
|
||||||
public class EngineIO {
|
|
||||||
|
|
||||||
public EngineIO() {}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,17 +9,10 @@ import com.github.nkzawa.engineio.parser.Parser;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.apache.http.Consts;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -52,7 +45,7 @@ public abstract class Socket extends Emitter {
|
|||||||
private String readyState = "";
|
private String readyState = "";
|
||||||
private List<String> transports;
|
private List<String> transports;
|
||||||
private List<String> upgrades;
|
private List<String> upgrades;
|
||||||
private List<NameValuePair> query;
|
private Map<String, String> query;
|
||||||
private ConcurrentLinkedQueue<Packet> writeBuffer = new ConcurrentLinkedQueue<Packet>();
|
private ConcurrentLinkedQueue<Packet> writeBuffer = new ConcurrentLinkedQueue<Packet>();
|
||||||
private ConcurrentLinkedQueue<Runnable> callbackBuffer = new ConcurrentLinkedQueue<Runnable>();
|
private ConcurrentLinkedQueue<Runnable> callbackBuffer = new ConcurrentLinkedQueue<Runnable>();
|
||||||
private Transport transport;
|
private Transport transport;
|
||||||
@@ -90,7 +83,8 @@ public abstract class Socket extends Emitter {
|
|||||||
this.secure = opts.secure;
|
this.secure = opts.secure;
|
||||||
this.hostname = opts.hostname != null ? opts.hostname : "localhost";
|
this.hostname = opts.hostname != null ? opts.hostname : "localhost";
|
||||||
this.port = opts.port != 0 ? opts.port : (this.secure ? 443 : 80);
|
this.port = opts.port != 0 ? opts.port : (this.secure ? 443 : 80);
|
||||||
this.query = URLEncodedUtils.parse(opts.query, Consts.UTF_8);
|
this.query = opts.query != null ?
|
||||||
|
Util.qsParse(opts.query) : new HashMap<String, String>();
|
||||||
this.upgrade = opts.upgrade;
|
this.upgrade = opts.upgrade;
|
||||||
this.path = (opts.path != null ? opts.path : "/engine.io").replaceAll("/$", "") + "/";
|
this.path = (opts.path != null ? opts.path : "/engine.io").replaceAll("/$", "") + "/";
|
||||||
this.timestampParam = opts.timestampParam != null ? opts.timestampParam : "t";
|
this.timestampParam = opts.timestampParam != null ? opts.timestampParam : "t";
|
||||||
@@ -112,12 +106,12 @@ public abstract class Socket extends Emitter {
|
|||||||
|
|
||||||
private Transport createTransport(String name) {
|
private Transport createTransport(String name) {
|
||||||
logger.info(String.format("creating transport '%s'", name));
|
logger.info(String.format("creating transport '%s'", name));
|
||||||
List<NameValuePair> query = new ArrayList<NameValuePair>(this.query);
|
Map<String, String> query = new HashMap<String, String>(this.query);
|
||||||
|
|
||||||
query.add(new BasicNameValuePair("EIO", String.valueOf(Parser.protocol)));
|
query.put("EIO", String.valueOf(Parser.protocol));
|
||||||
query.add(new BasicNameValuePair("transport", name));
|
query.put("transport", name);
|
||||||
if (this.id != null) {
|
if (this.id != null) {
|
||||||
query.add(new BasicNameValuePair("sid", this.id));
|
query.put("sid", this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transport.Options opts = new Transport.Options();
|
Transport.Options opts = new Transport.Options();
|
||||||
@@ -320,17 +314,9 @@ public abstract class Socket extends Emitter {
|
|||||||
private void onHandshake(JsonObject data) {
|
private void onHandshake(JsonObject data) {
|
||||||
this.emit("handshake", data);
|
this.emit("handshake", data);
|
||||||
this.id = data.get("sid").getAsString();
|
this.id = data.get("sid").getAsString();
|
||||||
|
this.transport.query.put("sid", data.get("sid").getAsString());
|
||||||
|
|
||||||
Iterator<NameValuePair> i = this.transport.query.iterator();
|
List<String> upgrades = new ArrayList<String>();
|
||||||
while (i.hasNext()) {
|
|
||||||
NameValuePair pair = i.next();
|
|
||||||
if ("sid".equals(pair.getName())) {
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.transport.query.add(new BasicNameValuePair("sid", data.get("sid").getAsString()));
|
|
||||||
|
|
||||||
List<String> upgrades = new ArrayList<String >();
|
|
||||||
for (JsonElement upgrade : data.get("upgrades").getAsJsonArray()) {
|
for (JsonElement upgrade : data.get("upgrades").getAsJsonArray()) {
|
||||||
upgrades.add(upgrade.getAsString());
|
upgrades.add(upgrade.getAsString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,14 @@ package com.github.nkzawa.engineio.client;
|
|||||||
import com.github.nkzawa.emitter.Emitter;
|
import com.github.nkzawa.emitter.Emitter;
|
||||||
import com.github.nkzawa.engineio.parser.Packet;
|
import com.github.nkzawa.engineio.parser.Packet;
|
||||||
import com.github.nkzawa.engineio.parser.Parser;
|
import com.github.nkzawa.engineio.parser.Parser;
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class Transport extends Emitter {
|
public abstract class Transport extends Emitter {
|
||||||
|
|
||||||
public boolean writable;
|
public boolean writable;
|
||||||
public String name;
|
public String name;
|
||||||
public List<NameValuePair> query;
|
public Map<String, String> query;
|
||||||
|
|
||||||
protected boolean secure;
|
protected boolean secure;
|
||||||
protected boolean timestampRequests;
|
protected boolean timestampRequests;
|
||||||
@@ -99,7 +98,7 @@ public abstract class Transport extends Emitter {
|
|||||||
public boolean timestampRequests;
|
public boolean timestampRequests;
|
||||||
public int port;
|
public int port;
|
||||||
public int policyPort;
|
public int policyPort;
|
||||||
public List<NameValuePair> query;
|
public Map<String, String> query;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/main/java/com/github/nkzawa/engineio/client/Util.java
Normal file
43
src/main/java/com/github/nkzawa/engineio/client/Util.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package com.github.nkzawa.engineio.client;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
private Util() {}
|
||||||
|
|
||||||
|
public static String qs(Map<String, String> obj) {
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> entry : obj.entrySet()) {
|
||||||
|
if (str.length() > 0) str.append("&");
|
||||||
|
try {
|
||||||
|
str.append(URLEncoder.encode(entry.getKey(), "UTF-8")).append("=")
|
||||||
|
.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> qsParse(String qs) {
|
||||||
|
Map<String, String> qry = new HashMap<String, String>();
|
||||||
|
String[] pairs = qs.split("&");
|
||||||
|
for (String _pair : pairs) {
|
||||||
|
String[] pair = _pair.split("=");
|
||||||
|
try {
|
||||||
|
qry.put(URLDecoder.decode(pair[0], "UTF-8"),
|
||||||
|
pair.length > 0 ? URLDecoder.decode(pair[1], "UTF-8") : "");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return qry;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,13 @@ package com.github.nkzawa.engineio.client.transports;
|
|||||||
|
|
||||||
|
|
||||||
import com.github.nkzawa.engineio.client.Transport;
|
import com.github.nkzawa.engineio.client.Transport;
|
||||||
|
import com.github.nkzawa.engineio.client.Util;
|
||||||
import com.github.nkzawa.engineio.parser.Packet;
|
import com.github.nkzawa.engineio.parser.Packet;
|
||||||
import com.github.nkzawa.engineio.parser.Parser;
|
import com.github.nkzawa.engineio.parser.Parser;
|
||||||
import org.apache.http.Consts;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
abstract public class Polling extends Transport {
|
abstract public class Polling extends Transport {
|
||||||
@@ -139,26 +135,18 @@ abstract public class Polling extends Transport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String uri() {
|
protected String uri() {
|
||||||
List<NameValuePair> query = this.query;
|
Map<String, String> query = this.query;
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
query = new ArrayList<NameValuePair>();
|
query = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
String schema = this.secure ? "https" : "http";
|
String schema = this.secure ? "https" : "http";
|
||||||
String port = "";
|
String port = "";
|
||||||
|
|
||||||
if (this.timestampRequests) {
|
if (this.timestampRequests) {
|
||||||
Iterator<NameValuePair> i = query.iterator();
|
query.put(this.timestampParam, String.valueOf(new Date().getTime()));
|
||||||
while (i.hasNext()) {
|
|
||||||
NameValuePair pair = i.next();
|
|
||||||
if (this.timestampParam.equals(pair.getName())) {
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query.add(new BasicNameValuePair(this.timestampParam,
|
|
||||||
String.valueOf(new Date().getTime())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _query = URLEncodedUtils.format(query, Consts.UTF_8);
|
String _query = Util.qs(query);
|
||||||
|
|
||||||
if (this.port > 0 && (("https".equals(schema) && this.port != 443)
|
if (this.port > 0 && (("https".equals(schema) && this.port != 443)
|
||||||
|| ("http".equals(schema) && this.port != 80))) {
|
|| ("http".equals(schema) && this.port != 80))) {
|
||||||
|
|||||||
@@ -2,22 +2,18 @@ package com.github.nkzawa.engineio.client.transports;
|
|||||||
|
|
||||||
|
|
||||||
import com.github.nkzawa.engineio.client.Transport;
|
import com.github.nkzawa.engineio.client.Transport;
|
||||||
|
import com.github.nkzawa.engineio.client.Util;
|
||||||
import com.github.nkzawa.engineio.parser.Packet;
|
import com.github.nkzawa.engineio.parser.Packet;
|
||||||
import com.github.nkzawa.engineio.parser.Parser;
|
import com.github.nkzawa.engineio.parser.Parser;
|
||||||
import org.apache.http.Consts;
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
import org.java_websocket.drafts.Draft_17;
|
import org.java_websocket.drafts.Draft_17;
|
||||||
import org.java_websocket.handshake.ServerHandshake;
|
import org.java_websocket.handshake.ServerHandshake;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -112,9 +108,9 @@ public class WebSocket extends Transport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String uri() {
|
private String uri() {
|
||||||
List<NameValuePair> query = this.query;
|
Map<String, String> query = this.query;
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
query = new ArrayList<NameValuePair>();
|
query = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
String schema = this.secure ? "wss" : "ws";
|
String schema = this.secure ? "wss" : "ws";
|
||||||
String port = "";
|
String port = "";
|
||||||
@@ -125,18 +121,10 @@ public class WebSocket extends Transport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.timestampRequests) {
|
if (this.timestampRequests) {
|
||||||
Iterator<NameValuePair> i = query.iterator();
|
query.put(this.timestampParam, String.valueOf(new Date().getTime()));
|
||||||
while (i.hasNext()) {
|
|
||||||
NameValuePair pair = i.next();
|
|
||||||
if (this.timestampParam.equals(pair.getName())) {
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query.add(new BasicNameValuePair(this.timestampParam,
|
|
||||||
String.valueOf(new Date().getTime())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _query = URLEncodedUtils.format(query, Consts.UTF_8);
|
String _query = Util.qs(query);
|
||||||
if (_query.length() > 0) {
|
if (_query.length() > 0) {
|
||||||
_query = "?" + _query;
|
_query = "?" + _query;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user