Example usage for java.net Proxy NO_PROXY

List of usage examples for java.net Proxy NO_PROXY

Introduction

In this page you can find the example usage for java.net Proxy NO_PROXY.

Prototype

Proxy NO_PROXY

To view the source code for java.net Proxy NO_PROXY.

Click Source Link

Document

A proxy setting that represents a DIRECT connection, basically telling the protocol handler not to use any proxying.

Usage

From source file:cc.arduino.net.CustomProxySelector.java

public Proxy getProxyFor(URI uri) throws IOException, ScriptException, NoSuchMethodException {
    String proxyType = preferences.get(Constants.PREF_PROXY_TYPE);
    if (proxyType == null || proxyType.isEmpty()) {
        proxyType = Constants.PROXY_TYPE_AUTO;
    }//from  w  w  w  .j  a v  a  2  s  .c  om

    if (Constants.PROXY_TYPE_NONE.equals(proxyType)) {
        return Proxy.NO_PROXY;
    }

    if (Constants.PROXY_TYPE_AUTO.equals(proxyType)) {
        String pac = preferences.get(Constants.PREF_PROXY_PAC_URL);
        if (pac == null || pac.isEmpty()) {
            return ProxySelector.getDefault().select(uri).get(0);
        }

        return pacProxy(pac, uri);
    }

    if (Constants.PROXY_TYPE_MANUAL.equals(proxyType)) {
        return manualProxy();
    }

    throw new IllegalStateException("Unable to understand proxy settings");
}

From source file:be.agiv.security.client.ClientProxySelector.java

@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select for: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }//from   www  .  j a  v a2s  . com
    if (null != this.defaultProxySelector) {
        return this.defaultProxySelector.select(uri);
    }
    return Collections.singletonList(Proxy.NO_PROXY);
}

From source file:fr.ironcraft.assets.Assets.java

private void getResourceFiles() {

    Proxy proxy = Proxy.NO_PROXY;
    InputStream inputStream = null;
    File assets = new File(path, "assets");
    objectsFolder = new File(assets, "objects");
    indexesFolder = new File(assets, "indexes");
    virtualFolder = new File(assets, "virtual");
    legacyFolder = new File(virtualFolder, "legacy");
    if (indexName == null) {
        indexName = "legacy";
    }//ww w .j ava 2 s  .com
    File indexFile = new File(indexesFolder, indexName + ".json");

    try {
        URL indexUrl = new URL("https://s3.amazonaws.com/Minecraft.Download/indexes/" + indexName + ".json");
        inputStream = indexUrl.openConnection(proxy).getInputStream();
        String json = IOUtils.toString(inputStream);

        FileUtils.writeStringToFile(indexFile, json);
        index = gson.fromJson(json, AssetIndex.class);

        for (AssetObject object : index.getUniqueObjects()) {

            String filename = object.getHash().substring(0, 2) + "/" + object.getHash();

            File file = new File(objectsFolder, filename);
            if ((!file.isFile()) || (FileUtils.sizeOf(file) != object.getSize())) {
                FileDownloader downloadable = new FileDownloader(
                        new URL("http://resources.download.minecraft.net/" + filename), file, object.getSize());

                //downloadable.setExpectedSize(object.getSize());
                queue.add(downloadable);

            }

        }

    } catch (IOException ex) {

    } catch (JsonSyntaxException ex) {

    } finally {
        IOUtils.closeQuietly(inputStream);
    }

}

From source file:com.peach.masktime.module.net.OkHttpStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {

    OkHttpClient client = mClient.clone();
    int timeoutMs = request.getTimeoutMs();
    LogUtils.i(TAG, "timeoutMs = " + timeoutMs);
    client.setProxy(Proxy.NO_PROXY);
    client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS);

    com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());

    Map<String, String> headers = request.getHeaders();
    for (final String name : headers.keySet()) {
        okHttpRequestBuilder.addHeader(name, headers.get(name));
    }/*www .  ja v a 2  s . co  m*/
    for (final String name : additionalHeaders.keySet()) {
        okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name));
    }

    setConnectionParametersForRequest(okHttpRequestBuilder, request);

    com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();

    StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()),
            okHttpResponse.code(), okHttpResponse.message());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromOkHttpResponse(okHttpResponse));

    Headers responseHeaders = okHttpResponse.headers();
    for (int i = 0, len = responseHeaders.size(); i < len; i++) {
        final String name = responseHeaders.name(i), value = responseHeaders.value(i);
        if (name != null) {
            response.addHeader(new BasicHeader(name, value));
        }
    }
    return response;
}

From source file:org.wso2.extension.siddhi.device.utils.ClientUtils.java

public static OkHttpClient getSSLClient() {

    boolean isIgnoreHostnameVerification = Boolean
            .parseBoolean(System.getProperty("org.wso2" + ".ignoreHostnameVerification"));
    OkHttpClient okHttpClient;/*  w  w  w .  j a  v a 2  s.  co  m*/
    final String proxyHost = System.getProperty("http.proxyHost");
    final String proxyPort = System.getProperty("http.proxyPort");
    final String nonProxyHostsValue = System.getProperty("http.nonProxyHosts");

    final ProxySelector proxySelector = new ProxySelector() {
        @Override
        public List<Proxy> select(URI uri) {
            List<Proxy> proxyList = new ArrayList<>();
            String host = uri.getHost();

            if (!StringUtils.isEmpty(host)) {
                if (host.startsWith(DEFAULT_HOST_IP) || host.startsWith(DEFAULT_HOST)
                        || StringUtils.isEmpty(nonProxyHostsValue)
                        || StringUtils.contains(nonProxyHostsValue, host) || StringUtils.isEmpty(proxyHost)
                        || StringUtils.isEmpty(proxyPort)) {
                    proxyList.add(Proxy.NO_PROXY);
                } else {
                    proxyList.add(new Proxy(Proxy.Type.HTTP,
                            new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort))));
                }
            } else {
                log.error("Host is null. Host could not be empty or null");
            }
            return proxyList;
        }

        @Override
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };

    X509TrustManager trustAllCerts = new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return new java.security.cert.X509Certificate[0];
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }
    };
    if (isIgnoreHostnameVerification) {
        okHttpClient = new OkHttpClient.Builder()
                .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts)
                .hostnameVerifier(new HostnameVerifier() {
                    @Override
                    public boolean verify(String s, SSLSession sslSession) {
                        return true;
                    }
                }).proxySelector(proxySelector).build();
        return okHttpClient;
    } else {
        SSLSocketFactory trustedSSLSocketFactory = getTrustedSSLSocketFactory();
        okHttpClient = new OkHttpClient.Builder().sslSocketFactory(trustedSSLSocketFactory)
                .proxySelector(proxySelector).build();
        return okHttpClient;
    }
}

From source file:fm.last.moji.impl.PropertyMojiFactory.java

public PropertyMojiFactory(String propertiesPath) throws IOException {
    this(propertiesPath, Proxy.NO_PROXY);
}

From source file:si.mazi.rescu.HttpTemplate.java

/**
 * Constructor//from   ww  w .ja  va 2  s .c o m
 */
public HttpTemplate() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    // Always use UTF8
    defaultHttpHeaders.put("Accept-Charset", CHARSET_UTF_8);
    // Assume form encoding by default (typically becomes application/json or application/xml)
    defaultHttpHeaders.put("Content-Type", "application/x-www-form-urlencoded");
    // Accept text/plain by default (typically becomes application/json or application/xml)
    defaultHttpHeaders.put("Accept", "text/plain");
    // User agent provides statistics for servers, but some use it for content negotiation so fake good agents
    defaultHttpHeaders.put("User-Agent", "ResCU JDK/6 AppleWebKit/535.7 Chrome/16.0.912.36 Safari/535.7"); // custom User-Agent

    if (Config.getProxyPort() == null || Config.getProxyHost() == null) {
        proxy = Proxy.NO_PROXY;
    } else {
        proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Config.getProxyHost(), Config.getProxyPort()));
        log.info("Using proxy {}", proxy);
    }
}

From source file:net.sf.keystore_explorer.utilities.net.PacProxySelector.java

/**
 * Get a list of proxies for the supplied URI.
 *
 * @param uri//from  www  .j a va  2  s. c om
 *            The URI that a connection is required to
 * @return List of proxies
 */
@Override
public List<Proxy> select(URI uri) {
    // If there are any issues with the PAC return 'no proxy'
    ArrayList<Proxy> proxies = new ArrayList<Proxy>();

    if (pacScript == null) {
        try {
            pacScript = compilePacScript(loadPacScript(pacUrl));
        } catch (PacProxyException ex) {
            ex.printStackTrace();
            proxies.add(Proxy.NO_PROXY);
            return proxies;
        }
    }

    String pacFunctionReturn = null;

    try {
        pacFunctionReturn = (String) pacScript.invokeFunction("FindProxyForURL", uri.toString(), uri.getHost());
    } catch (NoSuchMethodException ex) {
        ex.printStackTrace();
        proxies.add(Proxy.NO_PROXY);
        return proxies;
    } catch (ScriptException ex) {
        ex.printStackTrace();
        proxies.add(Proxy.NO_PROXY);
        return proxies;
    }

    if (pacFunctionReturn == null) {
        proxies.add(Proxy.NO_PROXY);
        return proxies;
    }

    proxies.addAll(parsePacProxies(pacFunctionReturn));

    if (proxies.size() == 0) {
        proxies.add(Proxy.NO_PROXY);
    }

    return proxies;
}

From source file:ch.cyberduck.core.socket.NetworkInterfaceAwareSocketFactory.java

/**
 * @param blacklisted Network interface names to ignore
 * @param proxy       Proxy or null for direct connection
 *///  www . ja va  2 s. c  o m
public NetworkInterfaceAwareSocketFactory(final SocketFactory delegate, final List<String> blacklisted,
        final java.net.Proxy proxy) {
    this.delegate = delegate;
    this.blacklisted = blacklisted;
    this.proxy = null == proxy ? Proxy.NO_PROXY : proxy;
}

From source file:fm.last.moji.impl.PropertyMojiFactory.java

public PropertyMojiFactory() throws IOException {
    this(DEFAULT_RESOURCE_PATH, Proxy.NO_PROXY);
}