|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
package org.redisson.misc;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
@ -41,31 +42,46 @@ public class URLBuilder {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
init = true;
|
|
|
|
|
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
|
|
|
|
|
@Override
|
|
|
|
|
public URLStreamHandler createURLStreamHandler(String protocol) {
|
|
|
|
|
if ("redis".equals(protocol)) {
|
|
|
|
|
return new URLStreamHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
protected URLConnection openConnection(URL u) throws IOException {
|
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Field field = URL.class.getDeclaredField("factory");
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
final URLStreamHandlerFactory currentFactory = (URLStreamHandlerFactory) field.get(null);
|
|
|
|
|
if (currentFactory != null) {
|
|
|
|
|
field.set(null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
|
|
|
|
|
@Override
|
|
|
|
|
public URLStreamHandler createURLStreamHandler(String protocol) {
|
|
|
|
|
if ("redis".equals(protocol)) {
|
|
|
|
|
return new URLStreamHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
protected URLConnection openConnection(URL u) throws IOException {
|
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean equals(URL u1, URL u2) {
|
|
|
|
|
return u1.toString().equals(u2.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected int hashCode(URL u) {
|
|
|
|
|
return u.toString().hashCode();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean equals(URL u1, URL u2) {
|
|
|
|
|
return u1.toString().equals(u2.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected int hashCode(URL u) {
|
|
|
|
|
return u.toString().hashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentFactory != null) {
|
|
|
|
|
return currentFactory.createURLStreamHandler(protocol);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new IllegalStateException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static InetSocketAddress toAddress(String url) {
|
|
|
|
|