Search in sources :

Example 96 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project keycloak by keycloak.

the class HttpClientBuilder method configureProxyForAuthServerIfProvided.

/**
 * Configures a the proxy to use for auth-server requests if provided.
 * <p>
 * If the given {@link AdapterHttpClientConfig} contains the attribute {@code proxy-url} we use the
 * given URL as a proxy server, otherwise the proxy configuration is ignored.
 * </p>
 *
 * @param adapterConfig
 */
private void configureProxyForAuthServerIfProvided(AdapterHttpClientConfig adapterConfig) {
    if (adapterConfig == null || adapterConfig.getProxyUrl() == null || adapterConfig.getProxyUrl().trim().isEmpty()) {
        return;
    }
    URI uri = URI.create(adapterConfig.getProxyUrl());
    this.proxyHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
}
Also used : HttpHost(org.apache.http.HttpHost) URI(java.net.URI)

Example 97 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project keycloak by keycloak.

the class ProxyMappingsAwareRoutePlanner method determineProxy.

@Override
protected HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    String targetHostName = target.getHostName();
    ProxyMapping proxyMapping = proxyMappings.getProxyFor(targetHostName);
    LOG.debugf("Returning proxyMapping=%s for targetHost=%s", proxyMapping, targetHostName);
    UsernamePasswordCredentials proxyCredentials = proxyMapping.getProxyCredentials();
    HttpHost proxyHost = proxyMapping.getProxyHost();
    if (proxyCredentials != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), proxyCredentials);
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider);
    }
    return proxyHost;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 98 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project crawler4j by yasserg.

the class BasicAuthHttpRequestInterceptor method process.

@Override
public void process(HttpRequest request, HttpContext context) {
    AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
    if (authState.getAuthScheme() == null) {
        CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
        HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
        Credentials credentials = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
        if (credentials != null) {
            authState.update(new BasicScheme(), credentials);
        }
    }
}
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 99 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project apollo by ctripcorp.

the class RetryableRestTemplateTest method init.

@Before
public void init() {
    socketTimeoutException.initCause(new SocketTimeoutException());
    httpHostConnectException.initCause(new HttpHostConnectException(new ConnectTimeoutException(), new HttpHost(serviceOne, 80)));
    connectTimeoutException.initCause(new ConnectTimeoutException());
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) HttpHost(org.apache.http.HttpHost) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Before(org.junit.Before)

Example 100 with HttpHost

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project quick-media by liuyueyi.

the class HttpUtil method downFile.

/**
 * 从网络上下载文件
 *
 * @param uri
 * @return
 * @throws IOException
 */
public static InputStream downFile(URI uri) throws IOException {
    HttpResponse httpResponse;
    try {
        Request request = Request.Get(uri);
        HttpHost httpHost = URIUtils.extractHost(uri);
        if (StringUtils.isNotEmpty(httpHost.getHostName())) {
            request.setHeader("Host", httpHost.getHostName());
        }
        request.addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
        httpResponse = request.execute().returnResponse();
    } catch (Exception e) {
        log.error("远程请求失败,url=" + uri, e);
        throw new FileNotFoundException();
    }
    int code = httpResponse.getStatusLine().getStatusCode();
    if (code != 200) {
        throw new FileNotFoundException();
    }
    return httpResponse.getEntity().getContent();
}
Also used : HttpHost(org.apache.http.HttpHost) Request(org.apache.http.client.fluent.Request) FileNotFoundException(java.io.FileNotFoundException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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