List of usage examples for java.net Proxy toString
public String toString()
From source file:com.sunchenbin.store.feilong.core.net.URLConnectionUtil.java
/** * Open connection./*ww w. j a va 2 s.co m*/ * * @param httpRequest * the http request * @param connectionConfig * the connection config * @return the http url connection * @throws IOException * the IO exception * @since 1.2.0 */ private static HttpURLConnection openConnection(HttpRequest httpRequest, ConnectionConfig connectionConfig) throws IOException { ConnectionConfig useConnectionConfig = null == connectionConfig ? new ConnectionConfig() : connectionConfig; LOGGER.debug("httpRequest:[{}],useConnectionConfig:[{}]", JsonUtil.format(httpRequest), JsonUtil.format(useConnectionConfig)); URL url = new URL(httpRequest.getUri()); Proxy proxy = getProxy(useConnectionConfig.getProxyAddress(), useConnectionConfig.getProxyPort()); // urlConnection?URL??(http)?URLConnection?HttpURLConnection, // HttpURLConnection, HttpURLConnectionAPI. if (Validator.isNotNullOrEmpty(proxy)) { LOGGER.debug("use proxy:{}", proxy.toString()); return (HttpURLConnection) url.openConnection(proxy); } // ? URL ???? openConnection . return (HttpURLConnection) url.openConnection(); }
From source file:fr.cls.atoll.motu.library.misc.intfce.Organizer.java
/** * Open connection./* w w w . jav a 2 s . co m*/ * * @param url the url * @return the uRL connection * @throws MotuException the motu exception */ public static URLConnection openConnection(URL url) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("openConnection(URL) - start - url=" + url); } String scheme = url.getProtocol(); String host = url.getHost(); Proxy proxy = Organizer.getUrlConnectionProxy(scheme, host); URLConnection urlConnection = null; if (proxy != null) { try { urlConnection = url.openConnection(proxy); } catch (IOException e) { LOG.error("openConnection(URL)", e); throw new MotuException(String.format("Unable to open URL connection '%s' (Proxy: '%s')", url.toString(), proxy.toString()), e); } } else { try { urlConnection = url.openConnection(); } catch (IOException e) { LOG.error("openConnection(URL)", e); throw new MotuException( String.format("Unable to open URL connection '%s' (No Proxy:)", url.toString()), e); } } if (LOG.isDebugEnabled()) { LOG.debug("openConnection(URL) - end"); } return urlConnection; }
From source file:org.cytoscape.cpath2.internal.CPathProtocol.java
/** * Sets Proxy Information (if set)./*from w w w . j av a 2 s .com*/ */ private void setProxyInfo(HttpClient client) { // TODO: Port this. // Proxy proxyServer = ProxyHandler.getProxyServer(); Proxy proxyServer = null; // The java.net.Proxy object does not provide getters for host and port. // So, we have to hack it by using the toString() method. // Note to self for future reference: I was able to test all this code // by downloading and installing Privoxy, a local HTTP proxy, // available at: http://www.privoxy.org/. Once it was running, I used the // following props in ~/.cytoscape/cytoscape3.props: // proxy.server=127.0.0.1 // proxy.server.port=8118 // proxy.server.type=HTTP if (proxyServer != null) { String proxyAddress = proxyServer.toString(); if (debug) logger.debug("full proxy string: " + proxyAddress); String[] addressComponents = proxyAddress.split("@"); if (addressComponents.length == 2) { String parts[] = addressComponents[1].split(":"); if (parts.length == 2) { String hostString = parts[0].trim(); String hostParts[] = hostString.split("/"); if (hostParts.length > 0) { String host = hostParts[0].trim(); String port = parts[1].trim(); if (debug) logger.debug("proxy host: " + host); if (debug) logger.debug("proxy port: " + port); client.getHostConfiguration().setProxy(host, Integer.parseInt(port)); } } } } }
From source file:org.sonar.plugins.github.GitHubPluginConfiguration.java
public Proxy getHttpProxy() { try {// w w w .ja v a 2 s .c o m if (system2.property(HTTP_PROXY_HOSTNAME) != null && system2.property(HTTPS_PROXY_HOSTNAME) == null) { System.setProperty(HTTPS_PROXY_HOSTNAME, system2.property(HTTP_PROXY_HOSTNAME)); System.setProperty(HTTPS_PROXY_PORT, system2.property(HTTP_PROXY_PORT)); } String proxyUser = system2.property(HTTP_PROXY_USER); String proxyPass = system2.property(HTTP_PROXY_PASS); if (proxyUser != null && proxyPass != null) { Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPass.toCharArray()); } }); } Proxy selectedProxy = ProxySelector.getDefault().select(new URI(endpoint())).get(0); if (selectedProxy.type() == Proxy.Type.DIRECT) { LOG.debug("There was no suitable proxy found to connect to GitHub - direct connection is used "); } LOG.info("A proxy has been configured - {}", selectedProxy.toString()); return selectedProxy; } catch (URISyntaxException e) { throw new IllegalArgumentException( "Unable to perform GitHub WS operation - endpoint in wrong format: " + endpoint(), e); } }