List of usage examples for java.net Proxy NO_PROXY
Proxy NO_PROXY
To view the source code for java.net Proxy NO_PROXY.
Click Source Link
From source file:org.springframework.security.oauth.consumer.client.CoreOAuthConsumerSupport.java
/** * Selects a proxy for the given URL.//from w w w . j ava 2 s. c om * * @param requestTokenURL The URL * @return The proxy. */ protected Proxy selectProxy(URL requestTokenURL) { try { List<Proxy> selectedProxies = getProxySelector().select(requestTokenURL.toURI()); return selectedProxies.isEmpty() ? Proxy.NO_PROXY : selectedProxies.get(0); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:com.blackducksoftware.integration.hub.jenkins.PostBuildHubScan.java
public void addProxySettingsToCLIInstaller(final IntLogger logger, final CLIRemoteInstall remoteCLIInstall) throws BDJenkinsHubPluginException, HubIntegrationException, URISyntaxException, MalformedURLException { final Jenkins jenkins = Jenkins.getInstance(); if (jenkins != null) { final ProxyConfiguration proxyConfig = jenkins.proxy; if (proxyConfig != null) { final URL serverUrl = new URL(getHubServerInfo().getServerUrl()); final Proxy proxy = ProxyConfiguration.createProxy(serverUrl.getHost(), proxyConfig.name, proxyConfig.port, proxyConfig.noProxyHost); if (proxy != Proxy.NO_PROXY && proxy.address() != null) { final InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); if (StringUtils.isNotBlank(proxyAddress.getHostName()) && proxyAddress.getPort() != 0) { if (StringUtils.isNotBlank(jenkins.proxy.getUserName()) && StringUtils.isNotBlank(jenkins.proxy.getPassword())) { remoteCLIInstall.setProxyHost(proxyAddress.getHostName()); remoteCLIInstall.setProxyPort(proxyAddress.getPort()); remoteCLIInstall.setProxyUserName(jenkins.proxy.getUserName()); remoteCLIInstall.setProxyPassword(jenkins.proxy.getPassword()); } else { remoteCLIInstall.setProxyHost(proxyAddress.getHostName()); remoteCLIInstall.setProxyPort(proxyAddress.getPort()); }/*from w w w .j av a2 s.c o m*/ if (logger != null) { logger.debug("Using proxy: '" + proxyAddress.getHostName() + "' at Port: '" + proxyAddress.getPort() + "'"); } } } } } }
From source file:org.eclipse.mylyn.commons.net.WebUtil.java
/** * @since 3.1//from www.ja v a2 s . c om */ public static Proxy createProxy(String proxyHost, int proxyPort, AuthenticationCredentials credentials) { String proxyUsername = ""; //$NON-NLS-1$ String proxyPassword = ""; //$NON-NLS-1$ if (credentials != null) { proxyUsername = credentials.getUserName(); proxyPassword = credentials.getPassword(); } if (proxyHost != null && proxyHost.length() > 0) { InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort); boolean authenticated = (proxyUsername != null && proxyPassword != null && proxyUsername.length() > 0 && proxyPassword.length() > 0); if (authenticated) { return new AuthenticatedProxy(Type.HTTP, sockAddr, proxyUsername, proxyPassword); } else { return new Proxy(Type.HTTP, sockAddr); } } return Proxy.NO_PROXY; }
From source file:com.vuze.plugin.azVPN_Helper.CheckerCommon.java
protected boolean canReach(InetAddress addressToReach, URI uri) { InetAddress[] resolve = null; try {/* www.j a v a 2 s . c om*/ String domain = uri.getHost(); // If Vuze has a proxy set up (Tools->Options->Connection->Proxy), then // we'll need to disable it for the URL AEProxySelector selector = AEProxySelectorFactory.getSelector(); if (selector != null) { resolve = SystemDefaultDnsResolver.INSTANCE.resolve(domain); for (InetAddress address : resolve) { selector.setProxy(new InetSocketAddress(address, 443), Proxy.NO_PROXY); } } HttpHead getHead = new HttpHead(uri); RequestConfig requestConfig = RequestConfig.custom().setLocalAddress(addressToReach) .setConnectTimeout(12000).build(); getHead.setConfig(requestConfig); CloseableHttpResponse response = HttpClients.createDefault().execute(getHead); response.close(); } catch (Throwable t) { t.printStackTrace(); return false; } finally { AEProxySelector selector = AEProxySelectorFactory.getSelector(); if (selector != null && resolve != null) { for (InetAddress address : resolve) { AEProxySelectorFactory.getSelector().removeProxy(new InetSocketAddress(address, 443)); } } } return true; }
From source file:com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.java
private void setClientProxyParams(String host, HttpClientBuilder builder) { Jenkins jenkins = Jenkins.getInstance(); ProxyConfiguration proxyConfig = null; if (jenkins != null) { proxyConfig = jenkins.proxy;/*from www .j av a 2 s . c om*/ } final Proxy proxy; if (proxyConfig != null) { URI hostURI = URI.create(host); proxy = proxyConfig.createProxy(hostURI.getHost()); } else { proxy = Proxy.NO_PROXY; } if (proxy.type() != Proxy.Type.DIRECT) { final InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); LOGGER.log(Level.FINE, "Jenkins proxy: {0}", proxy.address()); builder.setProxy(new HttpHost(proxyAddress.getHostName(), proxyAddress.getPort())); String username = proxyConfig.getUserName(); String password = proxyConfig.getPassword(); if (username != null && !"".equals(username.trim())) { LOGGER.fine("Using proxy authentication (user=" + username + ")"); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); AuthCache authCache = new BasicAuthCache(); authCache.put(HttpHost.create(proxyAddress.getHostName()), new BasicScheme()); context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache); } } }
From source file:net.sf.jsignpdf.BasicSignerOptions.java
/** * Creates and returns Proxy object, which should be used for URL * connections in JSignPdf.//from w ww .j a v a 2 s . co m * * @return initialized Proxy object. */ public Proxy createProxy() { Proxy tmpResult = Proxy.NO_PROXY; if (isAdvanced() && getProxyType() != Proxy.Type.DIRECT) { tmpResult = new Proxy(getProxyType(), new InetSocketAddress(getProxyHost(), getProxyPort())); } return tmpResult; }
From source file:fur.shadowdrake.minecraft.InstallPanel.java
public boolean downloadMojangLauncher() { URL u;//from w w w.java 2 s . c om HttpURLConnection connection; Proxy p; InputStream is; FileOutputStream fos; if (new File(config.getInstallDir(), "Minecraft.jar").isFile()) { return true; } log.println("Connecting to Mojang server..."); if (config.getHttpProxy().isEmpty()) { p = Proxy.NO_PROXY; } else { Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { if (getRequestorType() == Authenticator.RequestorType.PROXY) { return config.getHttpProxyCredentials(); } else { return super.getPasswordAuthentication(); } } }); p = new Proxy(Proxy.Type.HTTP, new ProxyAddress(config.getHttpProxy(), 3128).getSockaddr()); } try { u = new URL("https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar"); connection = (HttpURLConnection) u.openConnection(p); connection.addRequestProperty("User-agent", "Minecraft Bootloader"); connection.setUseCaches(false); connection.setDefaultUseCaches(false); connection.setConnectTimeout(10000); connection.setReadTimeout(10000); connection.connect(); log.println("Mojang server returned " + connection.getResponseMessage()); if (connection.getResponseCode() != 200) { connection.disconnect(); return false; } } catch (MalformedURLException ex) { Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (IOException ex) { Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex); log.println("Connection to Mojang server failed."); return false; } try { is = connection.getInputStream(); fos = new FileOutputStream(new File(config.getInstallDir(), "Minecraft.jar")); log.println("Downloading Minecraft.jar"); byte[] buffer = new byte[4096]; for (int n = is.read(buffer); n > 0; n = is.read(buffer)) { fos.write(buffer, 0, n); } fos.close(); is.close(); connection.disconnect(); log.println("Done."); } catch (IOException ex) { Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, "downloadMojangLauncher", ex); log.println("Faild to save file."); return false; } return true; }
From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java
void additionalAuthentication(String passPhrase) { final String passwordPhrase = passPhrase; JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() { @Override// www . j av a 2 s . c o m protected void configure(OpenSshConfig.Host hc, Session session) { CredentialsProvider provider = new CredentialsProvider() { @Override public boolean isInteractive() { return false; } @Override public boolean supports(CredentialItem... items) { return true; } @Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { for (CredentialItem item : items) { if (item instanceof CredentialItem.StringType) { ((CredentialItem.StringType) item).setValue(passwordPhrase); } } return true; } }; UserInfo userInfo = new CredentialsProviderUserInfo(session, provider); // Unknown host key for ssh java.util.Properties config = new java.util.Properties(); config.put(STRICT_HOST_KEY_CHECKING, NO); session.setConfig(config); session.setUserInfo(userInfo); } }; SshSessionFactory.setInstance(sessionFactory); /* * Enable clone of https url by trusting those urls */ // Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { } } }; final String https_proxy = System.getenv(HTTPS_PROXY); final String http_proxy = System.getenv(HTTP_PROXY); ProxySelector.setDefault(new ProxySelector() { final ProxySelector delegate = ProxySelector.getDefault(); @Override public List<Proxy> select(URI uri) { // Filter the URIs to be proxied if (uri.toString().contains(HTTPS) && StringUtils.isNotEmpty(http_proxy) && http_proxy != null) { try { URI httpsUri = new URI(https_proxy); String host = httpsUri.getHost(); int port = httpsUri.getPort(); return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(host, port))); } catch (URISyntaxException e) { if (debugEnabled) { S_LOGGER.debug("Url exception caught in https block of additionalAuthentication()"); } } } if (uri.toString().contains(HTTP) && StringUtils.isNotEmpty(http_proxy) && http_proxy != null) { try { URI httpUri = new URI(http_proxy); String host = httpUri.getHost(); int port = httpUri.getPort(); return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(host, port))); } catch (URISyntaxException e) { if (debugEnabled) { S_LOGGER.debug("Url exception caught in http block of additionalAuthentication()"); } } } // revert to the default behaviour return delegate == null ? Arrays.asList(Proxy.NO_PROXY) : delegate.select(uri); } @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { if (uri == null || sa == null || ioe == null) { throw new IllegalArgumentException("Arguments can't be null."); } } }); // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance(SSL); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (GeneralSecurityException e) { e.getLocalizedMessage(); } }
From source file:org.mariotaku.twidere.util.Utils.java
public static HttpClientWrapper getHttpClient(final int timeout_millis, final boolean ignore_ssl_error, final Proxy proxy, final HostAddressResolver resolver, final String user_agent) { final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setHttpConnectionTimeout(timeout_millis); cb.setIgnoreSSLError(ignore_ssl_error); if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { final SocketAddress address = proxy.address(); if (address instanceof InetSocketAddress) { cb.setHttpProxyHost(((InetSocketAddress) address).getHostName()); cb.setHttpProxyPort(((InetSocketAddress) address).getPort()); }//from www . j a v a2 s.c o m } cb.setHostAddressResolver(resolver); if (user_agent != null) { cb.setUserAgent(user_agent); } // cb.setHttpClientImplementation(HttpClientImpl.class); return new HttpClientWrapper(cb.build()); }
From source file:com.dwdesign.tweetings.util.Utils.java
public static Proxy getProxy(final Context context) { if (context == null) return null; final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final boolean enable_proxy = prefs.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false); if (!enable_proxy) return Proxy.NO_PROXY; final String proxy_host = prefs.getString(PREFERENCE_KEY_PROXY_HOST, null); final int proxy_port = parseInt(prefs.getString(PREFERENCE_KEY_PROXY_PORT, "-1")); if (!isNullOrEmpty(proxy_host) && proxy_port > 0) { final SocketAddress addr = InetSocketAddress.createUnresolved(proxy_host, proxy_port); return new Proxy(Proxy.Type.HTTP, addr); }//from w w w . jav a 2 s . co m return Proxy.NO_PROXY; }