List of usage examples for org.apache.http.impl.client HttpClientBuilder build
public CloseableHttpClient build()
From source file:com.helger.httpclient.HttpClientFactory.java
@Nonnull public CloseableHttpClient createHttpClient() { final HttpClientBuilder aBuilder = createHttpClientBuilder(); return aBuilder.build(); }
From source file:gobblin.writer.http.SalesforceRestWriterTest.java
private void setup(Operation operation, State state) throws ClientProtocolException, IOException, URISyntaxException { state.appendToSetProp(CONF_PREFIX + STATIC_SVC_ENDPOINT, "test"); state.appendToSetProp(CONF_PREFIX + CLIENT_ID, "test"); state.appendToSetProp(CONF_PREFIX + CLIENT_SECRET, "test"); state.appendToSetProp(CONF_PREFIX + USER_ID, "test"); state.appendToSetProp(CONF_PREFIX + PASSWORD, "test"); state.appendToSetProp(CONF_PREFIX + USE_STRONG_ENCRYPTION, "test"); state.appendToSetProp(CONF_PREFIX + SECURITY_TOKEN, "test"); state.appendToSetProp(CONF_PREFIX + OPERATION, operation.name()); SalesForceRestWriterBuilder builder = new SalesForceRestWriterBuilder(); builder = spy(builder);/* w ww. ja v a 2 s .c o m*/ HttpClientBuilder httpClientBuilder = mock(HttpClientBuilder.class); doReturn(httpClientBuilder).when(builder).getHttpClientBuilder(); client = mock(CloseableHttpClient.class); when(httpClientBuilder.build()).thenReturn(client); builder.fromState(state); writer = new SalesforceRestWriter(builder, "test"); writer.setCurServerHost(new URI("http://test.nowhere.com")); }
From source file:de.avanux.smartapplianceenabler.appliance.HttpTransactionExecutor.java
/** * Send a HTTP request whose response has to be closed by the caller! * @param url/*from w w w .j a v a2 s. c o m*/ * @return */ protected CloseableHttpResponse sendHttpRequest(String url, String data, ContentType contentType, String username, String password) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (username != null && password != null) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(AuthScope.ANY, credentials); httpClientBuilder.setDefaultCredentialsProvider(provider); } CloseableHttpClient client = httpClientBuilder.build(); logger.debug("Sending HTTP request"); logger.debug("url=" + url); logger.debug("data=" + data); logger.debug("contentType=" + contentType); logger.debug("username=" + username); logger.debug("password=" + password); try { HttpRequestBase request = null; if (data != null) { request = new HttpPost(url); ((HttpPost) request).setEntity(new StringEntity(data, contentType)); } else { request = new HttpGet(url); } CloseableHttpResponse response = client.execute(request); int responseCode = response.getStatusLine().getStatusCode(); logger.debug("Response code is " + responseCode); return response; } catch (IOException e) { logger.error("Error executing HTTP request.", e); return null; } }
From source file:org.nuxeo.ecm.core.opencmis.impl.CmisSuiteSession2.java
@Test public void testSetContentStreamWithDigestHeader() throws Exception { setUpData();/*w w w. jav a 2 s.c om*/ session.clear(); // clear cache assumeTrue(isBrowser); String content = FILE1_CONTENT + " Updated"; String contentMD5Hex = DigestUtils.md5Hex(content); String contentMD5Base64 = NuxeoPropertyData.transcodeHexToBase64(contentMD5Hex); File[] files = createFiles(content); ObjectMapper mapper = new ObjectMapper(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { String uri = getURI("/testfolder1/testfile1") + "&succinct=true&filter=cmis:contentStreamHash"; HttpPost request = new HttpPost(uri); request.setHeader("Authorization", BASIC_AUTH); for (int i = 0; i < 2; i++) { boolean okRequest = i == 0; request.setHeader("Digest", "md5=" + (String) (okRequest ? contentMD5Base64 : "bogusMD5Sum")); session.clear(); String changeToken = session.getObjectByPath("/testfolder1/testfile1").getChangeToken(); HttpEntity reqEntity = getSetContentStreamHttpEntity(files[i], changeToken); request.setEntity(reqEntity); try (CloseableHttpResponse response = httpClient.execute(request)) { if (okRequest) { checkOkContentStreamResponse(contentMD5Hex, mapper, response); } else { checkBadContentStreamResponse(mapper, response); } } } } deleteFiles(files); }
From source file:org.nuxeo.ecm.core.opencmis.impl.CmisSuiteSession2.java
@Test public void testCreateDocumentWithContentStreamAndDigestHeader() throws Exception { setUpData();//from w w w.j av a 2 s . c om session.clear(); // clear cache assumeTrue(isBrowser); String content = FILE1_CONTENT; String contentMD5Hex = DigestUtils.md5Hex(content); String contentMD5Base64 = NuxeoPropertyData.transcodeHexToBase64(contentMD5Hex); File[] files = createFiles(content); ObjectMapper mapper = new ObjectMapper(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { String uri = getURI("/testfolder1") + "&succinct=true"; HttpPost request = new HttpPost(uri); request.setHeader("Authorization", BASIC_AUTH); for (int i = 0; i < 2; i++) { boolean okRequest = i == 0; request.setHeader("Digest", "md5=" + (String) (okRequest ? contentMD5Base64 : "bogusMD5Sum")); HttpEntity reqEntity = getCreateDocumentHttpEntity(files[i]); request.setEntity(reqEntity); try (CloseableHttpResponse response = httpClient.execute(request)) { if (okRequest) { JsonNode root = checkOkContentStreamResponse(contentMD5Hex, mapper, response); String objectId = root.path("succinctProperties").path("cmis:objectId").getTextValue(); assertNotNull(objectId); coreSession.removeDocument(new IdRef(objectId)); coreSession.save(); } else { checkBadContentStreamResponse(mapper, response); } } } } deleteFiles(files); }
From source file:de.geeksfactory.opacclient.networking.HTTPClient.java
public static HttpClient getNewHttpClient(boolean customssl, boolean disguise_app) { HttpClientBuilder builder = HttpClientBuilder.create(); builder.setRedirectStrategy(new CustomRedirectStrategy()); if (disguise_app) { builder.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, " + "like Gecko) Chrome/43.0.2357.130 Safari/537.36\t"); } else {/*from w w w .jav a2 s.c o m*/ builder.setUserAgent("OpacApp/" + OpacClient.versionName); } if (customssl) { try { if (trustStore == null) { trustStore = KeyStore.getInstance("BKS"); final InputStream in = OpacClient.context.getResources().openRawResource(R.raw.ssl_trust_store); try { trustStore.load(in, "ro5eivoijeeGohsh0daequoo5Zeepaen".toCharArray()); } finally { in.close(); } } ConnectionSocketFactory sf = AdditionalKeyStoresSSLSocketFactory.create(trustStore); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sf) .build(); HttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(registry); builder.setConnectionManager(ccm); return builder.build(); } catch (Exception e) { e.printStackTrace(); return builder.build(); } } else { return builder.build(); } }
From source file:org.nuxeo.ecm.core.opencmis.impl.CmisSuiteSession2.java
@Test public void testCheckInWithDigestHeader() throws Exception { setUpData();/*from w ww .j a v a2s . c o m*/ session.clear(); // clear cache assumeTrue(isBrowser); String content = FILE1_CONTENT + " Updated"; String contentMD5Hex = DigestUtils.md5Hex(content); String contentMD5Base64 = NuxeoPropertyData.transcodeHexToBase64(contentMD5Hex); File[] files = createFiles(content); ObjectMapper mapper = new ObjectMapper(); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { String uri = getURI("/testfolder1/testfile7") + "&succinct=true&filter=cmis:contentStreamHash"; HttpPost request = new HttpPost(uri); request.setHeader("Authorization", BASIC_AUTH); for (int i = 0; i < 2; i++) { boolean okRequest = i == 0; List<NameValuePair> paramList = Arrays.asList(new BasicNameValuePair("cmisaction", "checkOut")); HttpEntity reqEntity = new UrlEncodedFormEntity(paramList); request.setEntity(reqEntity); try (CloseableHttpResponse response = httpClient.execute(request)) { assertEquals(HttpServletResponse.SC_CREATED, response.getStatusLine().getStatusCode()); InputStream is = response.getEntity().getContent(); JsonNode root = mapper.readTree(is); String objectId = root.path("succinctProperties").path("cmis:objectId").getTextValue(); assertNotNull(objectId); } request.setHeader("Digest", "md5=" + (String) (okRequest ? contentMD5Base64 : "bogusMD5Sum")); reqEntity = getCheckInHttpEntity(files[i]); request.setEntity(reqEntity); try (CloseableHttpResponse response = httpClient.execute(request)) { if (okRequest) { checkOkContentStreamResponse(contentMD5Hex, mapper, response); } else { checkBadContentStreamResponse(mapper, response); } } } } deleteFiles(files); }
From source file:io.github.bonigarcia.wdm.WdmHttpClient.java
private WdmHttpClient(String proxyUrl, String proxyUser, String proxyPass) { HttpHost proxyHost = createProxyHttpHost(proxyUrl); HttpClientBuilder builder = HttpClientBuilder.create(); if (proxyHost != null) { builder.setProxy(proxyHost);// w w w .ja v a 2s. c om BasicCredentialsProvider credentialsProvider = createBasicCredentialsProvider(proxyUrl, proxyUser, proxyPass, proxyHost); builder.setDefaultCredentialsProvider(credentialsProvider); } this.httpClient = builder.build(); }