Search in sources :

Example 1 with Type

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;
}
Also used : Type(java.net.Proxy.Type) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Properties(java.util.Properties)

Example 2 with Type

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();
}
Also used : Type(java.net.Proxy.Type) Proxy(java.net.Proxy) BasicAuthenticator(com.burgstaller.okhttp.basic.BasicAuthenticator) InetSocketAddress(java.net.InetSocketAddress) Credentials(com.burgstaller.okhttp.digest.Credentials)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 Proxy (java.net.Proxy)2 Type (java.net.Proxy.Type)2 BasicAuthenticator (com.burgstaller.okhttp.basic.BasicAuthenticator)1 Credentials (com.burgstaller.okhttp.digest.Credentials)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1