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