Example usage for org.apache.http.impl.client HttpClientBuilder build

List of usage examples for org.apache.http.impl.client HttpClientBuilder build

Introduction

In this page you can find the example usage for org.apache.http.impl.client HttpClientBuilder build.

Prototype

public CloseableHttpClient build() 

Source Link

Usage

From source file:ch.cyberduck.core.googledrive.DriveSession.java

@Override
protected Drive connect(final HostKeyCallback callback) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    this.transport = new ApacheHttpTransport(configuration.build());
    return new Drive.Builder(transport, json, new HttpRequestInitializer() {
        @Override/*from w w  w  . j a  va2  s  .  co m*/
        public void initialize(HttpRequest request) throws IOException {
            request.setSuppressUserAgentSuffix(true);
            // OAuth Bearer added in interceptor
        }
    }).setApplicationName(useragent.get()).build();
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testAndroidScopedBasicUsage() throws Exception {
    String browserLocation = this.baseURL + "browser";
    String valueLocation = this.baseURL + "value";
    LOGGER.debug("location: {}", browserLocation);
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient httpClient = httpClientBuilder.build();

    HttpContext httpContext = new BasicHttpContext();
    String androidCode = doGet(httpClient, httpContext, browserLocation);
    LOGGER.debug("result: {}", androidCode);
    String value = doGet(httpClient, httpContext, valueLocation);

    CookieStore cookieStore = (CookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
    cookieStore.clear();//from   w w  w  . j a v a 2s.  c o m

    String androidLocation = this.baseURL + "android?androidCode=" + androidCode;
    valueLocation += "?androidCode=" + androidCode;

    HttpClient androidHttpClient = httpClientBuilder.build();
    HttpContext androidHttpContext = new BasicHttpContext();

    String androidCode2 = doGet(androidHttpClient, androidHttpContext, androidLocation);
    LOGGER.debug("result 2: {}", androidCode2);
    String value2 = doGet(androidHttpClient, androidHttpContext, valueLocation);

    assertEquals(androidCode, androidCode2);
    assertEquals(value, value2);
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testWebBrowserSessionInvalidationCreatesNewAndroidScope() throws Exception {
    String webBrowserTestLocation = this.baseURL + "browser";
    String webBrowserValueLocation = this.baseURL + "value";
    String webBrowserInvalidateLocation = this.baseURL + "invalidate";

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient webBrowserHttpClient = httpClientBuilder.build();
    HttpContext webBrowserHttpContext = new BasicHttpContext();

    String webBrowserCode = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserTestLocation);
    String webBrowserValue = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserValueLocation);

    doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserInvalidateLocation);

    String webBrowserCode2 = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserTestLocation);
    String webBrowserValue2 = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserValueLocation);

    assertNotEquals(webBrowserCode, webBrowserCode2);
    assertNotEquals(webBrowserValue, webBrowserValue2);
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testAndroidSessionInvalidationInvalidatesAndroidSide() throws Exception {
    String webBrowserTestLocation = this.baseURL + "browser";
    String webBrowserInvalidateLocation = this.baseURL + "invalidate";

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient webBrowserHttpClient = httpClientBuilder.build();
    HttpContext webBrowserHttpContext = new BasicHttpContext();

    String webBrowserCode = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserTestLocation);

    doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserInvalidateLocation);

    String androidTestLocation = this.baseURL + "android?androidCode=" + webBrowserCode;

    HttpClient androidHttpClient = httpClientBuilder.build();
    HttpContext androidHttpContext = new BasicHttpContext();

    doGet(androidHttpClient, androidHttpContext, androidTestLocation,
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

From source file:org.ligoj.app.http.security.RestAuthenticationProvider.java

@Override
public Authentication authenticate(final Authentication authentication) {
    final String userpassword = StringUtils.defaultString(authentication.getCredentials().toString(), "");
    final String userName = StringUtils.lowerCase(authentication.getPrincipal().toString());

    // First get the cookie
    final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    clientBuilder.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build());
    final HttpPost httpPost = new HttpPost(getSsoPostUrl());

    // Do the POST
    try (CloseableHttpClient httpClient = clientBuilder.build()) {
        final String content = String.format(getSsoPostContent(), userName, userpassword);
        httpPost.setEntity(new StringEntity(content, StandardCharsets.UTF_8));
        httpPost.setHeader("Content-Type", "application/json");
        final HttpResponse httpResponse = httpClient.execute(httpPost);
        if (HttpStatus.SC_NO_CONTENT == httpResponse.getStatusLine().getStatusCode()) {
            // Succeed authentication, save the cookies data inside the authentication
            return newAuthentication(userName, userpassword, authentication, httpResponse);
        }//ww  w .ja  va2s.  c om
        log.info("Failed authentication of {}[{}] : {}", userName, userpassword.length(),
                httpResponse.getStatusLine().getStatusCode());
        httpResponse.getEntity().getContent().close();
    } catch (final IOException e) {
        log.warn("Remote SSO server is not available", e);
    }
    throw new BadCredentialsException("Invalid user or password");
}

From source file:org.scassandra.http.client.ActivityClient.java

private ActivityClient(String host, int port, int socketTimeout) {
    RequestConfig.Builder requestBuilder = RequestConfig.custom();
    requestBuilder = requestBuilder.setConnectTimeout(socketTimeout);
    requestBuilder = requestBuilder.setConnectionRequestTimeout(socketTimeout);
    requestBuilder = requestBuilder.setSocketTimeout(socketTimeout);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setDefaultRequestConfig(requestBuilder.build());
    httpClient = builder.build();
    this.connectionUrl = "http://" + host + ":" + port + "/connection";
    this.queryUrl = "http://" + host + ":" + port + "/query";
    this.preparedStatementExecutionUrl = "http://" + host + ":" + port + "/prepared-statement-execution";
    this.batchUrl = "http://" + host + ":" + port + "/batch-execution";
    this.preparedStatementPreparationUrl = "http://" + host + ":" + port + "/prepared-statement-preparation";
}

From source file:com.intuit.wasabi.export.rest.impl.DefaultRestDriver.java

private CloseableHttpClient createCloseableHttpClientWithProxy(final HttpClientBuilder httpClientBuilder,
        final String proxyHost, final Integer proxyPort) {
    HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(proxy);

    httpClientBuilder.setRoutePlanner(defaultProxyRoutePlanner);

    return httpClientBuilder.build();
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testAndroidSessionInvalidationKeepsResultForWebBrowser() throws Exception {
    String webBrowserTestLocation = this.baseURL + "browser";
    String webBrowserValueLocation = this.baseURL + "value";
    LOGGER.debug("location: {}", webBrowserTestLocation);
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient webBrowserHttpClient = httpClientBuilder.build();
    HttpContext webBrowserHttpContext = new BasicHttpContext();

    String webBrowserCode = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserTestLocation);
    LOGGER.debug("result: {}", webBrowserCode);
    String webBrowserValue = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserValueLocation);

    String androidLocation = this.baseURL + "android?androidCode=" + webBrowserCode;
    String androidValueLocation = webBrowserValueLocation + "?androidCode=" + webBrowserCode;
    String androidInvalidateLocation = this.baseURL + "invalidate?androidCode=" + webBrowserCode;

    HttpClient androidHttpClient = httpClientBuilder.build();
    HttpContext androidHttpContext = new BasicHttpContext();

    String androidCode = doGet(androidHttpClient, androidHttpContext, androidLocation);
    LOGGER.debug("result 2: {}", androidCode);
    String androidValue = doGet(androidHttpClient, androidHttpContext, androidValueLocation);

    assertEquals(webBrowserCode, androidCode);
    assertEquals(webBrowserValue, androidValue);

    doGet(androidHttpClient, androidHttpContext, androidInvalidateLocation);

    String webBrowserCode2 = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserTestLocation);
    String webBrowserValue2 = doGet(webBrowserHttpClient, webBrowserHttpContext, webBrowserValueLocation);

    assertEquals(webBrowserCode, webBrowserCode2);
    assertEquals(webBrowserValue, webBrowserValue2);
}