@Test public void testReturnProxyIfHTTPProxyIsSet() { System.setProperty("HTTP_PROXY", "http: System.clearProperty("ALL_PROXY"); assertNotNull(HttpUtils.returnProxyIfEnabled()); assertEquals("/104.207.145.113:3128", HttpUtils.returnProxyIfEnabled().address().toString()); assertEquals(Proxy.Type.HTTP, HttpUtils.returnProxyIfEnabled().type()); }
public static Proxy returnProxyIfEnabled() { LOG.debug("returnProxyIfEnabled() start!!"); String proxyStarturl = "http: String proxyURLString = System.getProperty(PROXY_PROPERTY_NAME) != null ? System.getProperty(PROXY_PROPERTY_NAME) : System.getProperty(PROXY_PROPERTY_NAME.toLowerCase()); String allproxyURLString = System.getProperty(ALL_PROXY_PROPERTY_NAME) != null ? System.getProperty(ALL_PROXY_PROPERTY_NAME) : System.getProperty(ALL_PROXY_PROPERTY_NAME.toLowerCase()); String finalProxyString = proxyURLString != null ? proxyURLString : allproxyURLString; URL proxyURL = null; try { if (finalProxyString != null && finalProxyString.toLowerCase().startsWith(proxyStarturl)) { proxyURL = returnParsedURL(finalProxyString); LOG.debug("protocol of proxy used is: " + proxyURL.getProtocol()); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())); } else if (finalProxyString != null && !finalProxyString.contains(": && finalProxyString.split(":").length == 2) { LOG.debug("protocol of proxy used is: http default"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString)); return proxyURL != null ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } else if (finalProxyString != null && finalProxyString.toLowerCase().startsWith("sock") && finalProxyString.split(": LOG.debug("protocol of proxy used is: Socks"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString.split(": return proxyURL != null ? new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } } catch (MalformedURLException | URISyntaxException mUE) { LOG.error("Can not configure Proxy because URL {} is incorrect: " + mUE, finalProxyString); } return null; }
HttpUtils { public static Proxy returnProxyIfEnabled() { LOG.debug("returnProxyIfEnabled() start!!"); String proxyStarturl = "http: String proxyURLString = System.getProperty(PROXY_PROPERTY_NAME) != null ? System.getProperty(PROXY_PROPERTY_NAME) : System.getProperty(PROXY_PROPERTY_NAME.toLowerCase()); String allproxyURLString = System.getProperty(ALL_PROXY_PROPERTY_NAME) != null ? System.getProperty(ALL_PROXY_PROPERTY_NAME) : System.getProperty(ALL_PROXY_PROPERTY_NAME.toLowerCase()); String finalProxyString = proxyURLString != null ? proxyURLString : allproxyURLString; URL proxyURL = null; try { if (finalProxyString != null && finalProxyString.toLowerCase().startsWith(proxyStarturl)) { proxyURL = returnParsedURL(finalProxyString); LOG.debug("protocol of proxy used is: " + proxyURL.getProtocol()); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())); } else if (finalProxyString != null && !finalProxyString.contains(": && finalProxyString.split(":").length == 2) { LOG.debug("protocol of proxy used is: http default"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString)); return proxyURL != null ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } else if (finalProxyString != null && finalProxyString.toLowerCase().startsWith("sock") && finalProxyString.split(": LOG.debug("protocol of proxy used is: Socks"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString.split(": return proxyURL != null ? new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } } catch (MalformedURLException | URISyntaxException mUE) { LOG.error("Can not configure Proxy because URL {} is incorrect: " + mUE, finalProxyString); } return null; } }
HttpUtils { public static Proxy returnProxyIfEnabled() { LOG.debug("returnProxyIfEnabled() start!!"); String proxyStarturl = "http: String proxyURLString = System.getProperty(PROXY_PROPERTY_NAME) != null ? System.getProperty(PROXY_PROPERTY_NAME) : System.getProperty(PROXY_PROPERTY_NAME.toLowerCase()); String allproxyURLString = System.getProperty(ALL_PROXY_PROPERTY_NAME) != null ? System.getProperty(ALL_PROXY_PROPERTY_NAME) : System.getProperty(ALL_PROXY_PROPERTY_NAME.toLowerCase()); String finalProxyString = proxyURLString != null ? proxyURLString : allproxyURLString; URL proxyURL = null; try { if (finalProxyString != null && finalProxyString.toLowerCase().startsWith(proxyStarturl)) { proxyURL = returnParsedURL(finalProxyString); LOG.debug("protocol of proxy used is: " + proxyURL.getProtocol()); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())); } else if (finalProxyString != null && !finalProxyString.contains(": && finalProxyString.split(":").length == 2) { LOG.debug("protocol of proxy used is: http default"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString)); return proxyURL != null ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } else if (finalProxyString != null && finalProxyString.toLowerCase().startsWith("sock") && finalProxyString.split(": LOG.debug("protocol of proxy used is: Socks"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString.split(": return proxyURL != null ? new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } } catch (MalformedURLException | URISyntaxException mUE) { LOG.error("Can not configure Proxy because URL {} is incorrect: " + mUE, finalProxyString); } return null; }  }
HttpUtils { public static Proxy returnProxyIfEnabled() { LOG.debug("returnProxyIfEnabled() start!!"); String proxyStarturl = "http: String proxyURLString = System.getProperty(PROXY_PROPERTY_NAME) != null ? System.getProperty(PROXY_PROPERTY_NAME) : System.getProperty(PROXY_PROPERTY_NAME.toLowerCase()); String allproxyURLString = System.getProperty(ALL_PROXY_PROPERTY_NAME) != null ? System.getProperty(ALL_PROXY_PROPERTY_NAME) : System.getProperty(ALL_PROXY_PROPERTY_NAME.toLowerCase()); String finalProxyString = proxyURLString != null ? proxyURLString : allproxyURLString; URL proxyURL = null; try { if (finalProxyString != null && finalProxyString.toLowerCase().startsWith(proxyStarturl)) { proxyURL = returnParsedURL(finalProxyString); LOG.debug("protocol of proxy used is: " + proxyURL.getProtocol()); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())); } else if (finalProxyString != null && !finalProxyString.contains(": && finalProxyString.split(":").length == 2) { LOG.debug("protocol of proxy used is: http default"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString)); return proxyURL != null ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } else if (finalProxyString != null && finalProxyString.toLowerCase().startsWith("sock") && finalProxyString.split(": LOG.debug("protocol of proxy used is: Socks"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString.split(": return proxyURL != null ? new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } } catch (MalformedURLException | URISyntaxException mUE) { LOG.error("Can not configure Proxy because URL {} is incorrect: " + mUE, finalProxyString); } return null; }  static void downloadFileWithProgress(String fileUrl, String outputFilePath); static Proxy returnProxyIfEnabled(); }
HttpUtils { public static Proxy returnProxyIfEnabled() { LOG.debug("returnProxyIfEnabled() start!!"); String proxyStarturl = "http: String proxyURLString = System.getProperty(PROXY_PROPERTY_NAME) != null ? System.getProperty(PROXY_PROPERTY_NAME) : System.getProperty(PROXY_PROPERTY_NAME.toLowerCase()); String allproxyURLString = System.getProperty(ALL_PROXY_PROPERTY_NAME) != null ? System.getProperty(ALL_PROXY_PROPERTY_NAME) : System.getProperty(ALL_PROXY_PROPERTY_NAME.toLowerCase()); String finalProxyString = proxyURLString != null ? proxyURLString : allproxyURLString; URL proxyURL = null; try { if (finalProxyString != null && finalProxyString.toLowerCase().startsWith(proxyStarturl)) { proxyURL = returnParsedURL(finalProxyString); LOG.debug("protocol of proxy used is: " + proxyURL.getProtocol()); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())); } else if (finalProxyString != null && !finalProxyString.contains(": && finalProxyString.split(":").length == 2) { LOG.debug("protocol of proxy used is: http default"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString)); return proxyURL != null ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } else if (finalProxyString != null && finalProxyString.toLowerCase().startsWith("sock") && finalProxyString.split(": LOG.debug("protocol of proxy used is: Socks"); proxyURL = returnParsedURL(proxyStarturl.concat(finalProxyString.split(": return proxyURL != null ? new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyURL.getHost(), proxyURL.getPort())) : null; } } catch (MalformedURLException | URISyntaxException mUE) { LOG.error("Can not configure Proxy because URL {} is incorrect: " + mUE, finalProxyString); } return null; }  static void downloadFileWithProgress(String fileUrl, String outputFilePath); static Proxy returnProxyIfEnabled();  }