use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project fess-crawler by codelibs.
the class HcHttpClient method buildConnectionManager.
protected HttpClientConnectionManager buildConnectionManager(final HttpClientBuilder httpClientBuilder) {
// SSL
final LayeredConnectionSocketFactory sslSocketFactory = buildSSLSocketFactory(httpClientBuilder);
final Registry<ConnectionSocketFactory> socketFactoryRegistry = //
RegistryBuilder.<ConnectionSocketFactory>create().register("http", //
PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
final long timeToLive = getInitParameter(TIME_TO_LIVE_PROPERTY, 5L, Long.class);
final TimeUnit timeUnit = TimeUnit.valueOf(getInitParameter(TIME_TO_LIVE_TIME_UNIT_PROPERTY, "MINUTES", String.class));
final int maxTotal = getInitParameter(MAX_TOTAL_CONNECTION_PROPERTY, 200, Integer.class);
final int defaultMaxPerRoute = getInitParameter(DEFAULT_MAX_CONNECTION_PER_ROUTE_PROPERTY, 20, Integer.class);
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, null, null, dnsResolver, timeToLive, timeUnit);
connectionManager.setMaxTotal(maxTotal);
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
return connectionManager;
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project testobject-java-api by saucelabs.
the class TestObjectClientImpl method buildClient.
private Client buildClient(ProxySettings proxySettings) {
X509HostnameVerifier defaultHostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SslConfigurator sslConfig = SslConfigurator.newInstance();
LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslConfig.createSSLContext(), new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" }, null, defaultHostnameVerifier);
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
ClientConfig config = new ClientConfig();
config.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager(registry));
ApacheConnectorProvider connector = new ApacheConnectorProvider();
config.connectorProvider(connector);
config.register(MultiPartFeature.class);
config.register(JacksonFeature.class);
if (proxySettings != null) {
config.property(ClientProperties.PROXY_URI, "http://" + proxySettings.getHost() + ":" + proxySettings.getPort());
if (proxySettings.getUsername() != null) {
config.property(ClientProperties.PROXY_USERNAME, proxySettings.getUsername());
config.property(ClientProperties.PROXY_PASSWORD, proxySettings.getPassword());
}
}
SSLContext sslContext = sslConfig.createSSLContext();
return ClientBuilder.newBuilder().sslContext(sslContext).newClient(config);
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project wavefront-proxy by wavefrontHQ.
the class HttpClientTest method httpClientTimeoutsWork.
@Test(expected = ProcessingException.class)
public void httpClientTimeoutsWork() throws Exception {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.registerProvider(JsonNodeWriter.class);
factory.registerProvider(ResteasyJackson2Provider.class);
HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setMaxConnTotal(200).setMaxConnPerRoute(100).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(100).build()).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(60000).build()).setSSLSocketFactory(new LayeredConnectionSocketFactory() {
@Override
public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) throws IOException, UnknownHostException {
return SSLConnectionSocketFactory.getSystemSocketFactory().createLayeredSocket(socket, target, port, context);
}
@Override
public Socket createSocket(HttpContext context) throws IOException {
return SSLConnectionSocketFactory.getSystemSocketFactory().createSocket(context);
}
@Override
public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
assertTrue("Non-zero timeout passed to connect socket is expected", connectTimeout > 0);
throw new ProcessingException("OK");
}
}).build();
ResteasyClient client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient, true)).providerFactory(factory).build();
SocketServerRunnable sr = new SocketServerRunnable();
Thread serverThread = new Thread(sr);
serverThread.start();
ResteasyWebTarget target = client.target("https://localhost:" + sr.getPort());
SimpleRESTEasyAPI proxy = target.proxy(SimpleRESTEasyAPI.class);
proxy.search("resteasy");
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project google-api-java-client by googleapis.
the class GoogleApacheHttpTransport method newTrustedTransport.
/**
* Returns a new instance of {@link ApacheHttpTransport} that uses {@link
* GoogleUtils#getCertificateTrustStore()} for the trusted certificates.
*
* @deprecated Use
* com.google.api.client.googleapis.apache.v2.GoogleApacheHttpTransport.newTrustedTransport()
*/
public static ApacheHttpTransport newTrustedTransport() throws GeneralSecurityException, IOException {
// Set socket buffer sizes to 8192
SocketConfig socketConfig = SocketConfig.custom().setRcvBufSize(8192).setSndBufSize(8192).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS);
// Disable the stale connection check (previously configured in the HttpConnectionParams
connectionManager.setValidateAfterInactivity(-1);
// Use the included trust store
KeyStore trustStore = GoogleUtils.getCertificateTrustStore();
SSLContext sslContext = SslUtils.getTlsSslContext();
SslUtils.initSslContext(sslContext, trustStore, SslUtils.getPkixTrustManagerFactory());
LayeredConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);
HttpClient client = HttpClientBuilder.create().useSystemProperties().setSSLSocketFactory(socketFactory).setDefaultSocketConfig(socketConfig).setMaxConnTotal(200).setMaxConnPerRoute(20).setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())).setConnectionManager(connectionManager).disableRedirectHandling().disableAutomaticRetries().build();
return new ApacheHttpTransport(client);
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project sslcontext-kickstart by Hakky54.
the class Apache4SslUtilsShould method createLayeredConnectionSocketFactoryWithIdentityMaterialAndTrustMaterial.
@Test
void createLayeredConnectionSocketFactoryWithIdentityMaterialAndTrustMaterial() {
KeyStore identity = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + IDENTITY_FILE_NAME, IDENTITY_PASSWORD);
KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
SSLFactory sslFactory = SSLFactory.builder().withIdentityMaterial(identity, IDENTITY_PASSWORD).withTrustMaterial(trustStore).build();
assertThat(sslFactory.getSslContext()).isNotNull();
assertThat(sslFactory.getKeyManager()).isPresent();
assertThat(sslFactory.getTrustManager()).isNotNull();
assertThat(sslFactory.getTrustedCertificates()).isNotEmpty();
assertThat(sslFactory.getTrustManager()).isNotNull();
assertThat(sslFactory.getHostnameVerifier()).isNotNull();
LayeredConnectionSocketFactory socketFactory = Apache4SslUtils.toSocketFactory(sslFactory);
assertThat(socketFactory).isNotNull();
}
Aggregations