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;
}
Aggregations