Search in sources :

Example 51 with HttpHost

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

the class HttpRoute method hashCode.

/**
     * Generates a hash code for this route.
     *
     * @return  the hash code
     */
@Override
public final int hashCode() {
    int hc = this.targetHost.hashCode();
    if (this.localAddress != null)
        hc ^= localAddress.hashCode();
    if (this.proxyChain != null) {
        hc ^= proxyChain.length;
        for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode();
    }
    if (this.secure)
        hc ^= 0x11111111;
    hc ^= this.tunnelled.hashCode();
    hc ^= this.layered.hashCode();
    return hc;
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 52 with HttpHost

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

the class RouteTracker method getHopTarget.

// non-JavaDoc, see interface RouteInfo
public final HttpHost getHopTarget(int hop) {
    if (hop < 0)
        throw new IllegalArgumentException("Hop index must not be negative: " + hop);
    final int hopcount = getHopCount();
    if (hop >= hopcount) {
        throw new IllegalArgumentException("Hop index " + hop + " exceeds tracked route length " + hopcount + ".");
    }
    HttpHost result = null;
    if (hop < hopcount - 1)
        result = this.proxyChain[hop];
    else
        result = this.targetHost;
    return result;
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 53 with HttpHost

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

the class HttpRoute method toString.

/**
     * Obtains a description of this route.
     *
     * @return  a human-readable representation of this route
     */
@Override
public final String toString() {
    StringBuilder cab = new StringBuilder(50 + getHopCount() * 30);
    cab.append("HttpRoute[");
    if (this.localAddress != null) {
        cab.append(this.localAddress);
        cab.append("->");
    }
    cab.append('{');
    if (this.tunnelled == TunnelType.TUNNELLED)
        cab.append('t');
    if (this.layered == LayerType.LAYERED)
        cab.append('l');
    if (this.secure)
        cab.append('s');
    cab.append("}->");
    if (this.proxyChain != null) {
        for (HttpHost aProxyChain : this.proxyChain) {
            cab.append(aProxyChain);
            cab.append("->");
        }
    }
    cab.append(this.targetHost);
    cab.append(']');
    return cab.toString();
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 54 with HttpHost

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

the class RequestQueue method queueRequest.

protected synchronized void queueRequest(Request request, boolean head) {
    HttpHost host = request.mProxyHost == null ? request.mHost : request.mProxyHost;
    LinkedList<Request> reqList;
    if (mPending.containsKey(host)) {
        reqList = mPending.get(host);
    } else {
        reqList = new LinkedList<Request>();
        mPending.put(host, reqList);
    }
    if (head) {
        reqList.addFirst(request);
    } else {
        reqList.add(request);
    }
}
Also used : HttpHost(org.apache.http.HttpHost)

Example 55 with HttpHost

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

the class ProxySelectorRoutePlanner method determineProxy.

/**
     * Determines a proxy for the given target.
     *
     * @param target    the planned target, never <code>null</code>
     * @param request   the request to be sent, never <code>null</code>
     * @param context   the context, or <code>null</code>
     *
     * @return  the proxy to use, or <code>null</code> for a direct route
     *
     * @throws HttpException
     *         in case of system proxy settings that cannot be handled
     */
protected HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    // the proxy selector can be 'unset', so we better deal with null here
    ProxySelector psel = this.proxySelector;
    if (psel == null)
        psel = ProxySelector.getDefault();
    if (psel == null)
        return null;
    URI targetURI = null;
    try {
        targetURI = new URI(target.toURI());
    } catch (URISyntaxException usx) {
        throw new HttpException("Cannot convert host to URI: " + target, usx);
    }
    List<Proxy> proxies = psel.select(targetURI);
    Proxy p = chooseProxy(proxies, target, request, context);
    HttpHost result = null;
    if (p.type() == Proxy.Type.HTTP) {
        // convert the socket address to an HttpHost
        if (!(p.address() instanceof InetSocketAddress)) {
            throw new HttpException("Unable to handle non-Inet proxy address: " + p.address());
        }
        final InetSocketAddress isa = (InetSocketAddress) p.address();
        // assume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }
    return result;
}
Also used : ProxySelector(java.net.ProxySelector) Proxy(java.net.Proxy) HttpHost(org.apache.http.HttpHost) InetSocketAddress(java.net.InetSocketAddress) HttpException(org.apache.http.HttpException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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