Search in sources :

Example 71 with HttpHost

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);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) MalformedURLException(java.net.MalformedURLException) HttpHost(org.apache.http.HttpHost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL)

Example 72 with HttpHost

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);
}
Also used : SocketConfig(org.apache.http.config.SocketConfig) HttpHost(org.apache.http.HttpHost) URI(java.net.URI)

Example 73 with HttpHost

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);
        }
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) AuthState(org.apache.http.auth.AuthState) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials)

Example 74 with HttpHost

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);
}
Also used : SocketConfig(org.apache.http.config.SocketConfig) HttpHost(org.apache.http.HttpHost) URI(java.net.URI)

Example 75 with HttpHost

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;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) AuthScope(org.apache.http.auth.AuthScope) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache)

Aggregations

HttpHost (org.apache.http.HttpHost)598 IOException (java.io.IOException)111 CredentialsProvider (org.apache.http.client.CredentialsProvider)105 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)102 HttpResponse (org.apache.http.HttpResponse)101 AuthScope (org.apache.http.auth.AuthScope)101 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)99 Test (org.junit.Test)86 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)84 URI (java.net.URI)68 HttpGet (org.apache.http.client.methods.HttpGet)66 HttpRequest (org.apache.http.HttpRequest)60 Header (org.apache.http.Header)56 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)56 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)48 HttpEntity (org.apache.http.HttpEntity)47 RequestConfig (org.apache.http.client.config.RequestConfig)45 BasicScheme (org.apache.http.impl.auth.BasicScheme)45 URISyntaxException (java.net.URISyntaxException)44 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)43