List of usage examples for org.apache.commons.httpclient ProxyHost ProxyHost
public ProxyHost(ProxyHost paramProxyHost)
From source file:com.pureinfo.srmcenter.datasync.client.config.impl.SyncConfigImpl.java
public void setProxy() { HttpUtilImpl httpUtil = (HttpUtilImpl) PureFactory.getBean("sync.httpUtil"); String sHost = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_HOST); ProxyHost host = null;/*w ww . j a v a 2 s . c o m*/ if (sHost != null) { String sPort = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PORT); if (sPort == null) { host = new ProxyHost(sHost); } else { int nPort = Integer.parseInt(sPort); host = new ProxyHost(sHost, nPort); } } httpUtil.setProxyHost(host); String sUser = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_USER); httpUtil.setProxyUser(sUser); String sPassword = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PASSWORD); httpUtil.setProxyPassword(sPassword); }
From source file:com.pureinfo.srmcenter.datasync.client.config.action.WebConfigSetAction.java
public static void setProxy() { HttpUtilImpl httpUtil = (HttpUtilImpl) PureFactory.getBean("sync.httpUtil"); String sHost = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_HOST); ProxyHost host = null;/*w w w . j av a2 s . c o m*/ if (sHost != null && sHost.length() > 0) { String sPort = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PORT); if (sPort == null || sPort.length() == 0) { host = new ProxyHost(sHost); } else { int nPort = Integer.parseInt(sPort); host = new ProxyHost(sHost, nPort); } } httpUtil.setProxyHost(host); String sUser = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_USER); httpUtil.setProxyUser(sUser); String sPassword = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PASSWORD); httpUtil.setProxyPassword(sPassword); }
From source file:com.eucalyptus.webui.server.DownloadsWebBackend.java
public static ArrayList<DownloadInfo> getDownloads(String downloadsUrl) { ArrayList<DownloadInfo> downloadsList = Lists.newArrayList(); HttpClient httpClient = new HttpClient(); //set User-Agent String clientVersion = (String) httpClient.getParams().getDefaults() .getParameter(HttpMethodParams.USER_AGENT); String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String eucaVersion = System.getProperty("euca.version"); String extraVersion = System.getProperty("euca.extra_version"); // Jakarta Commons-HttpClient/3.1 (java 1.6.0_24; Linux amd64) Eucalyptus/3.1.0-1.el6 String userAgent = clientVersion + " (java " + javaVersion + "; " + osName + " " + osArch + ") Eucalyptus/" + eucaVersion;/* w w w .j a va2 s . c o m*/ if (extraVersion != null) { userAgent = userAgent + "-" + extraVersion; } httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent); //support for http proxy if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) { String proxyHost = HttpServerBootstrapper.httpProxyHost; if (HttpServerBootstrapper.httpProxyPort != null && (HttpServerBootstrapper.httpProxyPort.length() > 0)) { int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } else { httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost)); } } GetMethod method = new GetMethod(downloadsUrl); method.getParams().setSoTimeout(TIMEOUT); try { httpClient.executeMethod(method); String str = ""; InputStream in = method.getResponseBodyAsStream(); byte[] readBytes = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(readBytes)) > 0) { str += new String(readBytes, 0, bytesRead); } String entries[] = str.split("[\\r\\n]+"); for (int i = 0; i < entries.length; i++) { String entry[] = entries[i].split("\\t"); if (entry.length == 3) { downloadsList.add(new DownloadInfo(entry[0], entry[1], entry[2])); } } } catch (MalformedURLException e) { LOG.error("Malformed URL exception: " + downloadsUrl, e); LOG.debug(e, e); } catch (IOException e) { LOG.error("I/O exception", e); LOG.debug(e, e); } finally { method.releaseConnection(); } return downloadsList; }
From source file:edu.ucsb.eucalyptus.admin.server.EucalyptusManagement.java
private static String getExternalIpAddress() { String ipAddr = null;/* w w w. ja v a 2s. co m*/ HttpClient httpClient = new HttpClient(); //support for http proxy if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) { String proxyHost = HttpServerBootstrapper.httpProxyHost; if (HttpServerBootstrapper.httpProxyPort != null && (HttpServerBootstrapper.httpProxyPort.length() > 0)) { int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } else { httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost)); } } // Use Rightscale's "whoami" service GetMethod method = new GetMethod("https://my.rightscale.com/whoami?api_version=1.0&cloud=0"); Integer timeoutMs = new Integer(3 * 1000); // TODO: is this working? method.getParams().setSoTimeout(timeoutMs); try { httpClient.executeMethod(method); String str = ""; InputStream in = method.getResponseBodyAsStream(); byte[] readBytes = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(readBytes)) > 0) { str += new String(readBytes, 0, bytesRead); } Matcher matcher = Pattern.compile(".*your ip is (.*)").matcher(str); if (matcher.find()) { ipAddr = matcher.group(1); } } catch (MalformedURLException e) { LOG.warn("Malformed URL exception: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { LOG.warn("I/O exception: " + e.getMessage()); e.printStackTrace(); } finally { method.releaseConnection(); } return ipAddr; }
From source file:edu.ucsb.eucalyptus.admin.server.EucalyptusWebBackendImpl.java
private static List<DownloadsWeb> getDownloadsFromUrl(final String downloadsUrl) { List<DownloadsWeb> downloadsList = new ArrayList<DownloadsWeb>(); HttpClient httpClient = new HttpClient(); //support for http proxy if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) { String proxyHost = HttpServerBootstrapper.httpProxyHost; if (HttpServerBootstrapper.httpProxyPort != null && (HttpServerBootstrapper.httpProxyPort.length() > 0)) { int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } else {/* ww w . j a va 2s.c o m*/ httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost)); } } GetMethod method = new GetMethod(downloadsUrl); Integer timeoutMs = new Integer(3 * 1000); method.getParams().setSoTimeout(timeoutMs); try { httpClient.executeMethod(method); String str = ""; InputStream in = method.getResponseBodyAsStream(); byte[] readBytes = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(readBytes)) > 0) { str += new String(readBytes, 0, bytesRead); } String entries[] = str.split("[\\r\\n]+"); for (int i = 0; i < entries.length; i++) { String entry[] = entries[i].split("\\t"); if (entry.length == 3) { downloadsList.add(new DownloadsWeb(entry[0], entry[1], entry[2])); } } } catch (MalformedURLException e) { LOG.warn("Malformed URL exception: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { LOG.warn("I/O exception: " + e.getMessage()); e.printStackTrace(); } finally { method.releaseConnection(); } return downloadsList; }
From source file:com.eucalyptus.webui.server.ConfigurationWebBackend.java
private static String getExternalIpAddress() { String ipAddr = null;//from w ww . jav a 2 s. com HttpClient httpClient = new HttpClient(); //set User-Agent String clientVersion = (String) httpClient.getParams().getDefaults() .getParameter(HttpMethodParams.USER_AGENT); String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String eucaVersion = System.getProperty("euca.version"); String extraVersion = System.getProperty("euca.extra_version"); // Jakarta Commons-HttpClient/3.1 (java 1.6.0_24; Linux amd64) Eucalyptus/3.1.0-1.el6 String userAgent = clientVersion + " (java " + javaVersion + "; " + osName + " " + osArch + ") Eucalyptus/" + eucaVersion; if (extraVersion != null) { userAgent = userAgent + "-" + extraVersion; } httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent); //support for http proxy if (HttpServerBootstrapper.httpProxyHost != null && (HttpServerBootstrapper.httpProxyHost.length() > 0)) { String proxyHost = HttpServerBootstrapper.httpProxyHost; if (HttpServerBootstrapper.httpProxyPort != null && (HttpServerBootstrapper.httpProxyPort.length() > 0)) { int proxyPort = Integer.parseInt(HttpServerBootstrapper.httpProxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } else { httpClient.getHostConfiguration().setProxyHost(new ProxyHost(proxyHost)); } } // Use Rightscale's "whoami" service String whoamiUrl = WebProperties.getProperty(WebProperties.RIGHTSCALE_WHOAMI_URL, WebProperties.RIGHTSCALE_WHOAMI_URL_DEFAULT); GetMethod method = new GetMethod(whoamiUrl); Integer timeoutMs = new Integer(3 * 1000); // TODO: is this working? method.getParams().setSoTimeout(timeoutMs); try { httpClient.executeMethod(method); String str = ""; InputStream in = method.getResponseBodyAsStream(); byte[] readBytes = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(readBytes)) > 0) { str += new String(readBytes, 0, bytesRead); } Matcher matcher = Pattern.compile(".*your ip is (.*)").matcher(str); if (matcher.find()) { ipAddr = matcher.group(1); } } catch (MalformedURLException e) { LOG.warn("Malformed URL exception: " + e.getMessage()); LOG.debug(e, e); } catch (IOException e) { LOG.warn("I/O exception: " + e.getMessage()); LOG.debug(e, e); } finally { method.releaseConnection(); } return ipAddr; }