List of usage examples for org.apache.http.config SocketConfig custom
public static Builder custom()
From source file:com.ibm.stocator.fs.swift.http.SwiftConnectionManager.java
/** * Default constructor//from w w w .j a v a 2 s. c om * @param connectionConfigurationT connection conf */ public SwiftConnectionManager(ConnectionConfiguration connectionConfigurationT) { connectionConfiguration = connectionConfigurationT; connectionPool = new PoolingHttpClientConnectionManager(); LOG.trace("SwiftConnectionManager: setDefaultMaxPerRoute {}", connectionConfiguration.getMaxPerRoute()); connectionPool.setDefaultMaxPerRoute(connectionConfiguration.getMaxPerRoute()); LOG.trace("SwiftConnectionManager: getMaxTotal {}", connectionConfiguration.getMaxTotal()); connectionPool.setMaxTotal(connectionConfiguration.getMaxTotal()); LOG.trace("Generate SocketConfig with soTimeout of {}", connectionConfiguration.getSoTimeout()); SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(false) .setSoTimeout(connectionConfiguration.getSoTimeout()).build(); connectionPool.setDefaultSocketConfig(socketConfig); rConfig = RequestConfig.custom().setExpectContinueEnabled(true) .setConnectTimeout(connectionConfiguration.getReqConnectTimeout()) .setConnectionRequestTimeout(connectionConfiguration.getReqConnectionRequestTimeout()) .setSocketTimeout(connectionConfiguration.getReqSocketTimeout()).build(); }
From source file:com.github.vanroy.cloud.dashboard.config.CloudDashboardConfig.java
@Bean public HttpClient HttpClient() { return HttpClients.custom().setMaxConnTotal(100) .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(2000).build()) .setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(1000) .setConnectionRequestTimeout(1000).build()) .build();//from ww w . j a va2s . co m }
From source file:com.opentable.jaxrs.JaxRsClientFactoryImpl.java
private void configureHttpEngine(String clientName, ResteasyClientBuilder clientBuilder, JaxRsClientConfig config) {//from w ww. ja v a2 s .c o m final HttpClientBuilder builder = HttpClientBuilder.create(); if (config.isEtcdHacksEnabled()) { builder.setRedirectStrategy(new ExtraLaxRedirectStrategy()) .addInterceptorFirst(new SwallowHeaderInterceptor(HttpHeaders.CONTENT_LENGTH)); } final MonitoredPoolingHttpClientConnectionManager connectionManager = new MonitoredPoolingHttpClientConnectionManager( clientName); connectionManager.setCheckoutWarnTime(Duration.ofMillis(config.connectionPoolWarnTime().getMillis())); connectionManager.setMaxTotal(config.connectionPoolSize()); connectionManager.setDefaultMaxPerRoute(config.httpClientDefaultMaxPerRoute()); final HttpClient client = builder .setDefaultSocketConfig( SocketConfig.custom().setSoTimeout((int) config.socketTimeout().getMillis()).build()) .setDefaultRequestConfig(customRequestConfig(config, RequestConfig.custom())) .setConnectionManager(connectionManager).build(); final ApacheHttpClient4Engine engine = new HackedApacheHttpClient4Engine(config, client); clientBuilder.httpEngine(engine); }
From source file:it.mbcraft.command_server.engine.CommandServer.java
/** * Starts the server//from ww w. j av a2s. c o m * */ @Override public void start() { try { System.out.print("Starting command server ..."); SocketConfig config = SocketConfig.custom().setSoTimeout(15000).setTcpNoDelay(true).setBacklogSize(2) .setSoKeepAlive(false).build(); server = ServerBootstrap.bootstrap().setListenerPort(listenPort) .setLocalAddress(InetAddress.getLoopbackAddress()).setServerInfo("Java:CommandServer/1.1") .setSocketConfig(config).setExceptionLogger(ExceptionLogger.NO_OP) .registerHandler("*", new HttpCommandHandler()).create(); server.start(); System.out.println("done!"); } catch (IOException ex) { Logger.getLogger(CommandServer.class.getName()).log(Level.SEVERE, null, ex); } }
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;//w ww . jav 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:com.meltmedia.cadmium.core.github.ApiClient.java
protected static HttpClient createStaticHttpClient() { HttpClient client = HttpClients.custom() .setDefaultSocketConfig(SocketConfig.custom().setSoReuseAddress(true).build()).build(); return client; }
From source file:org.apache.manifoldcf.jettyrunner.ManifoldCFJettyShutdown.java
public void shutdownJetty() throws Exception { // Pick up shutdown token String shutdownToken = System.getProperty("org.apache.manifoldcf.jettyshutdowntoken"); if (shutdownToken != null) { int socketTimeout = 900000; int connectionTimeout = 300000; HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true) .setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(false) .setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout) .setConnectionRequestTimeout(socketTimeout); HttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).setMaxConnTotal(1) .disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()) .setDefaultSocketConfig( SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build()) .setRequestExecutor(new HttpRequestExecutor(socketTimeout)) .setRedirectStrategy(new DefaultRedirectStrategy()).build(); HttpPost method = new HttpPost( jettyBaseURL + "/shutdown?token=" + URLEncoder.encode(shutdownToken, "UTF-8")); method.setEntity(new StringEntity("", ContentType.create("text/plain", StandardCharsets.UTF_8))); try {//from w w w.ja va 2 s . c om HttpResponse httpResponse = httpClient.execute(method); int resultCode = httpResponse.getStatusLine().getStatusCode(); if (resultCode != 200) throw new Exception("Received result code " + resultCode + " from POST"); } catch (org.apache.http.NoHttpResponseException e) { // This is ok and expected } } else { throw new Exception("No jetty shutdown token specified"); } }
From source file:com.jivesoftware.os.routing.bird.http.client.HttpClientFactoryProvider.java
public HttpClientFactory createHttpClientFactory(Collection<HttpClientConfiguration> configurations, boolean latentClient) { HttpClientConfig httpClientConfig = locateConfig(configurations, HttpClientConfig.class, HttpClientConfig.newBuilder().build()); HttpClientSSLConfig sslConfig = locateConfig(configurations, HttpClientSSLConfig.class, null); String scheme;/* w w w . j av a2s. co m*/ PoolingHttpClientConnectionManager poolingHttpClientConnectionManager; if (sslConfig != null && sslConfig.isUseSsl()) { LayeredConnectionSocketFactory sslSocketFactory; if (sslConfig.getCustomSSLSocketFactory() != null) { sslSocketFactory = sslConfig.getCustomSSLSocketFactory(); } else { sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory(); } scheme = "https"; poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory).build()); } else { scheme = "http"; poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(); } if (httpClientConfig.getMaxConnections() > 0) { poolingHttpClientConnectionManager.setMaxTotal(httpClientConfig.getMaxConnections()); } else { poolingHttpClientConnectionManager.setMaxTotal(Integer.MAX_VALUE); } if (httpClientConfig.getMaxConnectionsPerHost() > 0) { poolingHttpClientConnectionManager.setDefaultMaxPerRoute(httpClientConfig.getMaxConnectionsPerHost()); } else { poolingHttpClientConnectionManager.setDefaultMaxPerRoute(Integer.MAX_VALUE); } poolingHttpClientConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout( httpClientConfig.getSocketTimeoutInMillis() > 0 ? httpClientConfig.getSocketTimeoutInMillis() : 0) .build()); Closeable closeable; HttpClientConnectionManager clientConnectionManager; clientConnectionManager = poolingHttpClientConnectionManager; closeable = poolingHttpClientConnectionManager; return (OAuthSigner signer, String host, int port) -> { HttpClientBuilder httpClientBuilder = HttpClients.custom() .setConnectionManager(clientConnectionManager); CloseableHttpClient client = httpClientBuilder.build(); HttpClient httpClient = new ApacheHttpClient441BackedHttpClient(scheme, host, port, signer, client, closeable, httpClientConfig.getCopyOfHeadersForEveryRequest()); if (latentClient) { httpClient = new LatentHttpClient(httpClient); } return httpClient; }; }
From source file:com.palominolabs.crm.sf.rest.RestConnectionPoolImpl.java
/** * Create a new pool with a specific idle connection timeout. * * @param metricRegistry metric registry * @param idleConnTimeout how long an unused connection must sit idle before it is eligible for removal from the *//*from w ww .ja v a2 s . c om*/ public RestConnectionPoolImpl(MetricRegistry metricRegistry, int idleConnTimeout) { this.metricRegistry = metricRegistry; SSLContext sslContext = null; try { sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); } catch (Exception e) { throw new RuntimeException(e); } SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", sslsf).build(); connectionManager = new PoolingHttpClientConnectionManager(r); connectionManager.setDefaultMaxPerRoute(20); connectionManager.setMaxTotal(60); SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(300000).build(); connectionManager.setDefaultSocketConfig(socketConfig); objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).build(); this.idleConnTimeout = idleConnTimeout; }
From source file:com.ksc.http.apache.client.impl.ApacheConnectionManagerFactory.java
private SocketConfig buildSocketConfig(HttpClientSettings settings) { return SocketConfig.custom().setSoKeepAlive(settings.useTcpKeepAlive()) .setSoTimeout(settings.getSocketTimeout()).setTcpNoDelay(true).build(); }