Examples of HttpClientBuilder


Examples of org.apache.http.impl.client.HttpClientBuilder

    private ApacheHttpClientToMockServerResponseMapper apacheHttpClientToMockServerResponseMapper = new ApacheHttpClientToMockServerResponseMapper();
    private CloseableHttpClient httpClient;

    public ApacheHttpClient(boolean isSecure) {
        try {
            HttpClientBuilder httpClientBuilder = HttpClients.custom().disableCookieManagement();
            if (isSecure) {
                httpClientBuilder
                        .setSslcontext(
                                SSLContexts
                                        .custom()
                                        .loadTrustMaterial(SSLFactory.getInstance().buildKeyStore(), trustStrategy)
                                        .build()
                        )
                        .setHostnameVerifier(new AllowAllHostnameVerifier());
            }

            // TODO(jamesdbloom) the section below if commented out as it is still experimental
//            System.getProperty("http.keepAlive", "false");
//            httpClientBuilder
//                    .setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
//                        public long getKeepAliveDuration(org.apache.http.HttpResponse response, HttpContext context) {
//                            return 0;
//                        }
//                    })
//                    .setDefaultRequestConfig(
//                            RequestConfig
//                                    .custom()
//                                    .setConnectionRequestTimeout(new Long(maxTimeout()).intValue())
//                                    .setConnectTimeout(new Long(maxTimeout()).intValue())
//                                    .build()
//                    )
//                    .setDefaultSocketConfig(
//                            SocketConfig
//                                    .custom()
//                                    .setSoTimeout((int) TimeUnit.SECONDS.toMillis(10))
//                                    .setSoLinger((int) TimeUnit.SECONDS.toMillis(10))
//                                    .setSoKeepAlive(true)
//                                    .build()
//                    );
            this.httpClient = httpClientBuilder.build();
        } catch (Exception e) {
            throw new RuntimeException("Exception creating http client", e);
        }
    }
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

        } catch (Exception e) {
            LOGGER.error("can't set TLS Support. Error is: {}", e, e);
        }

        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
                .setMaxConnPerRoute(metadata.getMaxConnectionsPerAddress())
                .setMaxConnTotal(metadata.getMaxConnectionsTotal())
                .setDefaultRequestConfig(requestConfig)
                .setKeepAliveStrategy(new InfraConnectionKeepAliveStrategy(metadata.getIdleTimeout()))
                .setSslcontext(sslContext);

        if (!followRedirects) {
            httpClientBuilder.disableRedirectHandling();
        }

        httpClient = httpClientBuilder.build();

        httpAsyncClient = HttpAsyncClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .setMaxConnPerRoute(metadata.getMaxConnectionsPerAddress())
                .setMaxConnTotal(metadata.getMaxConnectionsTotal())
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

  protected CloseableHttpClient createHttpClient(GoogleAnalyticsConfig config) {
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

    HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connManager);

    if (isNotEmpty(config.getUserAgent())) {
      builder.setUserAgent(config.getUserAgent());
    }

    if (isNotEmpty(config.getProxyHost())) {
      builder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort()));

      if (isNotEmpty(config.getProxyUserName())) {
        BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
        builder.setDefaultCredentialsProvider(credentialsProvider);
      }
    }

    return builder.build();
  }
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

  protected CloseableHttpClient createHttpClient(GoogleAnalyticsConfig config) {
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

    HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connManager);

    if (isNotEmpty(config.getUserAgent())) {
      builder.setUserAgent(config.getUserAgent());
    }

    if (isNotEmpty(config.getProxyHost())) {
      builder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort()));

      if (isNotEmpty(config.getProxyUserName())) {
        BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
        builder.setDefaultCredentialsProvider(credentialsProvider);
      }
    }

    return builder.build();
  }
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

                .setAsynchronousWorkersCore(1)
                .setRevalidationQueueSize(100)
                .setSharedCache(true)
                .build();

        final HttpClientBuilder clientBuilder = CachingHttpClientBuilder.create().setCacheConfig(cacheConfig);
        clientBuilder.setMaxConnTotal(1);
        clientBuilder.setMaxConnPerRoute(1);

        final RequestConfig config = RequestConfig.custom()
                .setSocketTimeout(10000)
                .setConnectTimeout(10000)
                .setConnectionRequestTimeout(1000)
                .build();

        clientBuilder.setDefaultRequestConfig(config);


        client = clientBuilder.build();
    }
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
        // http client can be configured from URI options
        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        // allow the builder pattern
        IntrospectionSupport.setProperties(clientBuilder, parameters, "httpClient.", true);
        // set the Request configure this way and allow the builder pattern
        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
        IntrospectionSupport.setProperties(requestConfigBuilder, parameters, "httpClient.", true);
        clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
       
        // validate that we could resolve all httpClient. parameters as this component is lenient
        validateParameters(uri, parameters, "httpClient.");
       
        // TODO cmueller: remove the "httpBindingRef" look up in Camel 3.0
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
        // http client can be configured from URI options
        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        // allow the builder pattern
        IntrospectionSupport.setProperties(clientBuilder, parameters, "httpClient.", true);
        // set the Request configure this way and allow the builder pattern
        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
        IntrospectionSupport.setProperties(requestConfigBuilder, parameters, "httpClient.", true);
        clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
       
        // validate that we could resolve all httpClient. parameters as this component is lenient
        validateParameters(uri, parameters, "httpClient.");
       
        // TODO cmueller: remove the "httpBindingRef" look up in Camel 3.0
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

  }

  @Test
  public void testGetRange() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    client.addInterceptorFirst(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        // Verify partial content response
        assertEquals(206, r.getStatusLine().getStatusCode());
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

  }

  @Test
  public void testBasicPreemptiveAuth() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    final CountDownLatch count = new CountDownLatch(1);
    client.setDefaultCredentialsProvider(new BasicCredentialsProvider()
    {
      @Override
      public Credentials getCredentials(AuthScope authscope)
      {
        // Set flag that credentials have been used indicating preemptive authentication
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

  }

  @Test
  public void testBasicPreemptiveAuthHeader() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    client.addInterceptorFirst(new HttpRequestInterceptor()
    {
      public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException
      {
        assertNotNull(r.getHeaders(HttpHeaders.AUTHORIZATION));
        assertEquals(1, r.getHeaders(HttpHeaders.AUTHORIZATION).length);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.