List of usage examples for org.apache.commons.httpclient ProxyHost ProxyHost
public ProxyHost(String paramString, int paramInt)
From source file:com.pureinfo.force.net.impl.HttpUtilImpl.java
public HttpUtilImpl(String _sProxyHost, int _nProxyPort, String _sUser, String _sPassword) { m_proxyHost = new ProxyHost(_sProxyHost, _nProxyPort); m_sProxyUser = _sUser;/*from ww w. j a va 2s. co m*/ m_sProxyPassword = _sPassword; }
From source file:de.escidoc.core.test.examples.RetrieveCompressedExamplesIT.java
@Test public void testRetrieveCompressedExampleOrganizationalUnits() throws Exception { for (int i = 0; i < EXAMPLE_OU_IDS.length; ++i) { String ou = handleXmlResult(ouClient.retrieve(EXAMPLE_OU_IDS[i])); String response = null;// w w w .ja va 2 s . c om String url = "http://localhost:8080" + Constants.ORGANIZATIONAL_UNIT_BASE_URI + "/" + EXAMPLE_OU_IDS[i]; HttpClient client = new HttpClient(); try { if (PropertiesProvider.getInstance().getProperty("http.proxyHost") != null && PropertiesProvider.getInstance().getProperty("http.proxyPort") != null) { ProxyHost proxyHost = new ProxyHost( PropertiesProvider.getInstance().getProperty("http.proxyHost"), Integer.parseInt(PropertiesProvider.getInstance().getProperty("http.proxyPort"))); client.getHostConfiguration().setProxyHost(proxyHost); } } catch (final Exception e) { throw new RuntimeException("[ClientBase] Error occured loading properties! " + e.getMessage(), e); } GetMethod getMethod = new GetMethod(url); getMethod.setRequestHeader("Accept-Encoding", "gzip"); InputStream responseBody = null; try { int statusCode = client.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { throw new RuntimeException("getMethod failed:" + getMethod.getStatusLine()); } responseBody = new GZIPInputStream(getMethod.getResponseBodyAsStream()); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(responseBody, getMethod.getResponseCharSet())); StringBuffer result = new StringBuffer(); char[] buffer = new char[4 * 1024]; int charsRead; while ((charsRead = bufferedReader.read(buffer)) != -1) { result.append(buffer, 0, charsRead); } response = result.toString(); } catch (Exception e) { throw new RuntimeException("Error occured in retrieving compressed example! " + e.getMessage(), e); } assertXmlEquals("Compressed document not the same like the uncompressed one", ou, response); } }
From source file:com.dragoniade.deviantart.favorites.FavoritesDownloader.java
public void setProxy(ProxyCfg prx) { HostConfiguration hostConfiguration = client.getHostConfiguration(); if (prx != null) { ProxyHost proxyHost = new ProxyHost(prx.getHost(), prx.getPort()); hostConfiguration.setProxyHost(proxyHost); if (prx.getUsername() != null) { UsernamePasswordCredentials upCred = new UsernamePasswordCredentials(prx.getUsername(), prx.getPassword());/*from www . j a va 2s .c om*/ client.getState().setProxyCredentials(AuthScope.ANY, upCred); } else { client.getState().clearProxyCredentials(); } } else { hostConfiguration.setProxyHost(null); client.getState().clearProxyCredentials(); } }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Create the {@link HttpClient} object/* w w w .j a v a2 s . c om*/ */ private void createClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(TIMEOUT_MS); params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS); params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); configureCredentials(); if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) { log.debug("A HTTP Proxy is configured"); System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = chooseProxy(); if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) { // convert the socket address to an ProxyHost final InetSocketAddress isa = (InetSocketAddress) proxy.address(); // assume default scheme (http) ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort()); httpClient.getHostConfiguration().setProxyHost(proxyHost); if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) { String user = System.getProperty("http.proxyUser"); String password = System.getProperty("http.proxyPassword"); httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()), new UsernamePasswordCredentials(user, password)); } } } }
From source file:com.fatwire.dta.sscrawler.App.java
protected void doWork(final CommandLine cmd) throws Exception { final Crawler crawler = new Crawler(); URI startUri = null;/*from w w w. j av a2 s . com*/ startUri = URI.create(cmd.getArgs()[1]); if (cmd.hasOption('m')) { crawler.setMaxPages(Integer.parseInt(cmd.getOptionValue('m'))); } final int threads = Integer.parseInt(cmd.getOptionValue('t', "5")); if (startUri == null) { throw new IllegalArgumentException("startUri is not set"); } final int t = startUri.toASCIIString().indexOf("/ContentServer"); if (t == -1) { throw new IllegalArgumentException("/ContentServer is not found on the startUri."); } crawler.setStartUri(new URI(null, null, null, -1, startUri.getRawPath(), startUri.getRawQuery(), startUri.getFragment())); final HostConfig hc = createHostConfig(URI.create(startUri.toASCIIString().substring(0, t))); final String proxyUsername = cmd.getOptionValue("pu"); final String proxyPassword = cmd.getOptionValue("pw"); final String proxyHost = cmd.getOptionValue("ph"); final int proxyPort = Integer.parseInt(cmd.getOptionValue("", "8080")); if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyUsername)) { hc.setProxyCredentials(new UsernamePasswordCredentials(proxyUsername, proxyPassword)); } if (StringUtils.isNotBlank(proxyHost)) { hc.setProxyHost(new ProxyHost(proxyHost, proxyPort)); } else if (StringUtils.isNotBlank(System.getProperty("http.proxyhost")) && StringUtils.isNotBlank(System.getProperty("http.proxyport"))) { hc.setProxyHost(new ProxyHost(System.getProperty("http.proxyhost"), Integer.parseInt(System.getProperty("http.proxyport")))); } crawler.setHostConfig(hc); SSUriHelper helper = null; if (cmd.hasOption('f')) { final UriHelperFactory f = (UriHelperFactory) Class.forName(cmd.getOptionValue('f')).newInstance(); helper = f.create(crawler.getStartUri().getPath()); } else { helper = new SSUriHelper(crawler.getStartUri().getPath()); } final ThreadPoolExecutor readerPool = new RenderingThreadPool(threads); final MBeanServer platform = java.lang.management.ManagementFactory.getPlatformMBeanServer(); try { platform.registerMBean(readerPool, new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } crawler.setExecutor(readerPool); File path = null; if (cmd.hasOption('d')) { path = new File(cmd.getOptionValue("d")); } else { path = getOutputDir(); } if (path != null) { final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmm"); path = new File(path, df.format(new Date())); path.mkdirs(); } crawler.setReporters(createReporters(path, helper)); crawler.setUriHelper(helper); try { crawler.work(); } finally { readerPool.shutdown(); try { platform.unregisterMBean(new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } } }
From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java
public static ProxyHost getUseProxyServer(String useProxyServer) { ProxyHost proxyHost = null;//from www . ja va 2 s . com if (useProxyServer != null) { String proxyHostStr = useProxyServer; int colonIdx = proxyHostStr.indexOf(':'); if (colonIdx != -1) { proxyHostStr = proxyHostStr.substring(0, colonIdx); String proxyPortStr = useProxyServer.substring(colonIdx + 1); if (proxyPortStr != null && proxyPortStr.length() > 0 && proxyPortStr.matches("[0-9]+")) { int proxyPort = Integer.parseInt(proxyPortStr); proxyHost = new ProxyHost(proxyHostStr, proxyPort); } else { proxyHost = new ProxyHost(proxyHostStr); } } else { proxyHost = new ProxyHost(proxyHostStr); } } return proxyHost; }
From source file:com.sun.jersey.client.apache.DefaultApacheHttpMethodExecutor.java
private HostConfiguration getHostConfiguration(HttpClient client, Map<String, Object> props) { Object proxy = props.get(ApacheHttpClientConfig.PROPERTY_PROXY_URI); if (proxy != null) { URI proxyUri = getProxyUri(proxy); String proxyHost = proxyUri.getHost(); if (proxyHost == null) { proxyHost = "localhost"; }/*from w w w.j a v a 2s .co m*/ int proxyPort = proxyUri.getPort(); if (proxyPort == -1) { proxyPort = 8080; } HostConfiguration hostConfig = new HostConfiguration(client.getHostConfiguration()); String setHost = hostConfig.getProxyHost(); int setPort = hostConfig.getProxyPort(); if ((setHost == null) || (!setHost.equals(proxyHost)) || (setPort == -1) || (setPort != proxyPort)) { hostConfig.setProxyHost(new ProxyHost(proxyHost, proxyPort)); } return hostConfig; } else { return null; } }
From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java
private ProxyHost getProxyHost() { ProxyHost theProxyHost = null;/*from www . j ava 2s.c o m*/ ProxySelector ps = ProxySelector.getDefault(); List<Proxy> p = null; // select the proxy for the URI of this repository try { if (ps != null) { // log.info( "Getting Proxy List." ); p = ps.select(new java.net.URI(this.servletURL)); } } catch (Exception e) { // log.warn( "Exception getting proxy: " + e.toString() ); } if (p == null) { // log.warn( "No proxy information available." ); } else { // log.info( "Received proxy list: " + p.toString() ); Iterator<Proxy> proxies = p.iterator(); // just take the first for now if (proxies != null && proxies.hasNext()) { Proxy theProxy = (Proxy) proxies.next(); // log.info( "Proxy set to: " + theProxy.toString() ); if (!Proxy.NO_PROXY.equals(theProxy)) { InetSocketAddress theSock = (InetSocketAddress) theProxy.address(); theProxyHost = new ProxyHost(theSock.getHostName(), theSock.getPort()); } } else { // log.warn( "Proxy list has zero members." ); } } return theProxyHost; }
From source file:com.kaltura.client.KalturaClientBase.java
protected HttpClient createHttpClient() { HttpClient client = new HttpClient(); // added by Unicon to handle proxy hosts String proxyHost = System.getProperty("http.proxyHost"); if (proxyHost != null) { int proxyPort = -1; String proxyPortStr = System.getProperty("http.proxyPort"); if (proxyPortStr != null) { try { proxyPort = Integer.parseInt(proxyPortStr); } catch (NumberFormatException e) { if (logger.isEnabled()) logger.warn("Invalid number for system property http.proxyPort (" + proxyPortStr + "), using default port instead"); }//from w w w . ja v a2s .c om } ProxyHost proxy = new ProxyHost(proxyHost, proxyPort); client.getHostConfiguration().setProxyHost(proxy); } // added by Unicon to force encoding to UTF-8 client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8_CHARSET); client.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, UTF8_CHARSET); client.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, UTF8_CHARSET); HttpConnectionManagerParams connParams = client.getHttpConnectionManager().getParams(); if (this.kalturaConfiguration.getTimeout() != 0) { connParams.setSoTimeout(this.kalturaConfiguration.getTimeout()); connParams.setConnectionTimeout(this.kalturaConfiguration.getTimeout()); } client.getHttpConnectionManager().setParams(connParams); return client; }
From source file:com.borhan.client.BorhanClientBase.java
protected HttpClient createHttpClient() { HttpClient client = new HttpClient(); // added by Unicon to handle proxy hosts String proxyHost = System.getProperty("http.proxyHost"); if (proxyHost != null) { int proxyPort = -1; String proxyPortStr = System.getProperty("http.proxyPort"); if (proxyPortStr != null) { try { proxyPort = Integer.parseInt(proxyPortStr); } catch (NumberFormatException e) { if (logger.isEnabled()) logger.warn("Invalid number for system property http.proxyPort (" + proxyPortStr + "), using default port instead"); }//from www. j a v a 2s . co m } ProxyHost proxy = new ProxyHost(proxyHost, proxyPort); client.getHostConfiguration().setProxyHost(proxy); } // added by Unicon to force encoding to UTF-8 client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8_CHARSET); client.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, UTF8_CHARSET); client.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, UTF8_CHARSET); HttpConnectionManagerParams connParams = client.getHttpConnectionManager().getParams(); if (this.borhanConfiguration.getTimeout() != 0) { connParams.setSoTimeout(this.borhanConfiguration.getTimeout()); connParams.setConnectionTimeout(this.borhanConfiguration.getTimeout()); } client.getHttpConnectionManager().setParams(connParams); return client; }