Search in sources :

Example 1 with SchemePortResolver

use of org.apache.http.conn.SchemePortResolver in project oxCore by GluuFederation.

the class WebDavDocumentStoreProvider method createHttpClient.

private HttpClient createHttpClient(UsernamePasswordCredentials credentials, int timeoutInMillis) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // credentialsProvider.setCredentials(AuthScope.ANY, credentials);
    credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), credentials);
    SchemePortResolver portResolver = new DefaultSchemePortResolver() {

        @Override
        public int resolve(final HttpHost host) throws UnsupportedSchemeException {
            Args.notNull(host, "HTTP host");
            final int port = host.getPort();
            if (port > 0) {
                return port;
            }
            final String name = host.getSchemeName();
            if (name.equalsIgnoreCase("http")) {
                return 8080;
            } else if (name.equalsIgnoreCase("https")) {
                return 8443;
            }
            return super.resolve(host);
        }
    };
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).setSocketTimeout(timeoutInMillis).setExpectContinueEnabled(false).build()).setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(cm).build();
    // Increase max total connection to 50
    cm.setMaxTotal(50);
    // Increase default max connection per route to 10
    cm.setDefaultMaxPerRoute(10);
    context.setCredentialsProvider(credentialsProvider);
    return httpClient;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) DefaultSchemePortResolver(org.apache.http.impl.conn.DefaultSchemePortResolver) AuthScope(org.apache.http.auth.AuthScope) SchemePortResolver(org.apache.http.conn.SchemePortResolver) DefaultSchemePortResolver(org.apache.http.impl.conn.DefaultSchemePortResolver) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 SchemePortResolver (org.apache.http.conn.SchemePortResolver)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultSchemePortResolver (org.apache.http.impl.conn.DefaultSchemePortResolver)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1