use of org.apache.http.conn.scheme.SchemeRegistry in project liferay-ide by liferay.
the class RemoteConnection method _getHttpClient.
private HttpClient _getHttpClient() {
if (_httpClient != null) {
return _httpClient;
}
DefaultHttpClient newDefaultHttpClient = null;
if ((getUsername() != null) || (getPassword() != null)) {
try {
IProxyService proxyService = LiferayCore.getProxyService();
URI uri = new URI("http://" + getHost() + ":" + getHttpPort());
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if ((data.getHost() == null) || (data.getPort() == 0)) {
continue;
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", data.getPort(), PlainSocketFactory.getSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
DefaultHttpClient newHttpClient = new DefaultHttpClient(cm);
HttpHost proxy = new HttpHost(data.getHost(), data.getPort());
newHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
newDefaultHttpClient = newHttpClient;
break;
}
if (newDefaultHttpClient == null) {
uri = new URI("SOCKS://" + getHost() + ":" + getHttpPort());
proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() == null) {
continue;
}
DefaultHttpClient newHttpClient = new DefaultHttpClient();
newHttpClient.getParams().setParameter("socks.host", data.getHost());
newHttpClient.getParams().setParameter("socks.port", data.getPort());
SchemeRegistry registry = newHttpClient.getConnectionManager().getSchemeRegistry();
Scheme scheme = new Scheme("socks", data.getPort(), PlainSocketFactory.getSocketFactory());
registry.register(scheme);
newDefaultHttpClient = newHttpClient;
break;
}
}
} catch (URISyntaxException urise) {
LiferayCore.logError("Unable to read proxy data", urise);
}
if (newDefaultHttpClient == null) {
newDefaultHttpClient = new DefaultHttpClient();
}
_httpClient = newDefaultHttpClient;
} else {
_httpClient = new DefaultHttpClient();
}
return _httpClient;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project ovirt-engine-sdk-java by oVirt.
the class ConnectionBuilder42 method createConnectionSocketFactoryRegistry.
private SchemeRegistry createConnectionSocketFactoryRegistry() {
SchemeRegistry schemeRegistry = new SchemeRegistry();
SSLSocketFactory sf;
// Create SSL/TLS or plain connection:
if (HTTP_PROTOCOL.equals(getProtocol())) {
schemeRegistry.register(new Scheme(HTTP_PROTOCOL, getPort(), PlainSocketFactory.getSocketFactory()));
} else if (HTTPS_PROTOCOL.equals(getProtocol())) {
try {
if (this.insecure) {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { noCaTrustManager }, null);
sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} else {
KeyStore truststore = null;
InputStream in = null;
if (this.trustStoreFile != null) {
truststore = KeyStore.getInstance(KeyStore.getDefaultType());
try {
in = new FileInputStream(this.trustStoreFile);
truststore.load(in, this.trustStorePassword != null ? this.trustStorePassword.toCharArray() : null);
} finally {
if (in != null) {
in.close();
}
}
}
sf = new SSLSocketFactory(SSLSocketFactory.TLS, null, null, truststore, null, null, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
}
schemeRegistry.register(new Scheme(HTTPS_PROTOCOL, getPort(), sf));
} catch (NoSuchAlgorithmException e) {
throw new Error(NO_TLS_ERROR, e);
} catch (KeyManagementException e) {
throw new Error(BAD_KEY_ERROR, e);
} catch (KeyStoreException e) {
throw new Error(KEY_STORE_ERROR, e);
} catch (FileNotFoundException e) {
throw new Error(KEY_STORE_FILE_NOT_FOUND_ERROR, e);
} catch (CertificateException e) {
throw new Error(CERTIFICATE_ERROR, e);
} catch (IOException e) {
throw new Error(IO_ERROR, e);
} catch (UnrecoverableKeyException e) {
throw new Error(UNRECOVERABLE_KEY_ERROR, e);
}
}
return schemeRegistry;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project androidquery by androidquery.
the class AbstractAjaxCallback method getClient.
private static DefaultHttpClient getClient() {
if (client == null || !REUSE_CLIENT) {
AQUtility.debug("creating http client");
HttpParams httpParams = new BasicHttpParams();
// httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT);
// ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL));
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
// Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry);
client = new DefaultHttpClient(cm, httpParams);
}
return client;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project spring-boot-quick by vector4wang.
the class HttpUtil method sslClient.
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.http.conn.scheme.SchemeRegistry in project spring-boot-quick by vector4wang.
the class HttpUtils method sslClient.
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
Aggregations