Example usage for org.apache.http.client.params ClientPNames DEFAULT_HOST

List of usage examples for org.apache.http.client.params ClientPNames DEFAULT_HOST

Introduction

In this page you can find the example usage for org.apache.http.client.params ClientPNames DEFAULT_HOST.

Prototype

String DEFAULT_HOST

To view the source code for org.apache.http.client.params ClientPNames DEFAULT_HOST.

Click Source Link

Document

Defines the default host.

Usage

From source file:com.msopentech.thali.utilities.universal.CreateClientBuilder.java

/**
 *
 * @param host/*w ww.  j  ava 2s.  c o  m*/
 * @param port
 * @param serverPublicKey If null then the server won't be validated
 * @return
 */
public HttpClient CreateApacheClient(String host, int port, PublicKey serverPublicKey, KeyStore clientKeyStore,
        char[] clientKeyStorePassPhrase, Proxy proxy)
        throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    //  sslSocketFactory
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUseExpectContinue(params, false); // Work around for bug in TJWS, it doesn't properly
                                                            // support ExpectContinue
    HttpConnectionParams.setSoTimeout(params, timeout);
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setTcpNoDelay(params, Boolean.TRUE);
    params.setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(host, port, "https"));

    HttpKeyHttpClient httpKeyHttpClient = new HttpKeyHttpClient(serverPublicKey, clientKeyStore,
            clientKeyStorePassPhrase, proxy, params);
    return httpKeyHttpClient;
}

From source file:org.bedework.util.http.BasicHttpClient.java

/**
 * @param host default host or null/* w w  w  . j  a  v  a  2  s . c o m*/
 * @param port default port if host supplied or -1 for default
 * @param scheme default scheme if host supplied or null for default
 * @param timeOut - millisecs, 0 for no timeout
 * @param followRedirects true for auto handling
 * @throws HttpException
 */
public BasicHttpClient(final String host, final int port, final String scheme, final int timeOut,
        final boolean followRedirects) throws HttpException {
    super(connManager, null);
    setKeepAliveStrategy(kas);

    if (sslDisabled) {
        warn("*******************************************************");
        warn(" SSL disabled");
        warn("*******************************************************");
    }

    final HttpParams params = getParams();

    if (host != null) {
        hostSpecified = true;
        final HttpHost httpHost = new HttpHost(host, port, scheme);
        params.setParameter(ClientPNames.DEFAULT_HOST, httpHost);
    }

    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut);

    // XXX Should have separate value for this.
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut * 2);

    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects);
}

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java

/**
 * Determines the route for a request./*from   ww w  .j a va 2  s  .  c  om*/
 * Called by {@link #execute} to determine the route for either the original
 * or a followup request.
 * 
 * @param target
 *            the target host for the request.
 *            Implementations may accept <code>null</code> if they can still
 *            determine a route, for example
 *            to a default target or by inspecting the request.
 * @param request
 *            the request to execute
 * @param context
 *            the context to use for the execution,
 *            never <code>null</code>
 * 
 * @return the route the request should take
 * 
 * @throws HttpException
 *             in case of a problem
 */
private HttpRoute determineRoute(HttpHost originalTarget, HttpRequest request, HttpContext context)
        throws HttpException {
    HttpHost target = originalTarget;
    if (target == null) {
        target = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
    }
    if (target == null) {
        throw new IllegalStateException("Target host must not be null, or set in parameters.");
    }

    return routePlanner.determineRoute(target, request, context);
}

From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java

/**
 * Determines the route for a request.//  w w  w . j  a v  a 2 s  . c om
 * Called by {@link #execute}
 * to determine the route for either the original or a followup request.
 *
 * @param target    the target host for the request.
 *                  Implementations may accept <code>null</code>
 *                  if they can still determine a route, for example
 *                  to a default target or by inspecting the request.
 * @param request   the request to execute
 * @param context   the context to use for the execution,
 *                  never <code>null</code>
 *
 * @return  the route the request should take
 *
 * @throws HttpException    in case of a problem
 */
protected HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
        throws HttpException {

    if (target == null) {
        target = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
    }
    if (target == null) {
        throw new IllegalStateException("Target host must not be null, or set in parameters.");
    }

    return this.routePlanner.determineRoute(target, request, context);
}

From source file:org.apache.http.impl.client.AbstractHttpClient.java

@Override
protected final CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request,
        final HttpContext context) throws IOException, ClientProtocolException {

    Args.notNull(request, "HTTP request");
    // a null target may be acceptable, this depends on the route planner
    // a null context is acceptable, default context created below

    HttpContext execContext = null;
    RequestDirector director = null;// w w  w  .ja v a 2s  .  c o m
    HttpRoutePlanner routePlanner = null;
    ConnectionBackoffStrategy connectionBackoffStrategy = null;
    BackoffManager backoffManager = null;

    // Initialize the request execution context making copies of
    // all shared objects that are potentially threading unsafe.
    synchronized (this) {

        final HttpContext defaultContext = createHttpContext();
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }
        final HttpParams params = determineParams(request);
        final RequestConfig config = HttpClientParamConfig.getRequestConfig(params);
        execContext.setAttribute(ClientContext.REQUEST_CONFIG, config);

        // Create a director for this request
        director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(),
                getProtocolProcessor(), getHttpRequestRetryHandler(), getRedirectStrategy(),
                getTargetAuthenticationStrategy(), getProxyAuthenticationStrategy(), getUserTokenHandler(),
                params);
        routePlanner = getRoutePlanner();
        connectionBackoffStrategy = getConnectionBackoffStrategy();
        backoffManager = getBackoffManager();
    }

    try {
        if (connectionBackoffStrategy != null && backoffManager != null) {
            final HttpHost targetForRoute = (target != null) ? target
                    : (HttpHost) determineParams(request).getParameter(ClientPNames.DEFAULT_HOST);
            final HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext);

            final CloseableHttpResponse out;
            try {
                out = CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
            } catch (final RuntimeException re) {
                if (connectionBackoffStrategy.shouldBackoff(re)) {
                    backoffManager.backOff(route);
                }
                throw re;
            } catch (final Exception e) {
                if (connectionBackoffStrategy.shouldBackoff(e)) {
                    backoffManager.backOff(route);
                }
                if (e instanceof HttpException) {
                    throw (HttpException) e;
                }
                if (e instanceof IOException) {
                    throw (IOException) e;
                }
                throw new UndeclaredThrowableException(e);
            }
            if (connectionBackoffStrategy.shouldBackoff(out)) {
                backoffManager.backOff(route);
            } else {
                backoffManager.probe(route);
            }
            return out;
        } else {
            return CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
        }
    } catch (final HttpException httpException) {
        throw new ClientProtocolException(httpException);
    }
}

From source file:org.apache.http.impl.client.DefaultRequestDirector.java

/**
 * Determines the route for a request.// w w  w .  ja  v  a2  s.  c  o m
 * Called by {@link #execute}
 * to determine the route for either the original or a followup request.
 *
 * @param targetHost  the target host for the request.
 *                  Implementations may accept <code>null</code>
 *                  if they can still determine a route, for example
 *                  to a default target or by inspecting the request.
 * @param request   the request to execute
 * @param context   the context to use for the execution,
 *                  never <code>null</code>
 *
 * @return  the route the request should take
 *
 * @throws HttpException    in case of a problem
 */
protected HttpRoute determineRoute(final HttpHost targetHost, final HttpRequest request,
        final HttpContext context) throws HttpException {
    return this.routePlanner.determineRoute(targetHost != null ? targetHost
            : (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST), request, context);
}

From source file:org.apache.http.impl.client.InternalHttpClient.java

private HttpRoute determineRoute(final HttpHost target, final HttpRequest request, final HttpContext context)
        throws HttpException {
    HttpHost host = target;//from w w  w  .j  av  a 2s . c om
    if (host == null) {
        host = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
    }
    Asserts.notNull(host, "Target host");
    return this.routePlanner.determineRoute(host, request, context);
}

From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java

protected HttpRoute determineRoute(final HttpHost target, final HttpRequest request, final HttpContext context)
        throws HttpException {
    final HttpHost t = target != null ? target
            : (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
    if (t == null) {
        throw new IllegalStateException("Target host could not be resolved");
    }//  www  .ja va  2 s .c o m
    return this.routePlanner.determineRoute(t, request, context);
}