Search in sources :

Example 46 with HttpHost

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

the class AbstractPoolEntry method open.

/**
     * Opens the underlying connection.
     *
     * @param route         the route along which to open the connection
     * @param context       the context for opening the connection
     * @param params        the parameters for opening the connection
     *
     * @throws IOException  in case of a problem
     */
public void open(HttpRoute route, HttpContext context, HttpParams params) throws IOException {
    if (route == null) {
        throw new IllegalArgumentException("Route must not be null.");
    }
    //@@@ is context allowed to be null? depends on operator?
    if (params == null) {
        throw new IllegalArgumentException("Parameters must not be null.");
    }
    if ((this.tracker != null) && this.tracker.isConnected()) {
        throw new IllegalStateException("Connection already open.");
    }
    // - collect the arguments
    // - call the operator
    // - update the tracking data
    // In this order, we can be sure that only a successful
    // opening of the connection will be tracked.
    //@@@ verify route against planned route?
    this.tracker = new RouteTracker(route);
    final HttpHost proxy = route.getProxyHost();
    connOperator.openConnection(this.connection, (proxy != null) ? proxy : route.getTargetHost(), route.getLocalAddress(), context, params);
    // capture volatile        
    RouteTracker localTracker = tracker;
    // fail early.
    if (localTracker == null) {
        throw new IOException("Request aborted");
    }
    if (proxy == null) {
        localTracker.connectTarget(this.connection.isSecure());
    } else {
        localTracker.connectProxy(proxy, this.connection.isSecure());
    }
}
Also used : HttpHost(org.apache.http.HttpHost) IOException(java.io.IOException) RouteTracker(org.apache.http.conn.routing.RouteTracker)

Example 47 with HttpHost

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

the class AbstractPoolEntry method layerProtocol.

// tunnelProxy
/**
     * Layers a protocol on top of an established tunnel.
     *
     * @param context   the context for layering
     * @param params    the parameters for layering
     *
     * @throws IOException  in case of a problem
     */
public void layerProtocol(HttpContext context, HttpParams params) throws IOException {
    //@@@ is context allowed to be null? depends on operator?
    if (params == null) {
        throw new IllegalArgumentException("Parameters must not be null.");
    }
    if ((this.tracker == null) || !this.tracker.isConnected()) {
        throw new IllegalStateException("Connection not open.");
    }
    if (!this.tracker.isTunnelled()) {
        //@@@ allow this?
        throw new IllegalStateException("Protocol layering without a tunnel not supported.");
    }
    if (this.tracker.isLayered()) {
        throw new IllegalStateException("Multiple protocol layering not supported.");
    }
    // - collect the arguments
    // - call the operator
    // - update the tracking data
    // In this order, we can be sure that only a successful
    // layering on top of the connection will be tracked.
    final HttpHost target = tracker.getTargetHost();
    connOperator.updateSecureConnection(this.connection, target, context, params);
    this.tracker.layerProtocol(this.connection.isSecure());
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 48 with HttpHost

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

the class DefaultHttpRoutePlanner method determineRoute.

// non-javadoc, see interface HttpRoutePlanner
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    if (request == null) {
        throw new IllegalStateException("Request must not be null.");
    }
    // If we have a forced route, we can do without a target.
    HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
    if (route != null)
        return route;
    if (target == null) {
        throw new IllegalStateException("Target host must not be null.");
    }
    final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
    final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());
    final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
    // as it is typically used for TLS/SSL, we assume that
    // a layered scheme implies a secure connection
    final boolean secure = schm.isLayered();
    if (proxy == null) {
        route = new HttpRoute(target, local, secure);
    } else {
        route = new HttpRoute(target, local, proxy, secure);
    }
    return route;
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute) Scheme(org.apache.http.conn.scheme.Scheme) HttpHost(org.apache.http.HttpHost) InetAddress(java.net.InetAddress)

Example 49 with HttpHost

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

the class ProxySelectorRoutePlanner method determineRoute.

// non-javadoc, see interface HttpRoutePlanner
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    if (request == null) {
        throw new IllegalStateException("Request must not be null.");
    }
    // If we have a forced route, we can do without a target.
    HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
    if (route != null)
        return route;
    if (target == null) {
        throw new IllegalStateException("Target host must not be null.");
    }
    final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
    // BEGIN android-changed
    //     If the client or request explicitly specifies a proxy (or no
    //     proxy), prefer that over the ProxySelector's VM-wide default.
    HttpHost proxy = (HttpHost) request.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY);
    if (proxy == null) {
        proxy = determineProxy(target, request, context);
    } else if (ConnRouteParams.NO_HOST.equals(proxy)) {
        // value is explicitly unset
        proxy = null;
    }
    // END android-changed
    final Scheme schm = this.schemeRegistry.getScheme(target.getSchemeName());
    // as it is typically used for TLS/SSL, we assume that
    // a layered scheme implies a secure connection
    final boolean secure = schm.isLayered();
    if (proxy == null) {
        route = new HttpRoute(target, local, secure);
    } else {
        route = new HttpRoute(target, local, proxy, secure);
    }
    return route;
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute) Scheme(org.apache.http.conn.scheme.Scheme) HttpHost(org.apache.http.HttpHost) InetAddress(java.net.InetAddress)

Example 50 with HttpHost

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

the class HttpRoute method toChain.

/**
     * Helper to duplicate and check a proxy chain.
     * An empty proxy chain is converted to <code>null</code>.
     *
     * @param proxies   the proxy chain to duplicate, or <code>null</code>
     *
     * @return  a new proxy chain array, or <code>null</code>
     */
private static HttpHost[] toChain(HttpHost[] proxies) {
    if ((proxies == null) || (proxies.length < 1))
        return null;
    for (HttpHost proxy : proxies) {
        if (proxy == null)
            throw new IllegalArgumentException("Proxy chain may not contain null elements.");
    }
    // copy the proxy chain, the traditional way
    HttpHost[] result = new HttpHost[proxies.length];
    System.arraycopy(proxies, 0, result, 0, proxies.length);
    return result;
}
Also used : HttpHost(org.apache.http.HttpHost)

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