Search in sources :

Example 86 with HttpHost

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();
}
Also used : HttpHost(org.apache.http.HttpHost) Test(org.junit.Test)

Example 87 with HttpHost

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());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpMethodConfiguration(org.apache.maven.wagon.providers.http.HttpMethodConfiguration) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicHeader(org.apache.http.message.BasicHeader) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 88 with HttpHost

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);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) IProxyData(org.eclipse.core.net.proxy.IProxyData) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IProxyService(org.eclipse.core.net.proxy.IProxyService) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 89 with HttpHost

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();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AndroidHttpClient(android.net.http.AndroidHttpClient) Uri(android.net.Uri) HttpHost(org.apache.http.HttpHost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) List(java.util.List) ArrayList(java.util.ArrayList)

Example 90 with HttpHost

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;
}
Also used : HttpHost(org.apache.http.HttpHost) NTLMEncryptedRequestHandler(com.iwave.ext.windows.winrm.ntlm.NTLMEncryptedRequestHandler)

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