List of usage examples for org.apache.http.impl.client HttpClientBuilder build
public CloseableHttpClient build()
From source file:com.cisco.cta.taxii.adapter.httpclient.HttpClientFactory.java
public HttpClient create() { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); if (proxySettings.getUrl() != null) { URL proxyUrl = proxySettings.getUrl(); HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol()); clientBuilder.setProxy(proxyHost); }// ww w . j a v a2 s . c o m return clientBuilder.build(); }
From source file:cn.org.once.cstack.utils.JSONClient.java
public CloseableHttpClient buildSecureHttpClient() throws IOException { if (isUnixSocket) { HttpClientConnectionManager manager = new PoolingHttpClientConnectionManager( getUnixSocketFactoryRegistry()); HttpClientBuilder builder = HttpClients.custom(); builder.setConnectionManager(manager); return builder.build(); } else if (certPathDirectory != null && !certPathDirectory.isEmpty()) { org.apache.http.impl.client.HttpClientBuilder builder = HttpClients.custom(); HttpClientConnectionManager manager = getConnectionFactory(this.certPathDirectory, 10); builder.setConnectionManager(manager); return builder.build(); } else {/* w ww. j a v a 2 s.c o m*/ return HttpClients.createDefault(); } }
From source file:eu.fusepool.p3.webid.proxy.ProxyServlet.java
/** * Initializes the servlet by setting up the HTTP-client. *//*from w w w. ja v a 2s . c om*/ public ProxyServlet() { final HttpClientBuilder hcb = HttpClientBuilder.create(); hcb.setRedirectStrategy(new NeverRedirectStrategy()); httpclient = hcb.build(); targetBaseUri = null; }
From source file:org.ligoj.app.http.security.DigestAuthenticationFilter.java
@Override public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) { final String token = request.getParameter("token"); if (token != null) { // Token is the last part of URL // First get the cookie final HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.setDefaultRequestConfig( RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()); // Do the POST try (CloseableHttpClient httpClient = clientBuilder.build()) { final HttpPost httpPost = new HttpPost(getSsoPostUrl()); httpPost.setEntity(new StringEntity(token, StandardCharsets.UTF_8.name())); httpPost.setHeader("Content-Type", "application/json"); final HttpResponse httpResponse = httpClient.execute(httpPost); if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) { return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken( EntityUtils.toString(httpResponse.getEntity()), "N/A", new ArrayList<>())); }//from w ww .j av a2 s. c om } catch (final IOException e) { log.warn("Local SSO server is not available", e); } } throw new BadCredentialsException("Invalid user or password"); }
From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java
@Test public void testNonExistingAndroidCodeFails() throws Exception { String valueLocation = this.baseURL + "value?androidCode=" + "foobar"; HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); HttpClient httpClient = httpClientBuilder.build(); HttpContext httpContext = new BasicHttpContext(); doGet(httpClient, httpContext, valueLocation, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }
From source file:com.mirth.connect.plugins.httpauth.oauth2.OAuth2Authenticator.java
@Override public AuthenticationResult authenticate(RequestInfo request) throws Exception { OAuth2HttpAuthProperties properties = getReplacedProperties(request); CloseableHttpClient client = null;/*from ww w. j av a 2 s .c o m*/ CloseableHttpResponse response = null; try { // Create and configure the client and context RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()); ConnectorPluginProperties pluginProperties = null; if (CollectionUtils.isNotEmpty(properties.getConnectorPluginProperties())) { pluginProperties = properties.getConnectorPluginProperties().iterator().next(); } provider.getHttpConfiguration().configureSocketFactoryRegistry(pluginProperties, socketFactoryRegistry); BasicHttpClientConnectionManager httpClientConnectionManager = new BasicHttpClientConnectionManager( socketFactoryRegistry.build()); httpClientConnectionManager.setSocketConfig(SocketConfig.custom().setSoTimeout(SOCKET_TIMEOUT).build()); HttpClientBuilder clientBuilder = HttpClients.custom() .setConnectionManager(httpClientConnectionManager); HttpUtil.configureClientBuilder(clientBuilder); client = clientBuilder.build(); HttpClientContext context = HttpClientContext.create(); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(SOCKET_TIMEOUT) .setSocketTimeout(SOCKET_TIMEOUT).setStaleConnectionCheckEnabled(true).build(); context.setRequestConfig(requestConfig); URIBuilder uriBuilder = new URIBuilder(properties.getVerificationURL()); // Add query parameters if (properties.getTokenLocation() == TokenLocation.QUERY) { List<String> paramList = request.getQueryParameters().get(properties.getLocationKey()); if (CollectionUtils.isNotEmpty(paramList)) { for (String value : paramList) { uriBuilder.addParameter(properties.getLocationKey(), value); } } } // Build the final URI and create a GET request HttpGet httpGet = new HttpGet(uriBuilder.build()); // Add headers if (properties.getTokenLocation() == TokenLocation.HEADER) { List<String> headerList = request.getHeaders().get(properties.getLocationKey()); if (CollectionUtils.isNotEmpty(headerList)) { for (String value : headerList) { httpGet.addHeader(properties.getLocationKey(), value); } } } // Execute the request response = client.execute(httpGet, context); // Determine authentication from the status code if (response.getStatusLine().getStatusCode() < 400) { return AuthenticationResult.Success(); } else { return AuthenticationResult.Failure(); } } finally { HttpClientUtils.closeQuietly(response); HttpClientUtils.closeQuietly(client); } }
From source file:org.mitre.stixwebtools.services.TaxiiService.java
/** * Creates a new HttpClient which is needed to make requests from a taxii server. * // www .j a v a2s. co m * @param proxyUrl * @param proxyPort * @return */ public HttpClient getTaxiiClient(String proxyUrl, int proxyPort) { //We have to make our own CloseableHttpClient so we can use a proxy HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost(proxyUrl, proxyPort)); CloseableHttpClient client = clientBuilder.build(); HttpClient httpClient = new HttpClient(client); return httpClient; }
From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java
@Test public void testAndroidScoped() 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); String androidCode2 = doGet(httpClient, httpContext, browserLocation); LOGGER.debug("result 2: {}", androidCode2); String value2 = doGet(httpClient, httpContext, valueLocation); assertEquals(androidCode, androidCode2); assertEquals(value, value2);/*from w w w . jav a2 s . c om*/ }
From source file:io.fabric8.kit.build.service.docker.access.hc.util.AbstractNativeClientBuilder.java
@Override public CloseableHttpClient buildPooledClient() { final HttpClientBuilder httpBuilder = HttpClients.custom(); final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry, dnsResolver);// w w w .jav a 2 s .com manager.setDefaultMaxPerRoute(maxConnections); httpBuilder.setConnectionManager(manager); return httpBuilder.build(); }
From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java
@Test public void testAndroidScopedNewSessionIsNewAndroidScope() 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 av a 2s . c o m*/ String androidCode2 = doGet(httpClient, httpContext, browserLocation); LOGGER.debug("result 2: {}", androidCode2); String value2 = doGet(httpClient, httpContext, valueLocation); assertNotEquals(androidCode, androidCode2); assertNotEquals(value, value2); }