use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project jersey by jersey.
the class ApacheConnector method createConnectionManager.
private HttpClientConnectionManager createConnectionManager(final Client client, final Configuration config, final SSLContext sslContext, final boolean useSystemProperties) {
final String[] supportedProtocols = useSystemProperties ? split(System.getProperty("https.protocols")) : null;
final String[] supportedCipherSuites = useSystemProperties ? split(System.getProperty("https.cipherSuites")) : null;
HostnameVerifier hostnameVerifier = client.getHostnameVerifier();
final LayeredConnectionSocketFactory sslSocketFactory;
if (sslContext != null) {
sslSocketFactory = new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifier);
} else {
if (useSystemProperties) {
sslSocketFactory = new SSLConnectionSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault(), supportedProtocols, supportedCipherSuites, hostnameVerifier);
} else {
sslSocketFactory = new SSLConnectionSocketFactory(SSLContexts.createDefault(), hostnameVerifier);
}
}
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
final Integer chunkSize = ClientProperties.getValue(config.getProperties(), ClientProperties.CHUNKED_ENCODING_SIZE, ClientProperties.DEFAULT_CHUNK_SIZE, Integer.class);
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry, new ConnectionFactory(chunkSize));
if (useSystemProperties) {
String s = System.getProperty("http.keepAlive", "true");
if ("true".equalsIgnoreCase(s)) {
s = System.getProperty("http.maxConnections", "5");
final int max = Integer.parseInt(s);
connectionManager.setDefaultMaxPerRoute(max);
connectionManager.setMaxTotal(2 * max);
}
}
return connectionManager;
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project cloudbreak by hortonworks.
the class MockSetup method disableSSLCheck.
private void disableSSLCheck() {
try {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();
LayeredConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
Unirest.setHttpClient(httpclient);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ignored) {
throw new RuntimeException("can't create ssl settings");
}
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project java 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 gateway-dubbox by zhuzhong.
the class OpenApiHttpliClientFluentServiceImpl method initHttpClient.
private void initHttpClient() {
LayeredConnectionSocketFactory ssl = null;
try {
ssl = SSLConnectionSocketFactory.getSystemSocketFactory();
} catch (final SSLInitializationException ex) {
final SSLContext sslcontext;
try {
sslcontext = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
sslcontext.init(null, null, null);
ssl = new SSLConnectionSocketFactory(sslcontext);
} catch (final SecurityException ignore) {
} catch (final KeyManagementException ignore) {
} catch (final NoSuchAlgorithmException ignore) {
}
}
final Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", ssl != null ? ssl : SSLConnectionSocketFactory.getSocketFactory()).build();
manager = new PoolingHttpClientConnectionManager(sfr);
manager.setDefaultMaxPerRoute(maxPerRoute);
manager.setMaxTotal(maxTotal);
client = HttpClientBuilder.create().setConnectionManager(manager).build();
executor = Executor.newInstance(client);
}
use of org.apache.http.conn.socket.LayeredConnectionSocketFactory in project google-api-java-client by google.
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);
}
Aggregations