List of usage examples for org.apache.http.impl.client HttpClients custom
public static HttpClientBuilder custom()
From source file:org.jmonkey.external.bintray.BintrayApiClient.java
private CloseableHttpClient createAuthenticatedClient() { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.getUser(), config.getApiKey())); return HttpClients.custom().setDefaultCookieStore(new BasicCookieStore()).setUserAgent(userAgent) .setRedirectStrategy(new LaxRedirectStrategy()).setDefaultCredentialsProvider(credentialsProvider) .build();//from ww w. ja va 2 s. co m }
From source file:de.micromata.genome.tpsb.httpClient.HttpClientTestBuilder.java
public HttpClientTestBuilder createHttpClient() { PoolingHttpClientConnectionManager conManager = new PoolingHttpClientConnectionManager(); conManager.setMaxTotal(maxTotalConnection); conManager.setDefaultMaxPerRoute(maxPerHostConnection); final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeout) .setSocketTimeout(readTimeout).build(); final HttpClientBuilder httpClientBuilder = HttpClients.custom().setConnectionManager(conManager) // .setDefaultRequestConfig(requestConfig); httpClient = httpClientBuilder.build(); return getBuilder(); }
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);//from ww w.ja va2 s. c o m manager.setDefaultMaxPerRoute(maxConnections); httpBuilder.setConnectionManager(manager); return httpBuilder.build(); }
From source file:dal.arris.RequestArrisAlter.java
public RequestArrisAlter(Integer deviceId, Autenticacao autenticacao, String frequency) throws UnsupportedEncodingException, IOException { Autenticacao a = AuthFactory.getEnd(); String auth = a.getUser() + ":" + a.getPassword(); String url = a.getLink() + "capability/execute?capability=" + URLEncoder.encode("\"getLanWiFiInfo\"", "UTF-8") + "&deviceId=" + deviceId + "&input=" + URLEncoder.encode(frequency, "UTF-8"); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(1);/*from ww w . ja va 2 s. c om*/ cm.setDefaultMaxPerRoute(1); HttpHost localhost = new HttpHost("10.200.6.150", 80); cm.setMaxPerRoute(new HttpRoute(localhost), 50); // Cookies RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build(); CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm) .setDefaultRequestConfig(globalConfig).build(); byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8"))); String authHeader = "Basic " + new String(encodedAuth); // CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpGet httpget = new HttpGet(url); httpget.setHeader(HttpHeaders.AUTHORIZATION, authHeader); httpget.setHeader(HttpHeaders.CONTENT_TYPE, "text/html"); httpget.setHeader("Cookie", "JSESSIONID=aaazqNDcHoduPbavRvVUv; AX-CARE-AGENTS-20480=HECDMIAKJABP"); RequestConfig localConfig = RequestConfig.copy(globalConfig).setCookieSpec(CookieSpecs.STANDARD_STRICT) .build(); HttpGet httpGet = new HttpGet("/"); httpGet.setConfig(localConfig); // httpget.setHeader(n); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); for (Header allHeader : response.getAllHeaders()) { System.out.println("Nome: " + allHeader.getName() + " Valor: " + allHeader.getValue()); } } } finally { httpclient.close(); } httpclient.close(); }
From source file:jobhunter.api.infojobs.Client.java
public <T> Optional<T> get(Class<T> clazz, String url) throws InfoJobsAPIException { HttpGet httpGet = new HttpGet(url); try (CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build()) { try (CloseableHttpResponse response = client.execute(httpGet)) { if (response.getStatusLine().getStatusCode() == 200) { T entity = mapper.readValue(response.getEntity().getContent(), clazz); return Optional.of(entity); } else { Error error = mapper.readValue(response.getEntity().getContent(), Error.class); throw new InfoJobsAPIException(error); }/* ww w. j a va 2 s . c o m*/ } } catch (IOException e) { l.error("Failed to GET {} from {}", clazz.getCanonicalName(), url, e); throw new InfoJobsAPIException(e.getLocalizedMessage()); } }
From source file:com.jiuyi.qujiuyi.common.util.WxRefundSSL.java
public final static String post(String entity, String mch_id, Integer clientType) throws Exception { try {/*w w w . ja v a 2 s . com*/ KeyStore keyStore = KeyStore.getInstance("PKCS12"); // FileInputStream instream = new FileInputStream(new // File("D:\\apiclient_cert.p12")); FileInputStream instream = null; if (clientType == 0) { instream = new FileInputStream(new File(SysCfg.getString("apiclient.ssl"))); } else { instream = new FileInputStream(new File(SysCfg.getString("apiclient.app.ssl"))); } try { keyStore.load(instream, mch_id.toCharArray()); } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mch_id.toCharArray()).build(); sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } catch (Exception e) { e.printStackTrace(); } CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); String result = ""; try { HttpPost post = new HttpPost(SysCfg.getString("weixin.refund")); post.setEntity(new StringEntity(entity)); CloseableHttpResponse response = httpclient.execute(post); try { HttpEntity resp = response.getEntity(); if (resp != null) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resp.getContent())); String line = null; while ((line = bufferedReader.readLine()) != null) { result += line; } } EntityUtils.consume(resp); } finally { response.close(); } } finally { httpclient.close(); } return result; }
From source file:com.weitaomi.systemconfig.wechat.ClientCustomSSL.java
public static String connectKeyStore(String url, String xml, String path, int flag) throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); File file = LoadFileFactory.getFile(path); char[] arr = null; if (flag == 0) { arr = WechatConfig.MCHID.toCharArray(); }/* w w w. j av a 2s . c om*/ if (flag == 1) { arr = WechatConfig.MCHID_OFFICIAL.toCharArray(); } FileInputStream instream = new FileInputStream(file); try { keyStore.load(instream, arr); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, arr).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); StringEntity entityRequest = new StringEntity(xml, "utf-8"); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(entityRequest); // httpPost.setHeader("Content-Type", "application/json");//; charset=utf-8 HttpResponse response = httpclient.execute(httpPost); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new RuntimeException(""); } HttpEntity resEntity = response.getEntity(); InputStream inputStream = resEntity.getContent(); return HttpRequestUtils.readInstream(inputStream, "UTF-8"); }
From source file:org.codice.ddf.commands.solr.SolrHttpWrapper.java
public SolrHttpWrapper() { SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslContext(), getProtocols(), getCipherSuites(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); solrClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory) .setDefaultCookieStore(new BasicCookieStore()).setMaxConnTotal(128).setMaxConnPerRoute(32).build(); }
From source file:com.spotify.docker.client.ResteasyClientFactory.java
@Override public Client getClient(HttpClientConnectionManager cm, RequestConfig requestConfig) { final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig) .setConnectionManager(cm).build(); return new ResteasyClientBuilder().httpEngine(new NonAutoClosingApacheHttpClient4Engine(httpClient)) .register(ObjectMapperProvider.class).register(ProgressResponseReader.class) .register(LogsResponseReader.class).register(new CustomObjectMapperJacksonJaxbJsonProvider()) .build();/*from w ww .j av a2 s. co m*/ }
From source file:com.arrow.acs.client.api.ConnectionManager.java
public CloseableHttpClient getConnection() { Validate.notNull(connectionManager, "connection manager is not available"); return HttpClients.custom().setConnectionManager(connectionManager).setConnectionManagerShared(true) .build();/*from w ww . j av a2 s . c om*/ }