fix not to throw URISyntaxException

This commit is contained in:
Naoyuki Kanezawa
2015-06-28 02:00:54 +09:00
parent acd7426a48
commit f8c723289e
3 changed files with 25 additions and 22 deletions

View File

@@ -5,7 +5,6 @@ import com.github.nkzawa.socketio.parser.Parser;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -42,7 +41,7 @@ public class IO {
return socket(new URI(uri), opts);
}
public static Socket socket(URI uri) throws URISyntaxException {
public static Socket socket(URI uri) {
return socket(uri, null);
}
@@ -54,18 +53,18 @@ public class IO {
* @return {@link Socket} instance.
* @throws URISyntaxException
*/
public static Socket socket(URI uri, Options opts) throws URISyntaxException {
public static Socket socket(URI uri, Options opts) {
if (opts == null) {
opts = new Options();
}
URL parsed;
URL parsed = Url.parse(uri);
URI source;
try {
parsed = Url.parse(uri);
} catch (MalformedURLException e) {
throw new URISyntaxException(uri.toString(), e.getMessage());
source = parsed.toURI();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
URI source = parsed.toURI();
Manager io;
if (opts.forceNew || !opts.multiplex) {

View File

@@ -13,11 +13,11 @@ public class Url {
private Url() {}
public static URL parse(String uri) throws URISyntaxException, MalformedURLException {
public static URL parse(String uri) throws URISyntaxException {
return parse(new URI(uri));
}
public static URL parse(URI uri) throws MalformedURLException {
public static URL parse(URI uri) {
String protocol = uri.getScheme();
if (protocol == null || !protocol.matches("^https?|wss?$")) {
protocol = "https";
@@ -40,13 +40,17 @@ public class Url {
String userInfo = uri.getRawUserInfo();
String query = uri.getRawQuery();
String fragment = uri.getRawFragment();
return new URL(protocol + "://"
+ (userInfo != null ? userInfo + "@" : "")
+ uri.getHost()
+ (port != -1 ? ":" + port : "")
+ path
+ (query != null ? "?" + query : "")
+ (fragment != null ? "#" + fragment : ""));
try {
return new URL(protocol + "://"
+ (userInfo != null ? userInfo + "@" : "")
+ uri.getHost()
+ (port != -1 ? ":" + port : "")
+ path
+ (query != null ? "?" + query : "")
+ (fragment != null ? "#" + fragment : ""));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public static String extractId(String url) throws MalformedURLException {