use of java.net.Proxy.Type in project cytoscape-impl by cytoscape.
the class StreamUtilImpl method getProxy.
@SuppressWarnings("unchecked")
private Proxy getProxy() {
final CyProperty<Properties> cyProperty = serviceRegistrar.getService(CyProperty.class, "(cyPropertyName=cytoscape3.props)");
final Properties properties = cyProperty.getProperties();
final String proxyType = properties.getProperty("proxy.server.type");
if ("direct".equals(proxyType))
return Proxy.NO_PROXY;
String hostName = properties.getProperty("proxy.server");
String portString = properties.getProperty("proxy.server.port");
userName = properties.getProperty("proxy.server.userName");
String encodedPassword = properties.getProperty("proxy.server.password");
if (userName != null && userName.isEmpty())
userName = null;
if (encodedPassword != null) {
try {
password = decode(encodedPassword);
} catch (IOException e) {
password = null;
}
}
try {
int port = Integer.parseInt(portString);
Type type = null;
if ("http".equals(proxyType))
type = Type.HTTP;
if ("socks".equals(proxyType))
type = Type.SOCKS;
if (type == null)
return Proxy.NO_PROXY;
return new Proxy(type, new InetSocketAddress(hostName, port));
} catch (NumberFormatException e) {
}
return Proxy.NO_PROXY;
}
use of java.net.Proxy.Type in project LibreraReader by foobnix.
the class OPDS method buildProxy.
public static void buildProxy() {
new Thread(new Runnable() {
@Override
public void run() {
if (AppState.get().proxyEnable && TxtUtils.isNotEmpty(AppState.get().proxyServer) && AppState.get().proxyPort != 0) {
Type http = AppState.PROXY_SOCKS.equals(AppState.get().proxyType) ? Type.SOCKS : Type.HTTP;
LOG.d("Proxy: Server", http.name(), AppState.get().proxyServer, AppState.get().proxyPort);
builder.proxy(new Proxy(http, new InetSocketAddress(AppState.get().proxyServer, AppState.get().proxyPort)));
if (TxtUtils.isNotEmpty(AppState.get().proxyUser)) {
LOG.d("Proxy: User", AppState.get().proxyUser, AppState.get().proxyPassword);
builder.proxyAuthenticator(new BasicAuthenticator(new Credentials(AppState.get().proxyUser, AppState.get().proxyPassword)));
}
} else {
builder.proxy(null);
}
client = builder.build();
}
}).start();
}
Aggregations