List of usage examples for org.apache.http.impl.conn SchemeRegistryFactory createSystemDefault
public static SchemeRegistry createSystemDefault()
From source file:org.sonatype.nexus.client.rest.jersey.NexusClientFactoryImpl.java
protected ApacheHttpClient4 doCreateHttpClientFor(final ConnectionInfo connectionInfo, final XStream xstream) { final ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new XStreamXmlProvider(xstream, APPLICATION_XML_UTF8_TYPE)); // set _real_ URL for baseUrl, and not a redirection (typically http instead of https) config.getProperties().put(PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE); applyAuthenticationIfAny(connectionInfo, config); applyProxyIfAny(connectionInfo, config); // obey JSSE defined system properties config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault())); final ApacheHttpClient4 client = ApacheHttpClient4.create(config); // set UA//from ww w . ja va2 s . c o m client.getClientHandler().getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Nexus-Client/" + discoverClientVersion()); // "tweak" HTTPS scheme as requested final TrustStrategy trustStrategy; switch (connectionInfo.getSslCertificateValidation()) { case NONE: trustStrategy = new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }; break; case LAX: trustStrategy = new TrustSelfSignedStrategy(); break; default: trustStrategy = null; } final X509HostnameVerifier hostnameVerifier; switch (connectionInfo.getSslCertificateHostnameValidation()) { case NONE: hostnameVerifier = new AllowAllHostnameVerifier(); break; case STRICT: hostnameVerifier = new StrictHostnameVerifier(); break; default: hostnameVerifier = new BrowserCompatHostnameVerifier(); } try { final SSLSocketFactory ssf = new SSLSocketFactory(trustStrategy, hostnameVerifier); final Scheme tweakedHttpsScheme = new Scheme("https", 443, ssf); client.getClientHandler().getHttpClient().getConnectionManager().getSchemeRegistry() .register(tweakedHttpsScheme); } catch (Exception e) { Throwables.propagate(e); } // NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient enforceProxyUri(config, client); if (LOG.isDebugEnabled()) { client.addFilter(new LoggingFilter()); } client.addFilter(new RequestFilters()); return client; }
From source file:org.graphity.core.util.jena.HttpOp.java
/** Create an HttpClient that performs connection pooling. This can be used * with {@link #setDefaultHttpClient} or provided in the HttpOp calls. *///from www . j a v a 2 s . com public static HttpClient createCachingHttpClient() { return new SystemDefaultHttpClient() { /** See SystemDefaultHttpClient (4.2). This version always sets the connection cache */ @Override protected ClientConnectionManager createClientConnectionManager() { PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager( SchemeRegistryFactory.createSystemDefault()); String s = System.getProperty("http.maxConnections", "5"); int max = Integer.parseInt(s); connmgr.setDefaultMaxPerRoute(max); connmgr.setMaxTotal(2 * max); return connmgr; } }; }