List of usage examples for org.apache.http.client.fluent Executor newInstance
public static Executor newInstance(final HttpClient httpclient)
From source file:com.softinstigate.restheart.integrationtest.ContentEncodingIT.java
@BeforeClass public static void init() throws Exception { notDecompressingExecutor = Executor.newInstance(HttpClients.custom().disableContentCompression().build()) .authPreemptive(new HttpHost("127.0.0.1", 8080, "http")) .auth(new HttpHost("127.0.0.1"), "admin", "changeit"); }
From source file:org.opendatakit.briefcase.reused.http.CommonsHttp.java
@Override public <T> Response<T> execute(Request<T> request) { // Always instantiate a new Executor to avoid side-effects between executions Executor executor = Executor.newInstance(HttpClientBuilder.create() .setDefaultRequestConfig(custom().setCookieSpec(STANDARD).build()).build()); // Apply auth settings if credentials are received request.ifCredentials((URL url, Credentials credentials) -> executor.auth(HttpHost.create(url.getHost()), credentials.getUsername(), credentials.getPassword())); // get the response body and let the Request map it return uncheckedExecute(request, executor).map(request::map); }
From source file:org.wildfly.swarm.https.test.HttpsTest.java
@Test @RunAsClient//ww w . j av a 2s . co m public void hello() throws IOException, GeneralSecurityException { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial((TrustStrategy) (chain, authType) -> true) .build(); try (CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build()) { String response = Executor.newInstance(httpClient).execute(Request.Get("https://localhost:8443/")) .returnContent().asString(); assertThat(response).contains("Hello on port 8443, secure: true"); } }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ???json?post?//from ww w . j a va 2s .c om * * @throws IOException * @throws * */ public static String fetchJsonHttpResponse(String contentUrl, Map<String, String> headerMap, JsonObject bodyJson) throws IOException { Executor executor = Executor.newInstance(httpClient); Request request = Request.Post(contentUrl); if (headerMap != null && !headerMap.isEmpty()) { for (Map.Entry<String, String> m : headerMap.entrySet()) { request.addHeader(m.getKey(), m.getValue()); } } if (bodyJson != null) { request.bodyString(bodyJson.toString(), ContentType.APPLICATION_JSON); } return executor.execute(request).returnContent().asString(); }
From source file:photosharing.api.ExecutorUtil.java
/** * helper method that returns an HTTPClient executor with credentials * available.// w w w. jav a2 s . com * * Also enables the test case to connect to ANY SSL Certificate * valid/invalid * * @return {Executor} or Null if there is an issue */ public static Executor getExecutor() { Executor executor = null; /* * if using one of the environments without a trusted CA chain or * you are using Fiddler, you want to set TRUST=TRUE in appconfig.properties */ Configuration config = Configuration.getInstance(null); String sTrust = config.getValue(Configuration.TRUST); boolean trusted = Boolean.parseBoolean(sTrust); if (trusted) { try { HttpClientBuilder builder = HttpClients.custom(); // Setup the SSL Context to Trust Any SSL Certificate SSLContextBuilder sslBuilder = new SSLContextBuilder(); sslBuilder.loadTrustMaterial(null, new TrustStrategy() { /** * override for fiddler proxy */ public boolean isTrusted(X509Certificate[] certs, String host) throws CertificateException { return true; } }); SSLContext sslContext = sslBuilder.build(); builder.setHostnameVerifier(new AllowAllHostnameVerifier()); builder.setSslcontext(sslContext); CloseableHttpClient httpClient = builder.build(); executor = Executor.newInstance(httpClient); } catch (NoSuchAlgorithmException e) { logger.log(Level.SEVERE, "Issue with No Algorithm " + e.toString()); } catch (KeyStoreException e) { logger.log(Level.SEVERE, "Issue with KeyStore " + e.toString()); } catch (KeyManagementException e) { logger.log(Level.SEVERE, "Issue with KeyManagement " + e.toString()); } } return executor; }
From source file:io.fabric8.elasticsearch.plugin.HttpsProxyClientCertAuthenticatorIntegrationTest.java
@Test public void testProxyAuthWithSSL() throws Exception { SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial(new File(keyStoreFile), keystorePW.toCharArray(), new TrustSelfSignedStrategy()) .build();//from w ww . ja va2 s .c o m try (CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }).build()) { Executor ex = Executor.newInstance(httpclient); Response response = ex.execute(Request.Get("https://localhost:9200/blahobar.234324234/logs/1") .addHeader("Authorization", String.format("Bearer %s", token)) .addHeader("X-Proxy-Remote-User", proxyUser)); System.out.println(response.returnContent().asString()); } catch (Exception e) { System.out.println(e); fail("Test Failed"); } }
From source file:com.github.aistomin.jenkins.real.RealJenkins.java
@Override public String version() throws Exception { final Map<String, String> headers = new HashMap<>(); Executor.newInstance(HttpClientBuilder.create().build()).execute(Request.Post(this.base)) .handleResponse(new ResponseHandler<Object>() { public Object handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { for (final Header header : response.getAllHeaders()) { headers.put(header.getName(), header.getValue()); }//ww w.j av a 2 s. c o m return response; } }); return headers.get("X-Jenkins"); }
From source file:com.github.aistomin.http.PostRequest.java
@Override public String execute() throws Exception { final Request request = Request.Post(this.resource); for (final Map.Entry<String, String> item : this.heads.entrySet()) { request.addHeader(item.getKey(), item.getValue()); }/*from w ww . j a va 2s . c om*/ final HttpClientBuilder builder = HttpClientBuilder.create(); builder.setRedirectStrategy(new LaxRedirectStrategy()); builder.setServiceUnavailableRetryStrategy(new ServiceUnavailableRetryStrategy() { public boolean retryRequest(final HttpResponse response, final int count, final HttpContext context) { return count <= PostRequest.RETRY_COUNT; } public long getRetryInterval() { return PostRequest.RETRY_INTERVAL; } }); return Executor.newInstance(builder.build()).execute(request).returnContent().asString(); }
From source file:org.mule.module.http.functional.listener.HttpListenerWorkerThreadingProfileTestCase.java
@Before public void setup() { // Need to configure the maximum number of connections of HttpClient, because the default is less than // the default number of workers in the HTTP listener. PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(); mgr.setDefaultMaxPerRoute(HTTP_CLIENT_MAX_CONNECTIONS); mgr.setMaxTotal(HTTP_CLIENT_MAX_CONNECTIONS); httpClientExecutor = Executor.newInstance(HttpClientBuilder.create().setConnectionManager(mgr).build()); }
From source file:org.apache.james.jmap.methods.integration.cucumber.UploadStepdefs.java
@When("^\"([^\"]*)\" upload a content$") public void userUploadContent(String username) throws Throwable { AccessToken accessToken = userStepdefs.tokenByUser.get(username); Request request = Request.Post(uploadUri).bodyStream( new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); }/*from w ww . j a v a 2s .co m*/ response = Executor.newInstance(HttpClientBuilder.create().disableAutomaticRetries().build()) .execute(request).returnResponse(); }