Package org.apache.http.impl.client

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


          .setStaleConnectionCheckEnabled(true)
          .setExpectContinueEnabled(false)
          .setConnectTimeout(connectionTimeout)
          .setConnectionRequestTimeout(socketTimeout);

      HttpClientBuilder builder = HttpClients.custom()
        .setConnectionManager(connectionManager)
        .setMaxConnTotal(1)
        .disableAutomaticRetries()
        .setDefaultRequestConfig(requestBuilder.build())
        .setDefaultSocketConfig(SocketConfig.custom()
          .setTcpNoDelay(true)
          .setSoTimeout(socketTimeout)
          .build())
        .setDefaultCredentialsProvider(credentialsProvider);
      if (myFactory != null)
        builder.setSSLSocketFactory(myFactory);
      builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout))
        .setRedirectStrategy(new DefaultRedirectStrategy());
      httpClient = builder.build();
     
      proxy = new SPSProxyHelper( serverUrl, encodedServerLocation, serverLocation, serverUserName, password,
        org.apache.manifoldcf.core.common.CommonsHTTPSender.class, "client-config.wsdd",
        httpClient, isClaimSpace );
     
View Full Code Here


          .setStaleConnectionCheckEnabled(true)
          .setExpectContinueEnabled(false)
          .setConnectTimeout(connectionTimeout)
          .setConnectionRequestTimeout(socketTimeout);

      HttpClientBuilder builder = HttpClients.custom()
        .setConnectionManager(connectionManager)
        .setMaxConnTotal(1)
        .disableAutomaticRetries()
        .setDefaultRequestConfig(requestBuilder.build())
        .setDefaultSocketConfig(SocketConfig.custom()
          .setTcpNoDelay(true)
          .setSoTimeout(socketTimeout)
          .build())
        .setDefaultCredentialsProvider(credentialsProvider);
      if (myFactory != null)
        builder.setSSLSocketFactory(myFactory);
      builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout))
        .setRedirectStrategy(new DefaultRedirectStrategy());
      httpClient = builder.build();

      proxy = new SPSProxyHelper( serverUrl, encodedServerLocation, serverLocation, userName, password,
        org.apache.manifoldcf.core.common.CommonsHTTPSender.class, "client-config.wsdd",
        httpClient );
     
View Full Code Here

            if (conman == null) {
                conman = new PoolingHttpClientConnectionManager();
                conman.setDefaultMaxPerRoute(maxConnections);
                conman.setMaxTotal(Math.max(conman.getMaxTotal(), maxConnections));
            }
            HttpClientBuilder builder = HttpClientBuilder.create()
                    .disableCookieManagement()
                    .setConnectionManager(conman);
            builder.useSystemProperties();
            // TODO: use setDefaultHeaders for adding requestHeaders? It's a bit painful
            // because we need to convert it to a Collection of Header objects.

            // config code for older version of httpclient.
//            builder.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(socketTimeout).build());
//            HttpParams params = client.getParams();
//            params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout);
//            params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout);
            // setup request/response intercepter for handling gzip-compressed response.
            // Disabled because httpclient 4.3.3 sends "Accept-Encoding: gzip,deflate" by
            // default. Response parsing will fail If gzip-decompression ResponseInterceptor
            // is installed.
            builder.addInterceptorLast(new HttpRequestInterceptor() {
                @Override
                public void process(final HttpRequest request, final HttpContext context) {
//                    System.err.println("RequestInterceptor");
//                    if (request.containsHeader("Accept-Encoding")) {
//                        System.err.println("already has Accept-Encoding: " + request.getHeaders("Accept-Encoding")[0]);
//                    }
//                    if (gzipAccepted) {
//                        if (!request.containsHeader("Accept-Encoding")) {
//                            request.addHeader("Accept-Encoding", "gzip");
//                        }
//                    }
                    // add extra headers configured.
                    if (requestHeaders != null) {
                        for (Entry<String, String> ent : requestHeaders.entrySet()) {
                            request.addHeader(ent.getKey(), ent.getValue());
                        }
                    }
                }
            });
//            builder.addInterceptorFirst(new HttpResponseInterceptor() {
//                @Override
//                public void process(final HttpResponse response, final HttpContext context)
//                        throws HttpException, IOException {
//                    HttpEntity entity = response.getEntity();
//                    Header ceheader = entity.getContentEncoding();
//                    if (ceheader != null && contains(ceheader.getElements(), "gzip")) {
//                        response.setEntity(new GzipInflatingHttpEntityWrapper(response.getEntity()));
//                    }
//                }
//            });
            this.client = builder.build();
        }
        return client;
    }
View Full Code Here

          .setStaleConnectionCheckEnabled(true)
          .setExpectContinueEnabled(false)
          .setConnectTimeout(connectionTimeout)
          .setConnectionRequestTimeout(socketTimeout);

      HttpClientBuilder builder = HttpClients.custom()
        .setConnectionManager(connectionManager)
        .setMaxConnTotal(1)
        .disableAutomaticRetries()
        .setDefaultRequestConfig(requestBuilder.build())
        .setDefaultSocketConfig(SocketConfig.custom()
          .setTcpNoDelay(true)
          .setSoTimeout(socketTimeout)
          .build())
        .setDefaultCredentialsProvider(credentialsProvider);
      if (myFactory != null)
        builder.setSSLSocketFactory(myFactory);
      builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout))
        .setRedirectStrategy(new DefaultRedirectStrategy());
      httpClient = builder.build();

      proxy = new SPSProxyHelper( serverUrl, encodedServerLocation, serverLocation, userName, password,
        org.apache.manifoldcf.core.common.CommonsHTTPSender.class, "client-config.wsdd",
        httpClient );
     
View Full Code Here

      {
        credentialsProvider.setCredentials(AuthScope.ANY,
          new NTCredentials(ingestNtlmUsername,ingestNtlmPassword,currentHost,ingestNtlmDomain));
      }

      HttpClientBuilder builder = HttpClients.custom()
        .setConnectionManager(connectionManager)
        .setMaxConnTotal(1)
        .disableAutomaticRetries()
        .setDefaultRequestConfig(RequestConfig.custom()
          .setCircularRedirectsAllowed(true)
          .setSocketTimeout(socketTimeout)
          .setStaleConnectionCheckEnabled(true)
          .setExpectContinueEnabled(true)
          .setConnectTimeout(connectionTimeout)
          .setConnectionRequestTimeout(socketTimeout)
          .build())
        .setDefaultSocketConfig(SocketConfig.custom()
          .setTcpNoDelay(true)
          .setSoTimeout(socketTimeout)
          .build())
        .setDefaultCredentialsProvider(credentialsProvider)
        .setRequestExecutor(new HttpRequestExecutor(socketTimeout))
        .setRedirectStrategy(new DefaultRedirectStrategy());

      if (myFactory != null)
        builder.setSSLSocketFactory(myFactory);
     
      httpClient = builder.build();

      // System.out.println("Connection server object = "+llServer.toString());

      // Establish the actual connection
      int sanityRetryCount = FAILURE_RETRY_COUNT;
View Full Code Here

  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

  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

      return softwareManagerCollector.getSoftwareManager(appManager);
   }

   private boolean validateLocalRepoURL(String localRepoURL) {
      boolean succ = true;
      HttpClientBuilder builder = HttpClientBuilder.create();
      CloseableHttpClient httpClient = builder.build();

      // test the connection to the given url
      try {
         HttpGet httpGet = new HttpGet(localRepoURL);
         HttpResponse resp = httpClient.execute(httpGet);
View Full Code Here

            builder.register("https", getSslFactory());
            Registry<ConnectionSocketFactory> registry = builder.build();

            HttpClientConnectionManager hccm = createClientConnectionManager(registry);

            HttpClientBuilder clientBuilder = HttpClients.custom();
            clientBuilder.setDefaultRequestConfig(requestBuilder.build());
            clientBuilder.setDefaultConnectionConfig(connBuilder.build());
            clientBuilder.setConnectionManager(hccm);

            client = clientBuilder.build();
        }

        return client;
    }
View Full Code Here

            get.releaseConnection();
        }
    }
   
    private HttpClient createHttpClient() {
        HttpClientBuilder clientBuilder = HttpClientBuilder.create()
                .setConnectionManager(createConnectionManager())
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setConnectionRequestTimeout(graphiteConnectionRequestTimeout)
                        .setConnectTimeout(graphiteConnectTimeout)
                        .setSocketTimeout(graphiteSocketTimeout)
                        .build());
       
        // Set auth header for graphite if username and password are provided
        if (!StringUtils.isEmpty(graphiteUsername) && !StringUtils.isEmpty(graphitePassword)) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(
                    new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                    new UsernamePasswordCredentials(graphiteUsername, graphitePassword));
            clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            context.setAttribute("preemptive-auth", new BasicScheme());
            clientBuilder.addInterceptorFirst(new PreemptiveAuth());
        }
       
        return clientBuilder.build();
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.HttpClientBuilder

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.