List of usage examples for org.apache.http.impl.conn ProxySelectorRoutePlanner ProxySelectorRoutePlanner
public ProxySelectorRoutePlanner(final SchemeRegistry schreg, final ProxySelector prosel)
From source file:org.github.oauth2.AccessTokenClient.java
/** * Execute request and return response// w w w. j ava2 s . c o m * * @param target * @param request * @return response * @throws IOException */ protected HttpResponse execute(HttpHost target, HttpRequest request) throws IOException { DefaultHttpClient client = new DefaultHttpClient(); client.setRoutePlanner(new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault())); return client.execute(target, request); }
From source file:com.gistlabs.mechanize.integration.test.Issue36Test.java
private AbstractHttpClient buildClient() { AbstractHttpClient result = MechanizeAgent.buildDefaultHttpClient(); System.setProperty("http.proxyHost", "127.0.0.1"); System.setProperty("http.proxyPort", "8888"); // HttpHost proxy = new HttpHost("localhost", 8080); // result.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( result.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); result.setRoutePlanner(routePlanner); return result; }
From source file:com.google.step2.http.DefaultHttpFetcher.java
public DefaultHttpFetcher() { // this follows redirects by default this.httpClient = new DefaultHttpClient(); // this means you can set a proxy through // java.net.ProxySelector.setDefault(), or by simply starting the // jvm with -Dhttp.proxyHost=foo.com -Dhttp.proxyPort=8080 httpClient.setRoutePlanner(/*ww w . j av a 2s . c o m*/ new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(), null)); }
From source file:org.kevinferrare.solarSystemDataRetriever.utils.HttpClientTool.java
public HttpClientTool() { ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpclient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpclient.setRoutePlanner(routePlanner); }
From source file:org.codegist.crest.io.http.HttpClientFactory.java
public static HttpClient create(CRestConfig crestConfig, Class<?> source) { HttpClient httpClient = crestConfig.get(source.getName() + HTTP_CLIENT); if (httpClient != null) { return httpClient; }/*w ww.j a v a 2 s . c om*/ int concurrencyLevel = crestConfig.getConcurrencyLevel(); if (concurrencyLevel > 1) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(concurrencyLevel)); ConnManagerParams.setMaxTotalConnections(params, concurrencyLevel); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), HTTPS_PORT)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(cm, params); } else { httpClient = new DefaultHttpClient(); } ((DefaultHttpClient) httpClient).setRoutePlanner(new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault())); return httpClient; }
From source file:org.xwiki.extension.repository.xwiki.internal.httpclient.DefaultHttpClientFactory.java
@Override public HttpClient createClient(String user, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.configuration.getUserAgent()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // Setup proxy ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); // Setup authentication if (user != null) { httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); }/*from w w w . j av a2 s . co m*/ return httpClient; }
From source file:net.orpiske.ssps.common.resource.HttpResourceExchange.java
/** * Default constructor: setups a default http client object and uses system * proxy information if available/*from ww w .j av a 2 s . c o m*/ */ public HttpResourceExchange() { ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); }
From source file:org.hbird.estcube.mibreader.Parser.java
public void parse() throws Exception { if (proxyHost != null) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else {//from w w w . j a v a 2s . com ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( client.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); client.setRoutePlanner(routePlanner); } HttpResponse response = client.execute(new HttpGet( "http://tudengisatelliit.ut.ee:8001/svn/MCS/trunk/eu.estcube.sdc/src/main/resources/commands.xml")); Pattern commandPattern = Pattern.compile("<command>(.*?)</command>"); Pattern commandNamePattern = Pattern.compile("<name>(.*?)</name>"); Pattern commandDecriptionPattern = Pattern.compile("<description>(.*?)</description>"); Pattern commandSystemPattern = Pattern.compile("<subsys>(.*?)</subsys>"); Pattern commandArgumentPattern = Pattern.compile( "<param><description>(.*?)</description><name>(.*?)</name><type little_endian=\"true\">(.*?)</type></param>"); if (response.getStatusLine().getStatusCode() == 200) { String text = readFully(response.getEntity().getContent()).replaceAll("(\\n|\\t|\\r)", ""); LOG.info("File length with comments=" + text.length()); /** Remove all comments */ text = text.replaceAll("<!--(.*?)-->", ""); LOG.info("File length without comments=" + text.length()); /** Turn the part list into something easier to use. */ Map<String, CommandableEntity> partsMap = new HashMap<String, CommandableEntity>(); for (CommandableEntity part : parts) { partsMap.put(part.getName(), part); } /** Parse the XML */ Matcher commandMatcher = commandPattern.matcher(text); while (commandMatcher.find()) { String commandDefintion = commandMatcher.group(1); Matcher nameMatcher = commandNamePattern.matcher(commandDefintion); nameMatcher.find(); String name = nameMatcher.group(1); Matcher descriptionMatcher = commandDecriptionPattern.matcher(commandDefintion); descriptionMatcher.find(); String description = descriptionMatcher.group(1); /** Create the command */ Command command = new Command(name, description); Matcher subsysMatcher = commandSystemPattern.matcher(commandDefintion); while (subsysMatcher.find()) { String subsys = subsysMatcher.group(1); if (partsMap.containsKey(subsys)) { LOG.info("Adding command '" + name + "' to part '" + subsys + "'."); partsMap.get(subsys).addCommand(command); } else { LOG.error("Found command for part '" + subsys + "'. Parts is unknown. Check the Spring XML assembly."); } } Matcher argumentMatcher = commandArgumentPattern.matcher(commandDefintion); while (argumentMatcher.find()) { String argumentDescription = argumentMatcher.group(1); String argumentName = argumentMatcher.group(2); String argumentType = argumentMatcher.group(3); Class<?> type = null; if (argumentType.contains("int")) { type = Integer.class; } else if (argumentType.contains("string")) { type = String.class; } else { LOG.error("Unknown type '" + argumentType + "'."); } LOG.info("Adding argument '" + argumentName + "' to command '" + name + "'."); command.addArgument(new CommandArgument(argumentName, argumentDescription, type, true)); } } } for (CommandableEntity part : parts) { LOG.info("Publishing satellite part (subsystem) '" + part.getName() + "'"); publisher.publish(part); } }
From source file:org.n52.oxf.util.web.ProxyAwareHttpClient.java
private ProxySelectorRoutePlanner createProxyPlanner() { DefaultHttpClient decoratedHttpClient = getHttpClientToDecorate(); ClientConnectionManager connectionManager = decoratedHttpClient.getConnectionManager(); SchemeRegistry schemeRegistry = connectionManager.getSchemeRegistry(); ProxySelector defaultProxySelector = ProxySelector.getDefault(); return new ProxySelectorRoutePlanner(schemeRegistry, defaultProxySelector); }
From source file:org.n52.sps.util.http.SimpleHttpClient.java
private void initProxyAwareClient() { ClientConnectionManager connectionManager = httpclient.getConnectionManager(); SchemeRegistry schemeRegistry = connectionManager.getSchemeRegistry(); ProxySelector defaultProxySelector = ProxySelector.getDefault(); ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(schemeRegistry, defaultProxySelector);/*from w w w .j a v a 2 s .c om*/ httpclient.setRoutePlanner(routePlanner); httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); }