List of usage examples for org.apache.http.impl.nio.client HttpAsyncClients custom
public static HttpAsyncClientBuilder custom()
From source file:hoot.services.controllers.job.JobControllerBase.java
/** * Post Job request to jobExecutioner Servlet * //from ww w .jav a2s . c om * @param jobId * @param requestParams */ public void postJobRquest(String jobId, String requestParams) { logger.debug(jobId); logger.debug(requestParams); // Request should come back immediately but if something is wrong then timeout and clean up to make UI responsive RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(JOB_RES_CONNECTION_TIMEOUT) .setSocketTimeout(JOB_RES_CONNECTION_TIMEOUT).build(); try (CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig) .build()) { httpclient.start(); HttpPost httpPost = new HttpPost(CORE_JOB_SERVER_URL + "/hoot-services/job/" + jobId); logger.debug("postJobRequest : {}/hoot-services/job/{}", CORE_JOB_SERVER_URL, jobId); StringEntity se = new StringEntity(requestParams); httpPost.setEntity(se); Future<HttpResponse> future = httpclient.execute(httpPost, null); // wait for response HttpResponse r = future.get(); logger.debug("postJobRequest Response: {}", r.getStatusLine()); } catch (Exception ex) { String msg = "Failed upload: " + ex; throw new WebApplicationException(ex, Response.serverError().entity(msg).build()); } }
From source file:com.spotify.asyncdatastoreclient.Datastore.java
private Datastore(final DatastoreConfig config) { this.config = config; // TODO implement ning config which doesn't exist on apache http client // .setCompressionEnforced(true) RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(config.getConnectTimeout()) .setConnectionRequestTimeout(config.getRequestTimeout()).build(); client = FiberCloseableHttpAsyncClient.wrap(HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig) .setMaxConnPerRoute(config.getMaxConnections()).setMaxConnTotal(config.getMaxConnections()) .build());//from w w w. j av a 2 s . c om client.start(); prefixUri = String.format("%s/datastore/%s/datasets/%s/", config.getHost(), config.getVersion(), config.getDataset()); executor = Executors.newSingleThreadScheduledExecutor(); if (config.getCredential() != null) { // block while retrieving an access token for the first time refreshAccessToken(); // wake up every 10 seconds to check if access token has expired executor.scheduleAtFixedRate(this::refreshAccessToken, 10, 10, TimeUnit.SECONDS); } }
From source file:com.clxcommunications.xms.ApiHttpAsyncClient.java
/** * Creates a new HTTP asynchronous client suitable for communicating with * XMS.// ww w .ja va 2 s . com * * @param startedInternally * whether this object was created inside this SDK */ ApiHttpAsyncClient(boolean startedInternally) { this.startedInternally = startedInternally; // Allow TLSv1.2 protocol only SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(SSLContexts.createSystemDefault(), new String[] { "TLSv1.2" }, null, SSLIOSessionStrategy.getDefaultHostnameVerifier()); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout((int) DEFAULT_TIMEOUT.toMillis()) .setSocketTimeout((int) DEFAULT_TIMEOUT.toMillis()).build(); // TODO: Is this a good default setup? this.client = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).disableCookieManagement() .setMaxConnPerRoute(DEFAULT_MAX_CONN).setMaxConnTotal(DEFAULT_MAX_CONN) .setDefaultRequestConfig(requestConfig).build(); }
From source file:com.uber.jaeger.httpclient.JaegerRequestAndResponseInterceptorIntegrationTest.java
@Test public void testAsyncHttpClientTracing() throws Exception { HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom(); CloseableHttpAsyncClient client = TracingInterceptors.addTo(clientBuilder, tracer).build(); client.start();/* w w w.j a v a 2 s. c o m*/ //Make a request to the async client and wait for response client.execute(new HttpHost("localhost", mockServerRule.getPort()), new BasicHttpRequest("GET", "/testing"), new FutureCallback<org.apache.http.HttpResponse>() { @Override public void completed(org.apache.http.HttpResponse result) { } @Override public void failed(Exception ex) { } @Override public void cancelled() { } }).get(); verifyTracing(parentSpan); }
From source file:org.apache.zeppelin.notebook.repo.zeppelinhub.rest.HttpProxyClient.java
private CloseableHttpAsyncClient getAsyncProxyHttpClient(URI proxyUri) { LOG.info("Creating async proxy http client"); PoolingNHttpClientConnectionManager cm = getAsyncConnectionManager(); HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort()); HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom(); if (cm != null) { clientBuilder = clientBuilder.setConnectionManager(cm); }/* www . j av a 2 s .c om*/ if (proxy != null) { clientBuilder = clientBuilder.setProxy(proxy); } clientBuilder = setRedirects(clientBuilder); return clientBuilder.build(); }
From source file:org.voltdb.exportclient.TeradataListenerExportClient.java
private void connect() throws IOReactorException { if (m_connManager == null) { ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(); m_connManager = new PoolingNHttpClientConnectionManager(ioReactor); m_connManager.setMaxTotal(HTTP_EXPORT_MAX_CONNS); m_connManager.setDefaultMaxPerRoute(HTTP_EXPORT_MAX_CONNS); }/* w w w . j a va 2s. com*/ if (m_client == null || !m_client.isRunning()) { HttpAsyncClientBuilder client = HttpAsyncClients.custom().setConnectionManager(m_connManager); m_client = client.build(); m_client.start(); } }
From source file:net.simondieterle.wns.server.Sender.java
@VisibleForTesting public Sender(String id, String secret, int retryCount) { ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); this.clientId = id; this.clientSecret = secret; this.client = HttpAsyncClients.custom().setMaxConnTotal(100).setMaxConnPerRoute(10).build(); this.authExecutor = new AsyncRetryExecutor(scheduler).retryOn(ServerFailedException.class) .withExponentialBackoff(10, 2.0).withMaxRetries(5).withUniformJitter().withMaxDelay(60000); this.executor = new AsyncRetryExecutor(scheduler).retryOn(ServerFailedException.class) .retryOn(TimeoutException.class).retryOn(IOException.class).withExponentialBackoff(100, 2.0) .withUniformJitter().withMaxDelay(4000).withMaxRetries(retryCount); this.client.start(); }
From source file:com.floragunn.searchguard.HeaderAwareJestClientFactory.java
public HeaderAwareJestHttpClient getObject() { final HeaderAwareJestHttpClient client = new HeaderAwareJestHttpClient(); if (httpClientConfig != null) { log.debug("Creating HTTP client based on configuration"); client.setServers(httpClientConfig.getServerList()); final HttpClientConnectionManager connectionManager = createConnectionManager(); client.setHttpClient(createHttpClient(connectionManager)); // set custom gson instance final Gson gson = httpClientConfig.getGson(); if (gson != null) { client.setGson(gson);/*from w ww. java 2 s .c o m*/ } // set discovery (should be set after setting the httpClient on jestClient) if (httpClientConfig.isDiscoveryEnabled()) { log.info("Node Discovery Enabled..."); final NodeChecker nodeChecker = new NodeChecker(httpClientConfig, client); client.setNodeChecker(nodeChecker); nodeChecker.startAsync(); nodeChecker.awaitRunning(); } else { log.info("Node Discovery Disabled..."); } // schedule idle connection reaping if configured if (httpClientConfig.getMaxConnectionIdleTime() > 0) { log.info("Idle connection reaping enabled..."); final IdleConnectionReaper reaper = new IdleConnectionReaper(httpClientConfig, new HttpReapableConnectionManager(connectionManager)); client.setIdleConnectionReaper(reaper); reaper.startAsync(); reaper.awaitRunning(); } } else { log.debug( "There is no configuration to create http client. Going to create simple client with default values"); client.setHttpClient(HttpClients.createDefault()); final LinkedHashSet<String> servers = new LinkedHashSet<String>(); servers.add("http://localhost:9200"); client.setServers(servers); } client.setAsyncClient(HttpAsyncClients.custom().setRoutePlanner(getRoutePlanner()).build()); return client; }
From source file:org.jenkinsci.plugins.relution_publisher.net.RequestManager.java
private CloseableHttpAsyncClient createHttpClient() { final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); requestConfigBuilder.setConnectionRequestTimeout(TIMEOUT_CONNECTION_REQUEST); requestConfigBuilder.setConnectTimeout(TIMEOUT_CONNECT); requestConfigBuilder.setSocketTimeout(TIMEOUT_SOCKET); if (this.mProxyHost != null) { requestConfigBuilder.setProxy(this.mProxyHost); }/* www.java 2 s.c om*/ final HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom(); final RequestConfig requestConfig = requestConfigBuilder.build(); clientBuilder.setDefaultRequestConfig(requestConfig); if (this.mProxyHost != null && this.mCredentials != null) { final AuthScope authScope = new AuthScope(this.mProxyHost); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(authScope, this.mCredentials); clientBuilder.setDefaultCredentialsProvider(credentialsProvider); } return clientBuilder.build(); }
From source file:com.petalmd.armor.HeaderAwareJestClientFactory.java
public HeaderAwareJestHttpClient getObject() { final HeaderAwareJestHttpClient client = new HeaderAwareJestHttpClient(); if (httpClientConfig != null) { log.debug("Creating HTTP client based on configuration"); client.setServers(httpClientConfig.getServerList()); final HttpClientConnectionManager connectionManager = createConnectionManager(); client.setHttpClient(createHttpClient(connectionManager)); // set custom gson instance final Gson gson = httpClientConfig.getGson(); if (gson != null) { client.setGson(gson);/*from w w w . ja v a2 s . c o m*/ } // set discovery (should be set after setting the httpClient on jestClient) if (httpClientConfig.isDiscoveryEnabled()) { log.info("Node Discovery Enabled..."); final NodeChecker nodeChecker = new NodeChecker(client, httpClientConfig); client.setNodeChecker(nodeChecker); nodeChecker.startAsync(); nodeChecker.awaitRunning(); } else { log.info("Node Discovery Disabled..."); } // schedule idle connection reaping if configured if (httpClientConfig.getMaxConnectionIdleTime() > 0) { log.info("Idle connection reaping enabled..."); final IdleConnectionReaper reaper = new IdleConnectionReaper(httpClientConfig, new HttpReapableConnectionManager(connectionManager, getAsyncConnectionManager())); client.setIdleConnectionReaper(reaper); reaper.startAsync(); reaper.awaitRunning(); } } else { log.debug( "There is no configuration to create http client. Going to create simple client with default values"); client.setHttpClient(HttpClients.createDefault()); final LinkedHashSet<String> servers = new LinkedHashSet<String>(); servers.add("http://localhost:9200"); client.setServers(servers); } client.setAsyncClient(HttpAsyncClients.custom().setRoutePlanner(getRoutePlanner()).build()); return client; }