use of com.alibaba.csb.sdk.HttpCallerException in project csb-sdk by aliyun.
the class HttpClientFactory method createCloseableHttpClient.
public static CloseableHttpClient createCloseableHttpClient(PoolingHttpClientConnectionManager connManager) throws HttpCallerException {
ConnectionKeepAliveStrategy myStrategy = createKeepAliveStrategy();
CloseableHttpClient client;
try {
client = HttpClients.custom().setConnectionManager(connManager).setKeepAliveStrategy(myStrategy).build();
} catch (Exception e) {
throw new HttpCallerException("Failed to create httpclient: " + e.getMessage(), e);
}
return client;
}
use of com.alibaba.csb.sdk.HttpCallerException in project csb-sdk by aliyun.
the class HttpClientFactory method createConnManager.
/**
* Create a connection pool which supports http and https socket
* @return
* @throws HttpCallerException
*/
public static PoolingHttpClientConnectionManager createConnManager() throws HttpCallerException {
try {
// ignore SSL certificate info with the below two setting:
// 1. trust https server certificate always.
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {
return true;
}
}).build();
// 2. hostname verifier pass
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
return new PoolingHttpClientConnectionManager(socketFactoryRegistry);
} catch (Exception e) {
throw new HttpCallerException("Failed to create httpclient: " + e.getMessage(), e);
}
}
use of com.alibaba.csb.sdk.HttpCallerException in project csb-sdk by aliyun.
the class HttpClientHelper method getUrlPathInfo.
public static String getUrlPathInfo(String url) throws HttpCallerException {
URL urlStr = null;
try {
urlStr = new URL(url);
} catch (Exception e) {
throw new HttpCallerException("url is unformat, url is " + url);
}
String path = urlStr.getPath();
return path;
}
Aggregations