use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project brave by openzipkin.
the class HttpAdapterTest method parseServerAddress_doesntNsLookup.
@Test
public void parseServerAddress_doesntNsLookup() {
when(request.getTarget()).thenReturn(new HttpHost("localhost"));
assertThat(adapter.parseServerAddress(request, Endpoint.newBuilder())).isFalse();
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project fabric8 by jboss-fuse.
the class ConfigurableHttpWagon method execute.
@Override
protected CloseableHttpResponse execute(HttpUriRequest httpMethod) throws HttpException, IOException {
setHeaders(httpMethod);
String userAgent = getUserAgent(httpMethod);
if (userAgent != null) {
httpMethod.setHeader(HTTP.USER_AGENT, userAgent);
}
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
// WAGON-273: default the cookie-policy to browser compatible
requestConfigBuilder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
Repository repo = getRepository();
ProxyInfo proxyInfo = getProxyInfo(repo.getProtocol(), repo.getHost());
if (proxyInfo != null) {
HttpHost proxy = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
requestConfigBuilder.setProxy(proxy);
}
HttpMethodConfiguration config = getHttpConfiguration() == null ? null : getHttpConfiguration().getMethodConfiguration(httpMethod);
if (config != null) {
copyConfig(config, requestConfigBuilder);
} else {
requestConfigBuilder.setSocketTimeout(getReadTimeout());
requestConfigBuilder.setConnectTimeout(getTimeout());
}
getLocalContext().setRequestConfig(requestConfigBuilder.build());
if (config != null && config.isUsePreemptive()) {
HttpHost targetHost = new HttpHost(repo.getHost(), repo.getPort(), repo.getProtocol());
AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
if (getCredentialsProvider().getCredentials(targetScope) != null) {
BasicScheme targetAuth = new BasicScheme();
targetAuth.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC preemptive"));
getAuthCache().put(targetHost, targetAuth);
}
}
if (proxyInfo != null) {
if (proxyInfo.getHost() != null) {
HttpHost proxyHost = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
AuthScope proxyScope = getProxyBasicAuthScope().getScope(proxyHost);
String proxyUsername = proxyInfo.getUserName();
String proxyPassword = proxyInfo.getPassword();
String proxyNtlmHost = proxyInfo.getNtlmHost();
String proxyNtlmDomain = proxyInfo.getNtlmDomain();
if (proxyUsername != null && proxyPassword != null) {
Credentials creds;
if (proxyNtlmHost != null || proxyNtlmDomain != null) {
creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain);
} else {
creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
}
getCredentialsProvider().setCredentials(proxyScope, creds);
BasicScheme proxyAuth = new BasicScheme();
proxyAuth.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC preemptive"));
getAuthCache().put(proxyHost, proxyAuth);
}
}
}
return client.execute(httpMethod, getLocalContext());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project vorto by eclipse.
the class RestClient method getProxyConfiguration.
private ProxyConfiguration getProxyConfiguration() {
IProxyService proxyService = getProxyService();
IProxyData[] proxyDataForHost = proxyService.select(java.net.URI.create(connectionInfo.getUrl()));
CredentialsProvider credsProvider = new BasicCredentialsProvider();
RequestConfig.Builder configBuilder = RequestConfig.custom();
for (IProxyData data : proxyDataForHost) {
if (!Strings.isNullOrEmpty(data.getHost())) {
HttpHost proxyConfig = new HttpHost(data.getHost(), data.getPort(), data.getType());
configBuilder.setProxy(proxyConfig);
if (!Strings.isNullOrEmpty(data.getUserId())) {
credsProvider.setCredentials(new AuthScope(data.getHost(), data.getPort()), new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
}
}
}
return new ProxyConfiguration(configBuilder.build(), credsProvider);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project fdroidclient by f-droid.
the class SwapService method askServerToSwapWithUs.
private void askServerToSwapWithUs(final String address) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... args) {
Uri repoUri = Uri.parse(address);
String swapBackUri = Utils.getLocalRepoUri(FDroidApp.repo).toString();
AndroidHttpClient client = AndroidHttpClient.newInstance("F-Droid", SwapService.this);
HttpPost request = new HttpPost("/request-swap");
HttpHost host = new HttpHost(repoUri.getHost(), repoUri.getPort(), repoUri.getScheme());
try {
Utils.debugLog(TAG, "Asking server at " + address + " to swap with us in return (by POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\")...");
populatePostParams(swapBackUri, request);
client.execute(host, request);
} catch (IOException e) {
notifyOfErrorOnUiThread();
Log.e(TAG, "Error while asking server to swap with us", e);
} finally {
client.close();
}
return null;
}
private void populatePostParams(String swapBackUri, HttpPost request) throws UnsupportedEncodingException {
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("repo", swapBackUri));
UrlEncodedFormEntity encodedParams = new UrlEncodedFormEntity(params);
request.setEntity(encodedParams);
}
private void notifyOfErrorOnUiThread() {
// TODO: Broadcast error message so that whoever wants to can display a relevant
// message in the UI. This service doesn't understand the concept of UI.
/*runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(
SwapService.this,
R.string.swap_reciprocate_failed,
Toast.LENGTH_LONG
).show();
}
});*/
}
}.execute();
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpHost in project coprhd-controller by CoprHD.
the class EncryptedHttpRequestExecutor method getHandler.
/**
* Retrieves the handler for the connection, or creates a new one.
*
* @param message
* the message to process
* @param conn
* the connection to retrieve the handler for
* @param context
* the context to retrieve the handler for
* @return an encrypted request handler that can process the message, or null if one doesn't exist
*/
private EncryptedRequestHandler getHandler(HttpMessage message, HttpClientConnection conn, HttpContext context) {
// This is our guarantee of unicity. We are unable to use connection, because it changes occasionally.
HttpHost host = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
if (host == null) {
throw new RuntimeException("Context does not contain a host.");
}
EncryptedRequestHandler handler = handlers.get(host);
if (handler == null || !handler.accepts(message)) {
handler = null;
handlers.remove(host);
for (EncryptedRequestHandler h : getAvailableHandlers()) {
if (h.accepts(message)) {
handler = h;
handlers.put(host, handler);
break;
}
}
}
return handler;
}
Aggregations