List of usage examples for org.apache.http.impl.conn DefaultProxyRoutePlanner DefaultProxyRoutePlanner
public DefaultProxyRoutePlanner(final HttpHost proxy)
From source file:org.apache.jmeter.protocol.http.proxy.NonGuiProxySample.java
public static void main(String[] args) throws IllegalUserActionException, IOException { JMeterUtils.setJMeterHome("./"); // Or wherever you put it. JMeterUtils.loadJMeterProperties(JMeterUtils.getJMeterBinDir() + "/jmeter.properties"); JMeterUtils.initLocale();// w w w . j ava2s . com TestPlan testPlan = new TestPlan(); ThreadGroup threadGroup = new ThreadGroup(); ListedHashTree testPlanTree = new ListedHashTree(); testPlanTree.add(testPlan); testPlanTree.add(threadGroup, testPlan); JMeterTreeModel treeModel = new JMeterTreeModel(new Object()); JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot(); treeModel.addSubTree(testPlanTree, root); ProxyControl proxy = new ProxyControl(); proxy.setNonGuiTreeModel(treeModel); proxy.setTarget(treeModel.getNodeOf(threadGroup)); proxy.setPort(8282); treeModel.addComponent(proxy, (JMeterTreeNode) root.getChildAt(1)); proxy.startProxy(); HttpHost proxyHost = new HttpHost("localhost", 8282); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); CloseableHttpClient httpclient = HttpClients.custom().setRoutePlanner(routePlanner).build(); try { httpclient.execute(new HttpGet("http://example.invalid")); } catch (Exception e) { // } proxy.stopProxy(); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { SaveService.saveTree(treeModel.getTestPlan(), out); out.close(); System.out.println(out.toString()); } }
From source file:io.uploader.drive.drive.largefile.HttpClientUtils.java
public static CloseableHttpClient getHttpClient(HasProxySettings proxySetting) { // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475 CloseableHttpClient httpclient = null; if (proxySetting != null && proxySetting.isActive()) { logger.info("Set the http proxy (" + proxySetting.getHost() + ":" + proxySetting.getPort() + ")"); CredentialsProvider credsProvider = Preconditions.checkNotNull(proxySetting.getCredentialsProvider()); HttpHost proxy = new HttpHost(proxySetting.getHost(), proxySetting.getPort()); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); httpclient = HttpClients.custom().setRoutePlanner(routePlanner) .setDefaultCredentialsProvider(credsProvider).build(); } else {// w ww . j a v a 2 s. c om httpclient = HttpClients.createDefault(); } return httpclient; }
From source file:network.ProxiedHttpClientAdaptor.java
public ProxiedHttpClientAdaptor(HttpHost proxy) { super();/* ww w . j ava2 s .co m*/ DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); this.httpclient = HttpClients.custom().setRoutePlanner(routePlanner).build(); }
From source file:lh.api.showcase.server.util.HttpClientUtils.java
public static CloseableHttpClient createHttpClient(HasProxySettings proxySetting, PoolingHttpClientConnectionManager connectionManager) { // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d5e475 HttpClientBuilder clientBuilder = HttpClients.custom(); if (proxySetting != null && proxySetting.isActive()) { logger.info("Set the http proxy (" + proxySetting.getHost() + ":" + proxySetting.getPort() + ")"); CredentialsProvider credsProvider = Preconditions.checkNotNull(proxySetting.getCredentialsProvider()); HttpHost proxy = new HttpHost(proxySetting.getHost(), proxySetting.getPort()); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); clientBuilder.setRoutePlanner(routePlanner).setDefaultCredentialsProvider(credsProvider); }/*from w w w. j a v a 2 s. com*/ if (connectionManager != null) { clientBuilder.setConnectionManager(connectionManager); } return clientBuilder.build(); }
From source file:network.ProxiedHttpClientAdaptor.java
public ProxiedHttpClientAdaptor(HttpHost proxy, String encode) { super(encode); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); this.httpclient = HttpClients.custom().setRoutePlanner(routePlanner).build(); }
From source file:com.facebook.presto.jdbc.QueryExecutor.java
private QueryExecutor(String userAgent, ObjectMapper mapper, HttpHost proxy) { checkNotNull(userAgent, "userAgent is null"); checkNotNull(mapper, "mapper is null"); this.userAgent = userAgent; this.mapper = mapper; HttpClientBuilder builder = HttpClients.custom(); HttpAsyncClientBuilder asyncBuilder = HttpAsyncClients.custom(); if (proxy != null) { DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); builder.setRoutePlanner(routePlanner); asyncBuilder.setRoutePlanner(routePlanner); }/* ww w . j a v a 2 s . c o m*/ this.httpClient = asyncBuilder.build(); this.httpClient.start(); }
From source file:com.fun.util.HttpClientUtil.java
private HttpClientUtil(String ip, String port) { if (StringUtils.isNotBlank(ip) && NumberUtils.isDigits(port)) { HttpHost proxy = new HttpHost(ip, Integer.parseInt(port)); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); this.client = this.setRoutePlanner(routePlanner).setMaxConnPerRoute(50).setMaxConnTotal(200).build(); return;/* w w w .j a v a 2 s. c o m*/ } connectionManager = new PoolingClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(50); connectionManager.setMaxTotal(200); this.client = new DefaultHttpClient(HttpClientUtil.connectionManager); }
From source file:com.yahoo.sql4d.sql4ddriver.DruidNodeAccessor.java
/** * To ensure customRouterPlanner is initialized only once. *//*from ww w . ja v a2 s .c o m*/ private static synchronized void proxyInit() { if (PROXY_HOST != null && customRouterPlanner == null) { HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT); customRouterPlanner = new DefaultProxyRoutePlanner(proxy); } }
From source file:com.respam.comniq.models.OMDBParser.java
public void requestOMDB(String movie, String year) { String imageURL;//from w ww . j a v a 2s .co m // Location for downloading and storing thumbnails String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output" + File.separator + "thumbnails"; File userOutDir = new File(path); // Create Thumbnails directory if not present if (userOutDir.mkdirs()) { System.out.println(userOutDir + " was created"); } // Connect to OMDB API and fetch details try { // Proxy details HttpHost proxy = new HttpHost("web-proxy.in.hpecorp.net", 8080, "http"); // HttpClient client = HttpClientBuilder.create().build(); // Start of proxy client DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient client = HttpClients.custom().setRoutePlanner(routePlanner).build(); // End of proxy client String uri = "http://www.omdbapi.com/?t=" + URLEncoder.encode(movie) + "&y=" + year; uri = uri.replace(" ", "%20"); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); String json = EntityUtils.toString(response.getEntity()); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(json); // Excluding Non Movies if (null != jsonObject.get("Title")) { movieInfo.add(jsonObject); // Download the thumbnails if Poster URL present if (null != jsonObject.get("Poster")) { imageURL = ((String) jsonObject.get("Poster")); System.out.println(imageURL); URL thumbnail = new URL(imageURL); ReadableByteChannel rbc = Channels.newChannel(thumbnail.openStream()); FileOutputStream fos = new FileOutputStream( path + File.separator + jsonObject.get("Title") + ".jpg"); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } } } catch (ParseException | IOException | UnsupportedOperationException e) { e.printStackTrace(); } }
From source file:org.dasein.cloud.utils.requester.AbstractDaseinRequestExecutor.java
protected HttpClientBuilder setProxyIfRequired(HttpClientBuilder httpClientBuilder) { if (this.httpProxyConfig != null) { HttpHost proxy = new HttpHost(httpProxyConfig.getHost(), httpProxyConfig.getPort()); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); httpClientBuilder.setRoutePlanner(routePlanner); }//from www . j a v a2s .c o m return httpClientBuilder; }