use of org.apache.http.conn.scheme.Scheme in project ignition by mttkay.
the class IgnitedHttp method setPortForScheme.
public void setPortForScheme(String scheme, int port) {
Scheme _scheme = new Scheme(scheme, PlainSocketFactory.getSocketFactory(), port);
httpClient.getConnectionManager().getSchemeRegistry().register(_scheme);
}
use of org.apache.http.conn.scheme.Scheme 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.conn.scheme.Scheme in project android_frameworks_base by ResurrectionRemix.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of org.apache.http.conn.scheme.Scheme in project android_frameworks_base by ResurrectionRemix.
the class AbstractProxyTest method testConnectViaHttpProxyToHttps.
private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders());
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via a secure proxy"));
server.play();
HttpClient httpProxyClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpProxyClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, 443));
HttpGet request = new HttpGet("https://android.com/foo");
proxyConfig.configure(server, httpProxyClient, request);
HttpResponse response = httpProxyClient.execute(request);
assertEquals("this response comes via a secure proxy", contentToString(response));
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy " + proxyConfig, "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertContains(connect.getHeaders(), "Host: android.com");
RecordedRequest get = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
assertContains(get.getHeaders(), "Host: android.com");
}
use of org.apache.http.conn.scheme.Scheme 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);
}
Aggregations