public static DefaultHttpClient getThreadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager mgr = client.getConnectionManager(); HttpParams params = client.getParams(); client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params); return client; }
public void setPortForScheme(String scheme, int port) { Scheme _scheme = new Scheme(scheme, PlainSocketFactory.getSocketFactory(), port); httpClient.getConnectionManager().getSchemeRegistry().register(_scheme); }
@Override protected HttpRoutePlanner createHttpRoutePlanner() { // BEGIN android-changed // Use the proxy specified by system properties return new ProxySelectorRoutePlanner(getConnectionManager().getSchemeRegistry(), null); // END android-changed }
private HttpClient sslClient(HttpClient client) { try { X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[]{tm}, null); SSLSocketFactory ssf = new MySSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, client.getParams()); } catch (Exception ex) { return null; } }
public KylinClient(KylinConnectionInfo connInfo) { this.connInfo = connInfo; this.connProps = connInfo.getConnectionProperties(); this.httpClient = new DefaultHttpClient(); this.jsonMapper = new ObjectMapper(); // trust all certificates if (isSSL()) { try { SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(final X509Certificate[] chain, String authType) throws CertificateException { // Oh, I am easy... return true; } }); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sslsf)); } catch (Exception e) { throw new RuntimeException("Initialize HTTPS client failed", e); } } }
int port = target.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry(). getScheme(target.getSchemeName()); port = scheme.getDefaultPort();
int port = target.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry(). getScheme(target.getSchemeName()); port = scheme.getDefaultPort();
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); DefaultHttpClient sslClient = new DefaultHttpClient(ccm,
int port = host.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry().getScheme(host); port = scheme.getDefaultPort();
@Before public void setUp() { MockitoAnnotations.initMocks(this); HttpParams httpParams = new BasicHttpParams(); when(mockHttpClientFactory.create()).thenReturn(mockHttpClient); when(mockHttpClient.getParams()).thenReturn(httpParams); when(mockHttpClient.getConnectionManager()).thenReturn(mockClientConnectionManager); when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry); storeConfig = createStoreConfig(); serverSettings = createWebDavStoreSettings(ConnectionSecurity.SSL_TLS_REQUIRED); webDavStore = createWebDavStore(); }
int port = host.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry().getScheme(host); port = scheme.getDefaultPort();
public WebDavHttpClient getHttpClient() throws MessagingException { if (httpClient == null) { httpClient = httpClientFactory.create(); // Disable automatic redirects on the http client. httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false); // Setup a cookie store for forms-based authentication. httpContext = new BasicHttpContext(); authCookies = new BasicCookieStore(); httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies); SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry(); try { Scheme s = new Scheme("https", new WebDavSocketFactory(trustManagerFactory, hostname, 443), 443); reg.register(s); } catch (NoSuchAlgorithmException nsa) { Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient"); throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa); } catch (KeyManagementException kme) { Timber.e(kme, "KeyManagementException in getHttpClient"); throw new MessagingException("KeyManagementException in getHttpClient: ", kme); } } return httpClient; }
public SchemeRegistry getSchemeRegistry() { return delegate.getSchemeRegistry(); }
final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext); final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);
ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams());
/** * 默认httpclient * * @see <a * href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a> * @param clientConnectionManager */ public HttpComponent4_1Factory() { PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(); clientConnectionManager.setMaxTotal(30); clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager .getMaxTotal()); httpClient = new DefaultHttpClient(clientConnectionManager); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name()); httpClient.getParams().setParameter( CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET, Consts.UTF_8); SSLSocketFactory socketFactory = new SSLSocketFactory( HttpClientFactory.allowSSLContext()); socketFactory .setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme scheme = new Scheme("https", socketFactory, 443); httpClient.getConnectionManager().getSchemeRegistry().register(scheme); }
/** * Constructor. * @param config the client configuration. */ public ApacheHttpClient(ClientConfiguration config) { HttpClientFactory httpClientFactory = new HttpClientFactory(); httpClient = httpClientFactory.createHttpClient(config); // disable retry ((AbstractHttpClient) httpClient) .setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry(); Scheme https = schemeRegistry.getScheme("https"); ((SSLSocketFactory) https.getSocketFactory()) .setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }
private void resolveHttpParams(HttpParams params) { if (params != null) { if (params.getProxy() != null) { InetSocketAddress socketAddress = (InetSocketAddress) params .getProxy().address(); HttpHost proxy = new HttpHost(socketAddress.getHostName(), socketAddress.getPort()); httpClient.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy); } httpClient.getParams().setIntParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, params.getConnectTimeout()); httpClient.getParams().setIntParameter( CoreConnectionPNames.SO_TIMEOUT, params.getReadTimeout()); if (params.getSSLContext() != null) { SSLSocketFactory socketFactory = new SSLSocketFactory( params.getSSLContext()); if (params.getHostnameVerifier() != null) { socketFactory .setHostnameVerifier(new CustomHostnameVerifier( params.getHostnameVerifier())); } Scheme scheme = new Scheme("https", socketFactory, 443); httpClient.getConnectionManager().getSchemeRegistry() .register(scheme); } } }
protected void acceptAllCertificatesOf(@Nonnull HttpClient client) throws Exception { final SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[]{new X509TrustManagerImpl()}, null); final SSLSocketFactory ssf = new SSLSocketFactory(ctx, ALLOW_ALL_HOSTNAME_VERIFIER); client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, ssf)); }
@Provides @Singleton HttpClient newDefaultHttpClient(ProxyConfig config, BasicHttpParams params, ClientConnectionManager cm) { DefaultHttpClient client = new DefaultHttpClient(cm, params); if (config.useSystem()) { ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(client.getConnectionManager() .getSchemeRegistry(), ProxySelector.getDefault()); client.setRoutePlanner(routePlanner); } return client; }