use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project openstack4j by ContainX.
the class ApacheHttpClientExecutor method create.
public static ApacheHttpClientExecutor create(Config config) {
HttpParams params = new BasicHttpParams();
if (config.getReadTimeout() > 0)
HttpConnectionParams.setSoTimeout(params, config.getReadTimeout());
if (config.getConnectTimeout() > 0)
HttpConnectionParams.setConnectionTimeout(params, config.getConnectTimeout());
HttpClient client = new DefaultHttpClient(params);
if (config.getProxy() != null) {
try {
URL url = new URL(config.getProxy().getHost());
HttpHost proxy = new HttpHost(url.getHost(), config.getProxy().getPort(), url.getProtocol());
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return new ApacheHttpClientExecutor(client);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project sling by apache.
the class HttpServerRule method before.
@Override
protected void before() throws Throwable {
final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(5000).build();
serverBootstrap = ServerBootstrap.bootstrap().setSocketConfig(socketConfig).setServerInfo(ORIGIN);
if (ProtocolScheme.https.equals(protocolScheme)) {
serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
}
registerHandlers();
server = serverBootstrap.create();
server.start();
host = new HttpHost("127.0.0.1", server.getLocalPort(), protocolScheme.name());
uri = URIUtils.rewriteURI(new URI("/"), host);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project sling by apache.
the class PreemptiveAuthInterceptor method process.
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
// If not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
Credentials creds = credsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project sling by apache.
the class HttpServerRule method before.
@Override
protected void before() throws Throwable {
final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(5000).build();
serverBootstrap = ServerBootstrap.bootstrap().setSocketConfig(socketConfig).setServerInfo(ORIGIN);
if (ProtocolScheme.https.equals(protocolScheme)) {
serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
}
registerHandlers();
server = serverBootstrap.create();
server.start();
host = new HttpHost("127.0.0.1", server.getLocalPort(), protocolScheme.name());
uri = URIUtils.rewriteURI(new URI("/"), host);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project opennms by OpenNMS.
the class ScvEnabledRestClientImpl method getResponse.
// Setup a client with pre-emptive authentication
private CloseableHttpResponse getResponse(HttpGet httpget) throws Exception {
CloseableHttpResponse response = null;
HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(target.getHostName(), target.getPort()), getCredentials());
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(target, basicAuth);
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
response = httpclient.execute(target, httpget, localContext);
return response;
}
Aggregations