Example usage for org.apache.http.impl.conn DefaultSchemePortResolver INSTANCE

List of usage examples for org.apache.http.impl.conn DefaultSchemePortResolver INSTANCE

Introduction

In this page you can find the example usage for org.apache.http.impl.conn DefaultSchemePortResolver INSTANCE.

Prototype

DefaultSchemePortResolver INSTANCE

To view the source code for org.apache.http.impl.conn DefaultSchemePortResolver INSTANCE.

Click Source Link

Usage

From source file:org.keycloak.connections.httpclient.ProxyMappingsAwareRoutePlanner.java

public ProxyMappingsAwareRoutePlanner(ProxyMappings proxyMappings) {
    super(DefaultSchemePortResolver.INSTANCE);
    this.proxyMappings = proxyMappings;
}

From source file:com.ksc.http.apache.SdkProxyRoutePlanner.java

public SdkProxyRoutePlanner(String proxyHost, int proxyPort, String nonProxyHosts) {
    super(DefaultSchemePortResolver.INSTANCE);
    proxy = new HttpHost(proxyHost, proxyPort);
    parseNonProxyHosts(nonProxyHosts);//from   w w  w.  jav  a2  s.co  m
}

From source file:org.sonatype.nexus.httpclient.internal.NexusHttpRoutePlanner.java

/**
 * @since 2.5/*ww w .  j  ava 2 s .  com*/
 */
public NexusHttpRoutePlanner(final Map<String, HttpHost> proxies,
        @Nullable final Pattern nonProxyHostsPattern) {
    super(DefaultSchemePortResolver.INSTANCE);
    this.proxies = checkNotNull(proxies);
    this.nonProxyHostPattern = nonProxyHostsPattern;
}

From source file:com.ksc.http.apache.client.impl.ApacheConnectionManagerFactory.java

@Override
public HttpClientConnectionManager create(final HttpClientSettings settings) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings);

    final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf), null, DefaultSchemePortResolver.INSTANCE,
            new DelegatingDnsResolver(settings.getDnsResolver()), settings.getConnectionPoolTTL(),
            TimeUnit.MILLISECONDS);

    cm.setDefaultMaxPerRoute(settings.getMaxConnections());
    cm.setMaxTotal(settings.getMaxConnections());
    cm.setDefaultSocketConfig(buildSocketConfig(settings));
    cm.setDefaultConnectionConfig(buildConnectionConfig(settings));

    return cm;//from   ww w.  j  ava2  s . co  m
}

From source file:org.callimachusproject.client.ProxyClientExecDecorator.java

private HttpHost key(HttpHost host) {
    if (host != null && host.getPort() < 0) {
        try {/* w  w w  .j  a  v a  2s . co  m*/
            int port = DefaultSchemePortResolver.INSTANCE.resolve(host);
            host = new HttpHost(host.getHostName(), port, host.getSchemeName());
        } catch (UnsupportedSchemeException e) {
            throw new AssertionError(e);
        }
    }
    return host;
}

From source file:com.github.caldav4j.functional.support.CalDavFixture.java

private static HttpClient configureHttpClient(final CaldavCredential credential) {
    // HttpClient 4 requires a Cred providers, to be added during creation of client
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(credential.user, credential.password));

    // Default Host setting
    HttpRoutePlanner routePlanner = new DefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE) {

        @Override//from  w ww.j av  a  2 s . c om
        public HttpRoute determineRoute(final HttpHost target, final HttpRequest request,
                final HttpContext context) throws HttpException {
            return super.determineRoute(
                    target != null ? target
                            : new HttpHost(credential.host, credential.port, credential.protocol),
                    request, context);
        }

    };

    HttpClientBuilder builder = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
            .setRoutePlanner(routePlanner);

    if (credential.getProxyHost() != null) {
        builder.setProxy(new HttpHost(credential.getProxyHost(),
                (credential.getProxyPort() > 0) ? credential.getProxyPort() : 8080));
    }

    return builder.build();
}

From source file:org.sonatype.nexus.repository.httpclient.HttpClientFactoryImpl.java

@VisibleForTesting
public void applyProxyConfig(final Builder builder, final HttpClientConfig config) {
    if (config.getProxy() != null && config.getProxy().getHttp() != null) {
        Map<String, HttpHost> proxies = Maps.newHashMap();

        HttpProxyConfig httpProxyConfig = config.getProxy().getHttp();
        HttpHost httpProxy = new HttpHost(httpProxyConfig.getHostname(), httpProxyConfig.getPort());
        applyAuthenticationConfig(builder, httpProxyConfig.getAuthentication(), httpProxy);

        log.debug("http proxy setup with host '{}'", httpProxyConfig.getHostname());
        proxies.put("http", httpProxy);
        proxies.put("https", httpProxy);

        if (config.getProxy().getHttps() != null) {
            HttpProxyConfig httpsProxyConfig = config.getProxy().getHttps();
            HttpHost httpsProxy = new HttpHost(httpsProxyConfig.getHostname(), httpsProxyConfig.getPort());
            applyAuthenticationConfig(builder, httpsProxyConfig.getAuthentication(), httpsProxy);
            log.debug("https proxy setup with host '{}'", httpsProxy.getHostName());
            proxies.put("https", httpsProxy);
        }/* ww  w  .j  a  va  2s  .  c o  m*/

        final Set<Pattern> nonProxyHostPatterns = Sets.newHashSet();
        if (config.getProxy().getNonProxyHosts() != null) {
            for (String nonProxyHostRegex : config.getProxy().getNonProxyHosts()) {
                try {
                    nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE));
                } catch (PatternSyntaxException e) {
                    log.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }
            }
        }

        builder.getHttpClientBuilder().setRoutePlanner(
                new NexusHttpRoutePlanner(proxies, nonProxyHostPatterns, DefaultSchemePortResolver.INSTANCE));
    }
}

From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.RemoteStorageContextCustomizer.java

@VisibleForTesting
public void applyProxyConfig(final Builder builder, final RemoteProxySettings remoteProxySettings) {
    if (remoteProxySettings != null && remoteProxySettings.getHttpProxySettings() != null
            && remoteProxySettings.getHttpProxySettings().isEnabled()) {
        final Map<String, HttpHost> proxies = Maps.newHashMap();

        final HttpHost httpProxy = new HttpHost(remoteProxySettings.getHttpProxySettings().getHostname(),
                remoteProxySettings.getHttpProxySettings().getPort());
        applyAuthenticationConfig(builder, remoteProxySettings.getHttpProxySettings().getProxyAuthentication(),
                httpProxy);/*from w  w w.jav a 2  s. c o m*/

        log.debug("http proxy setup with host '{}'", remoteProxySettings.getHttpProxySettings().getHostname());
        proxies.put("http", httpProxy);
        proxies.put("https", httpProxy);

        if (remoteProxySettings.getHttpsProxySettings() != null
                && remoteProxySettings.getHttpsProxySettings().isEnabled()) {
            final HttpHost httpsProxy = new HttpHost(remoteProxySettings.getHttpsProxySettings().getHostname(),
                    remoteProxySettings.getHttpsProxySettings().getPort());
            applyAuthenticationConfig(builder,
                    remoteProxySettings.getHttpsProxySettings().getProxyAuthentication(), httpsProxy);
            log.debug("https proxy setup with host '{}'",
                    remoteProxySettings.getHttpsProxySettings().getHostname());
            proxies.put("https", httpsProxy);
        }

        final Set<Pattern> nonProxyHostPatterns = Sets.newHashSet();
        if (remoteProxySettings.getNonProxyHosts() != null
                && !remoteProxySettings.getNonProxyHosts().isEmpty()) {
            for (String nonProxyHostRegex : remoteProxySettings.getNonProxyHosts()) {
                try {
                    nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE));
                } catch (PatternSyntaxException e) {
                    log.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }
            }
        }

        builder.getHttpClientBuilder().setRoutePlanner(
                new NexusHttpRoutePlanner(proxies, nonProxyHostPatterns, DefaultSchemePortResolver.INSTANCE));
    }
}

From source file:org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory.java

public synchronized void setupNIOClient(HTTPClientPolicy clientPolicy) throws IOReactorException {
    if (client != null) {
        return;//from w ww  . j av  a2  s  .co m
    }

    IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(ioThreadCount)
            .setSelectInterval(selectInterval).setInterestOpQueued(interestOpQueued).setSoLinger(soLinger)
            .setSoTimeout(soTimeout).setSoKeepAlive(soKeepalive).setTcpNoDelay(tcpNoDelay).build();

    Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry = RegistryBuilder
            .<SchemeIOSessionStrategy>create().register("http", NoopIOSessionStrategy.INSTANCE)
            .register("https", SSLIOSessionStrategy.getSystemDefaultStrategy()).build();

    ManagedNHttpClientConnectionFactory connectionFactory = new ManagedNHttpClientConnectionFactory() {

        @Override
        public ManagedNHttpClientConnection create(final IOSession iosession, final ConnectionConfig config) {
            ManagedNHttpClientConnection conn = super.create(iosession, config);
            return conn;
        }
    };

    DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor(config);
    connectionManager = new PoolingNHttpClientConnectionManager(ioreactor, connectionFactory,
            ioSessionFactoryRegistry, DefaultSchemePortResolver.INSTANCE, SystemDefaultDnsResolver.INSTANCE,
            connectionTTL, TimeUnit.MILLISECONDS);

    connectionManager.setDefaultMaxPerRoute(maxPerRoute);
    connectionManager.setMaxTotal(maxConnections);

    ConnectionConfig connectionConfig = ConnectionConfig.custom()
            .setBufferSize(clientPolicy.getChunkLength() > 0 ? clientPolicy.getChunkLength() : 16332).build();

    connectionManager.setDefaultConnectionConfig(connectionConfig);

    RedirectStrategy redirectStrategy = new RedirectStrategy() {

        public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)
                throws ProtocolException {
            return false;
        }

        public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
                throws ProtocolException {
            return null;
        }
    };

    HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom()
            .setConnectionManager(connectionManager).setRedirectStrategy(redirectStrategy)
            .setDefaultCookieStore(new BasicCookieStore() {
                private static final long serialVersionUID = 1L;

                public void addCookie(Cookie cookie) {
                }
            });

    adaptClientBuilder(httpAsyncClientBuilder);

    client = httpAsyncClientBuilder.build();
    // Start the client thread
    client.start();
    if (this.connectionTTL == 0) {
        //if the connection does not have an expiry deadline
        //use the ConnectionMaxIdle to close the idle connection
        new CloseIdleConnectionThread(connectionManager, client).start();
    }
}

From source file:org.sonatype.nexus.apachehttpclient.Hc4ProviderBase.java

/**
 * @since 2.6/*from  w  w  w.j av  a2  s  .c  om*/
 */
protected void applyProxyConfig(final Builder builder, final RemoteProxySettings remoteProxySettings) {
    if (remoteProxySettings != null && remoteProxySettings.getHttpProxySettings() != null
            && remoteProxySettings.getHttpProxySettings().isEnabled()) {
        final Map<String, HttpHost> proxies = Maps.newHashMap();

        final HttpHost httpProxy = new HttpHost(remoteProxySettings.getHttpProxySettings().getHostname(),
                remoteProxySettings.getHttpProxySettings().getPort());
        applyAuthenticationConfig(builder, remoteProxySettings.getHttpProxySettings().getProxyAuthentication(),
                httpProxy);

        log.debug("http proxy setup with host '{}'", remoteProxySettings.getHttpProxySettings().getHostname());
        proxies.put("http", httpProxy);
        proxies.put("https", httpProxy);

        if (remoteProxySettings.getHttpsProxySettings() != null
                && remoteProxySettings.getHttpsProxySettings().isEnabled()) {
            final HttpHost httpsProxy = new HttpHost(remoteProxySettings.getHttpsProxySettings().getHostname(),
                    remoteProxySettings.getHttpsProxySettings().getPort());
            applyAuthenticationConfig(builder,
                    remoteProxySettings.getHttpsProxySettings().getProxyAuthentication(), httpsProxy);
            log.debug("https proxy setup with host '{}'",
                    remoteProxySettings.getHttpsProxySettings().getHostname());
            proxies.put("https", httpsProxy);
        }

        final Set<Pattern> nonProxyHostPatterns = Sets.newHashSet();
        if (remoteProxySettings.getNonProxyHosts() != null
                && !remoteProxySettings.getNonProxyHosts().isEmpty()) {
            for (String nonProxyHostRegex : remoteProxySettings.getNonProxyHosts()) {
                try {
                    nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE));
                } catch (PatternSyntaxException e) {
                    log.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }
            }
        }

        builder.getHttpClientBuilder().setRoutePlanner(
                new NexusHttpRoutePlanner(proxies, nonProxyHostPatterns, DefaultSchemePortResolver.INSTANCE));
    }
}