Package org.apache.http

Examples of org.apache.http.HttpHost


        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(httpMessageConverters);

        // configure proxy
        if (Boolean.parseBoolean(System.getProperty("proxySet"))) {
            HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            HttpClient httpClient = HttpClients.custom().setRoutePlanner(defaultProxyRoutePlanner).build();
//            todo - need to support SOCKS protocol for this solution to work - jamesdbloom 12/01/2014
//            HttpClient httpClient = HttpClients.custom().setRoutePlanner(new SystemDefaultRoutePlanner(PROXY_SELECTOR.getDefault())).build();
            restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
View Full Code Here


        return objectMapper;
    }

    private HttpClient createHttpClient() {
        if (Boolean.parseBoolean(System.getProperty("proxySet"))) {
            HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            return HttpClients.custom().setRoutePlanner(defaultProxyRoutePlanner).build();
//            todo - need to support SOCKS protocol for this solution to work - jamesdbloom 12/01/2014
//            return HttpClients.custom().setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())).build();
        } else {
View Full Code Here

                .setSslcontext(SSLFactory.getInstance().sslContext())
                .setHostnameVerifier(new AllowAllHostnameVerifier());
        if (Boolean.parseBoolean(System.getProperty("defaultProxySet"))) {
            httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())).build();
        } else if (Boolean.parseBoolean(System.getProperty("proxySet"))) {
            HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            httpClientBuilder.setRoutePlanner(defaultProxyRoutePlanner).build();
        } else {
            HttpHost httpHost = new HttpHost("localhost", getProxyPort());
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            httpClientBuilder.setRoutePlanner(defaultProxyRoutePlanner);
        }
        return httpClientBuilder.build();
    }
View Full Code Here

        return false;
    }

    private String extractRedirectedUrl(String url, HttpContext localContext) {
        // This was triggered by HttpClient with the redirect count was exceeded.
        HttpHost host = (HttpHost)localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        HttpUriRequest finalRequest = (HttpUriRequest)localContext.getAttribute(ExecutionContext.HTTP_REQUEST);

        try {
            URL hostUrl = new URI(host.toURI()).toURL();
            return new URL(hostUrl, finalRequest.getURI().toString()).toExternalForm();
        } catch (MalformedURLException e) {
            LOGGER.warn("Invalid host/uri specified in final fetch: " + host + finalRequest.getURI());
            return url;
        } catch (URISyntaxException e) {
View Full Code Here

    */
   public String getCurrentURL()
   {
      HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(
               ExecutionContext.HTTP_REQUEST);
      HttpHost currentHost = (HttpHost) context.getAttribute(
               ExecutionContext.HTTP_TARGET_HOST);
      String currentUrl = currentHost.toURI() + currentReq.getURI();

      if (currentUrl.startsWith(baseUrl))
      {
         currentUrl = currentUrl.substring(baseUrl.length());
      }
View Full Code Here

   /**
    * Return the URL up to and including the host and port.
    */
   public String getHost()
   {
      HttpHost currentHost = (HttpHost) context.getAttribute(
               ExecutionContext.HTTP_TARGET_HOST);

      return currentHost.toURI();
   }
View Full Code Here

             * In case the proxy host is running multiple virtual servers, rewrite the Host header to ensure that we get
             * content from the correct virtual server
             */
            if (headerName.equalsIgnoreCase(HttpHeaders.HOST))
            {
               HttpHost host = URIUtils.extractHost(this.targetUriObj);
               headerValue = host.getHostName();
               if (host.getPort() != -1)
                  headerValue += ":" + host.getPort();
            }
            proxyRequest.addHeader(headerName, headerValue);
         }
      }
   }
View Full Code Here

  private static GooglePlayAPI service;

  private static HttpClient getProxiedHttpClient(String host, Integer port) throws Exception {
    HttpClient client = new DefaultHttpClient(GooglePlayAPI.getConnectionManager());
    client.getConnectionManager().getSchemeRegistry().register(Utils.getMockedScheme());
    HttpHost proxy = new HttpHost(host, port);
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    return client;
  }
View Full Code Here

    }

    private static HttpClient getProxiedHttpClient(String host, Integer port) throws Exception {
  HttpClient client = new DefaultHttpClient(GooglePlayAPI.getConnectionManager());
  client.getConnectionManager().getSchemeRegistry().register(Utils.getMockedScheme());
  HttpHost proxy = new HttpHost(host, port);
  client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
  return client;
    }
View Full Code Here

        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
        //params.setParameter(CoreProtocolPNames.USER_AGENT, settings.getHttpUserAgent());
        String proxys = settings.getHttpProxyServer();
        int port = settings.getHttpProxyPort();
        if (proxys != null && !proxys.equals("")) {
            HttpHost proxy;
            if (port > 0) {
                proxy = new HttpHost(settings.getHttpProxyServer(), settings.getHttpProxyPort());
            } else {
                proxy = new HttpHost(settings.getHttpProxyServer());
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        //TODO add support for SOCKS
View Full Code Here

TOP

Related Classes of org.apache.http.HttpHost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.