use of org.apache.http.params.HttpParams in project 12306-hunter by xautlx.
the class HttpClientService method buildHttpClient.
/**
* 构建HttpClient对象
*
* @return
*/
public static HttpClient buildHttpClient() {
try {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(sslcontext);
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 8000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 8000);
HttpClient httpclient = new DefaultHttpClient(ccm, params);
httpclient.getParams().setParameter(HTTP.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
return httpclient;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
use of org.apache.http.params.HttpParams in project tdi-studio-se by Talend.
the class paloconnection method initConnection.
private void initConnection() {
pingPaloServer();
paloTargetHost = new HttpHost(strServer, Integer.valueOf(strPort), "http");
SchemeRegistry supportedSchemes = new SchemeRegistry();
supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Integer.valueOf(strPort)));
// prepare parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, true);
ClientConnectionManager connMgr = new ThreadSafeClientConnManager(params, supportedSchemes);
paloHttpClient = new DefaultHttpClient(connMgr, params);
}
use of org.apache.http.params.HttpParams in project tdi-studio-se by Talend.
the class WsdlTokenManager method getSOAPResponse.
private static String getSOAPResponse(URI issuerUri, String soapEnvelope) {
HttpResponse response = null;
// Create the request that will submit the request to the server
try {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
HttpClient client = new SystemDefaultHttpClient(params);
HttpPost post = new HttpPost(issuerUri);
StringEntity entity = new StringEntity(soapEnvelope);
post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
post.setEntity(entity);
response = client.execute(post);
return EntityUtils.toString(response.getEntity());
} catch (ClientProtocolException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}
return null;
}
use of org.apache.http.params.HttpParams in project java-chassis by ServiceComb.
the class HttpsClient method getHttpsClient.
public static HttpClient getHttpsClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
registry.register(new Scheme("https", sf, PORT_443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (RuntimeException e) {
LOGGER.error("Get https client runtime exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
} catch (Exception e) {
LOGGER.error("Get https client exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
}
}
use of org.apache.http.params.HttpParams in project Libraries-for-Android-Developers by eoecn.
the class AsyncHttpClient method setProxy.
/**
* Sets the Proxy by it's hostname and port
*
* @param hostname the hostname (IP or DNS name)
* @param port the port number. -1 indicates the scheme default port.
*/
public void setProxy(String hostname, int port) {
final HttpHost proxy = new HttpHost(hostname, port);
final HttpParams httpParams = this.httpClient.getParams();
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
Aggregations