org.apache.http.HttpRequest - java examples

Here are the examples of the java api org.apache.http.HttpRequest taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : ConditionalRequestBuilder.java
Copyright Apache License 2.0
Author : apigee
/**
 * Returns a request to unconditionally validate a cache entry with the
 * origin. In certain cases (due to multiple intervening caches) our cache
 * may actually receive a response to a normal conditional validation where
 * the Date header is actually older than that of our current cache entry.
 * In this case, the protocol recommendation is to retry the validation and
 * force syncup with the origin.
 *
 * @param request
 *            client request we are trying to satisfy
 * @param entry
 *            existing cache entry we are trying to validate
 * @return an unconditional validation request
 * @throws ProtocolException
 */
public HttpRequest buildUnconditionalRequest(HttpRequest request, HttpCacheEntry entry) throws ProtocolException {
    RequestWrapper wrapped = new RequestWrapper(request);
    wrapped.resetHeaders();
    wrapped.addHeader("Cache-Control", "no-cache");
    wrapped.addHeader("Pragma", "no-cache");
    wrapped.removeHeaders("If-Range");
    wrapped.removeHeaders("If-Match");
    wrapped.removeHeaders("If-None-Match");
    wrapped.removeHeaders("If-Unmodified-Since");
    wrapped.removeHeaders("If-Modified-Since");
    return wrapped;
}

19 View Complete Implementation : RequestProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private HttpRequest upgradeRequestTo(HttpRequest request, ProtocolVersion version) throws ProtocolException {
    RequestWrapper newRequest = new RequestWrapper(request);
    newRequest.setProtocolVersion(version);
    return newRequest;
}

19 View Complete Implementation : AbstractHttpServerConnection.java
Copyright MIT License
Author : pivotal-legacy
public HttpRequest receiveRequestHeader() throws HttpException, IOException {
    replacedertOpen();
    HttpRequest request = (HttpRequest) this.requestParser.parse();
    this.metrics.incrementRequestCount();
    return request;
}

19 View Complete Implementation : CachingHttpClient.java
Copyright Apache License 2.0
Author : apigee
/**
 * Execute an {@link HttpRequest} @ a given {@link HttpHost}
 *
 * @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
 * @return HttpResponse The cached entry or the result of a backend call
 * @throws IOException
 */
public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException {
    HttpContext defaultContext = null;
    return execute(target, request, defaultContext);
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
    return execute(target, request, responseHandler, null);
}

19 View Complete Implementation : AbstractHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : RequestProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private void verifyRequestWithExpectContinueFlagHas100continueHeader(HttpRequest request) {
    if (request instanceof HttpEnreplacedyEnclosingRequest) {
        if (((HttpEnreplacedyEnclosingRequest) request).expectContinue() && ((HttpEnreplacedyEnclosingRequest) request).getEnreplacedy() != null) {
            add100ContinueHeaderIfMissing(request);
        } else {
            remove100ContinueHeaderIfExists(request);
        }
    } else {
        remove100ContinueHeaderIfExists(request);
    }
}

19 View Complete Implementation : AndroidHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Sends the request line and all headers over the connection.
 * @param request the request whose headers to send.
 * @throws HttpException
 * @throws IOException
 */
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : BasicHttpCache.java
Copyright Apache License 2.0
Author : apigee
SizeLimitedResponseReader getResponseReader(HttpRequest request, HttpResponse backEndResponse) {
    return new SizeLimitedResponseReader(resourceFactory, maxObjectSizeBytes, request, backEndResponse);
}

19 View Complete Implementation : AndroidHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Sends the request line and all headers over the connection.
 * @param request the request whose headers to send.
 * @throws HttpException
 * @throws IOException
 */
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/*
     * Chooses a proxy from a list of available proxies.
     * The default implementation just picks the first non-SOCKS proxy
     * from the list. If there are only SOCKS proxies,
     * {@link Proxy#NO_PROXY Proxy.NO_PROXY} is returned.
     * Derived clreplacedes may implement more advanced strategies,
     * such as proxy rotation if there are multiple options.
     *
     * @param proxies   the list of proxies to choose from,
     *                  never <code>null</code> or empty
     * @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  a proxy of type {@link Proxy.Type#DIRECT DIRECT}
     *          or {@link Proxy.Type#HTTP HTTP}, never <code>null</code>
     */
protected Proxy chooseProxy(List<Proxy> proxies, HttpHost target, HttpRequest request, HttpContext context) {
    if ((proxies == null) || proxies.isEmpty()) {
        throw new IllegalArgumentException("Proxy list must not be empty.");
    }
    Proxy result = null;
    // check the list for one we can use
    for (int i = 0; (result == null) && (i < proxies.size()); i++) {
        Proxy p = proxies.get(i);
        switch(p.type()) {
            case DIRECT:
            case HTTP:
                result = p;
                break;
            case SOCKS:
                // SOCKS hosts are not handled on the route level.
                // The socket may make use of the SOCKS host though.
                break;
        }
    }
    if (result == null) {
        // @@@ log as warning or info that only a socks proxy is available?
        // result can only be null if all proxies are socks proxies
        // socks proxies are not handled on the route planning level
        result = Proxy.NO_PROXY;
    }
    return result;
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public final HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
    return execute(target, request, (HttpContext) null);
}

19 View Complete Implementation : AbstractHttpServerConnection.java
Copyright MIT License
Author : pivotal-legacy
public HttpRequest receiveRequestHeader() throws HttpException, IOException {
    replacedertOpen();
    HttpRequest request = (HttpRequest) this.requestParser.parse();
    this.metrics.incrementRequestCount();
    return request;
}

19 View Complete Implementation : CachingHttpClient.java
Copyright Apache License 2.0
Author : apigee
/**
 * Execute an {@link HttpRequest} @ a given {@link HttpHost} with a
 * specified {@link ResponseHandler} that will deal with the result of the
 * call.
 *
 * @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 responseHandler
 *            the response handler
 * @param <T>
 *            The Return Type Identified by the generic type of the
 *            {@link ResponseHandler}
 * @return T The response type as handled by ResponseHandler
 * @throws IOException
 */
public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException {
    return execute(target, request, responseHandler, null);
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Determines the route for a request.
 * 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);
}

19 View Complete Implementation : RequestProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
/**
 * If the {@link HttpRequest} is non-compliant but 'fixable' we go ahead and
 * fix the request here. Returning the updated one.
 *
 * @param request
 *            the request to check for compliance
 * @return the updated request
 * @throws ProtocolException
 *             when we have trouble making the request compliant
 */
public HttpRequest makeRequestCompliant(HttpRequest request) throws ProtocolException {
    if (requestMustNotHaveEnreplacedy(request)) {
        ((HttpEnreplacedyEnclosingRequest) request).setEnreplacedy(null);
    }
    verifyRequestWithExpectContinueFlagHas100continueHeader(request);
    verifyOPTIONSRequestWithBodyHasContentType(request);
    decrementOPTIONSMaxForwardsIfGreaterThen0(request);
    if (requestVersionIsTooLow(request)) {
        return upgradeRequestTo(request, HttpVersion.HTTP_1_1);
    }
    if (requestMinorVersionIsTooHighMajorVersionsMatch(request)) {
        return downgradeRequestTo(request, HttpVersion.HTTP_1_1);
    }
    return request;
}

19 View Complete Implementation : AbstractHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : BasicHttpCache.java
Copyright Apache License 2.0
Author : apigee
public void flushInvalidatedCacheEntriesFor(HttpHost host, HttpRequest request) throws IOException {
    cacheInvalidator.flushInvalidatedCacheEntries(host, request);
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Determines the route for a request.
 * 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);
}

19 View Complete Implementation : CachedResponseSuitabilityChecker.java
Copyright Apache License 2.0
Author : apigee
private boolean hasUnsupportedConditionalHeaders(HttpRequest request) {
    return (request.getFirstHeader("If-Range") != null || request.getFirstHeader("If-Match") != null || hasValidDateField(request, "If-Unmodified-Since"));
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
// constructor
private RequestWrapper wrapRequest(final HttpRequest request) throws ProtocolException {
    if (request instanceof HttpEnreplacedyEnclosingRequest) {
        return new EnreplacedyEnclosingRequestWrapper((HttpEnreplacedyEnclosingRequest) request);
    } else {
        return new RequestWrapper(request);
    }
}

19 View Complete Implementation : AbstractHttpServerConnection.java
Copyright MIT License
Author : pivotal-legacy
public HttpRequest receiveRequestHeader() throws HttpException, IOException {
    replacedertOpen();
    HttpRequest request = (HttpRequest) this.requestParser.parse();
    this.metrics.incrementRequestCount();
    return request;
}

19 View Complete Implementation : HttpRequestExecutor.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Prepare a request for sending.
 *
 * @param request   the request to prepare
 * @param processor the processor to use
 * @param context   the context for sending the request
 *
 * @throws HttpException      in case of a protocol or processing problem
 * @throws IOException        in case of an I/O problem
 */
public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (processor == null) {
        throw new IllegalArgumentException("HTTP processor may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    processor.process(request, context);
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public final HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
    return execute(target, request, (HttpContext) null);
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Obtains parameters for executing a request.
 * The default implementation in this clreplaced creates a new
 * {@link ClientParamsStack} from the request parameters
 * and the client parameters.
 * <br/>
 * This method is called by the default implementation of
 * {@link #execute(HttpHost,HttpRequest,HttpContext)}
 * to obtain the parameters for the
 * {@link DefaultRequestDirector}.
 *
 * @param req    the request that will be executed
 *
 * @return  the parameters to use
 */
protected HttpParams determineParams(HttpRequest req) {
    return new ClientParamsStack(null, getParams(), req.getParams(), null);
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/*
     * Chooses a proxy from a list of available proxies.
     * The default implementation just picks the first non-SOCKS proxy
     * from the list. If there are only SOCKS proxies,
     * {@link Proxy#NO_PROXY Proxy.NO_PROXY} is returned.
     * Derived clreplacedes may implement more advanced strategies,
     * such as proxy rotation if there are multiple options.
     *
     * @param proxies   the list of proxies to choose from,
     *                  never <code>null</code> or empty
     * @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  a proxy of type {@link Proxy.Type#DIRECT DIRECT}
     *          or {@link Proxy.Type#HTTP HTTP}, never <code>null</code>
     */
protected Proxy chooseProxy(List<Proxy> proxies, HttpHost target, HttpRequest request, HttpContext context) {
    if ((proxies == null) || proxies.isEmpty()) {
        throw new IllegalArgumentException("Proxy list must not be empty.");
    }
    Proxy result = null;
    // check the list for one we can use
    for (int i = 0; (result == null) && (i < proxies.size()); i++) {
        Proxy p = proxies.get(i);
        switch(p.type()) {
            case DIRECT:
            case HTTP:
                result = p;
                break;
            case SOCKS:
                // SOCKS hosts are not handled on the route level.
                // The socket may make use of the SOCKS host though.
                break;
        }
    }
    if (result == null) {
        // @@@ log as warning or info that only a socks proxy is available?
        // result can only be null if all proxies are socks proxies
        // socks proxies are not handled on the route planning level
        result = Proxy.NO_PROXY;
    }
    return result;
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public final HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
    return execute(target, request, (HttpContext) null);
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/**
 * 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();
        // replacedume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }
    return result;
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/*
     * Chooses a proxy from a list of available proxies.
     * The default implementation just picks the first non-SOCKS proxy
     * from the list. If there are only SOCKS proxies,
     * {@link Proxy#NO_PROXY Proxy.NO_PROXY} is returned.
     * Derived clreplacedes may implement more advanced strategies,
     * such as proxy rotation if there are multiple options.
     *
     * @param proxies   the list of proxies to choose from,
     *                  never <code>null</code> or empty
     * @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  a proxy of type {@link Proxy.Type#DIRECT DIRECT}
     *          or {@link Proxy.Type#HTTP HTTP}, never <code>null</code>
     */
protected Proxy chooseProxy(List<Proxy> proxies, HttpHost target, HttpRequest request, HttpContext context) {
    if ((proxies == null) || proxies.isEmpty()) {
        throw new IllegalArgumentException("Proxy list must not be empty.");
    }
    Proxy result = null;
    // check the list for one we can use
    for (int i = 0; (result == null) && (i < proxies.size()); i++) {
        Proxy p = proxies.get(i);
        switch(p.type()) {
            case DIRECT:
            case HTTP:
                result = p;
                break;
            case SOCKS:
                // SOCKS hosts are not handled on the route level.
                // The socket may make use of the SOCKS host though.
                break;
        }
    }
    if (result == null) {
        // @@@ log as warning or info that only a socks proxy is available?
        // result can only be null if all proxies are socks proxies
        // socks proxies are not handled on the route planning level
        result = Proxy.NO_PROXY;
    }
    return result;
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Obtains parameters for executing a request.
 * The default implementation in this clreplaced creates a new
 * {@link ClientParamsStack} from the request parameters
 * and the client parameters.
 * <br/>
 * This method is called by the default implementation of
 * {@link #execute(HttpHost,HttpRequest,HttpContext)}
 * to obtain the parameters for the
 * {@link DefaultRequestDirector}.
 *
 * @param req    the request that will be executed
 *
 * @return  the parameters to use
 */
protected HttpParams determineParams(HttpRequest req) {
    return new ClientParamsStack(null, getParams(), req.getParams(), null);
}

19 View Complete Implementation : ResponseProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private void requestDidNotExpect100ContinueButResponseIsOne(HttpRequest request, HttpResponse response) throws ClientProtocolException {
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) {
        return;
    }
    if (!requestWasWrapped(request)) {
        return;
    }
    ProtocolVersion originalProtocol = getOriginalRequestProtocol((RequestWrapper) request);
    if (originalProtocol.compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
        return;
    }
    if (originalRequestDidNotExpectContinue((RequestWrapper) request)) {
        throw new ClientProtocolException("The incoming request did not contain a " + "100-continue header, but the response was a Status 100, continue.");
    }
}

19 View Complete Implementation : AbstractHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : HttpClientWrapper.java
Copyright Apache License 2.0
Author : apigee
@Override
public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
    boolean errorOccurred = false;
    if (context == null) {
        context = new BasicHttpContext();
    }
    // Pre-Process requests
    captureRequest(request, context);
    HttpResponse response = null;
    try {
        if ((context.getAttribute(ATTR_SKIP_PROCESSING) != null) && (Boolean) context.getAttribute(ATTR_SKIP_PROCESSING)) {
            response = (HttpResponse) context.getAttribute(ATTR_OVERRIDDEN_RESPONSE);
        } else {
            response = delgatedHttpClientImpl.execute(target, request, context);
        }
    } catch (ClientProtocolException e) {
        errorOccurred = true;
        context.setAttribute(ATTR_DELEGATE_EXCEPTION_OCCURRED, errorOccurred);
        context.setAttribute(ATTR_DELEGATE_EXCEPTION, e);
        throw e;
    } catch (IOException e) {
        errorOccurred = true;
        context.setAttribute(ATTR_DELEGATE_EXCEPTION_OCCURRED, errorOccurred);
        context.setAttribute(ATTR_DELEGATE_EXCEPTION, e);
        throw e;
    } finally {
        captureResponse(response, context);
    }
    return response;
}

19 View Complete Implementation : AndroidHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Sends the request line and all headers over the connection.
 * @param request the request whose headers to send.
 * @throws HttpException
 * @throws IOException
 */
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : CachingHttpClient.java
Copyright Apache License 2.0
Author : apigee
/**
 * Execute an {@link HttpRequest} @ a given {@link HttpHost} with a
 * specified {@link ResponseHandler} that will deal with the result of the
 * call using a specific {@link HttpContext}
 *
 * @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 responseHandler
 *            the response handler
 * @param context
 *            the context to use for the execution, or <code>null</code> to
 *            use the default context
 * @param <T>
 *            The Return Type Identified by the generic type of the
 *            {@link ResponseHandler}
 * @return T The response type as handled by ResponseHandler
 * @throws IOException
 */
public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException {
    HttpResponse resp = execute(target, request, context);
    return responseHandler.handleResponse(resp);
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
// constructor
private RequestWrapper wrapRequest(final HttpRequest request) throws ProtocolException {
    if (request instanceof HttpEnreplacedyEnclosingRequest) {
        return new EnreplacedyEnclosingRequestWrapper((HttpEnreplacedyEnclosingRequest) request);
    } else {
        return new RequestWrapper(request);
    }
}

19 View Complete Implementation : ResponseProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private void transferEncodingIsNotReturnedTo1_0Client(HttpRequest request, HttpResponse response) {
    if (!requestWasWrapped(request)) {
        return;
    }
    ProtocolVersion originalProtocol = getOriginalRequestProtocol((RequestWrapper) request);
    if (originalProtocol.compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
        return;
    }
    removeResponseTransferEncoding(response);
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/**
 * 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();
        // replacedume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }
    return result;
}

19 View Complete Implementation : RequestProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
protected boolean requestVersionIsTooLow(HttpRequest request) {
    return request.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) < 0;
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
    return execute(target, request, responseHandler, null);
}

19 View Complete Implementation : ResponseProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private boolean backendResponseMustNotHaveBody(HttpRequest request, HttpResponse backendResponse) {
    return HeaderConstants.HEAD_METHOD.equals(request.getRequestLine().getMethod()) || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_RESET_CONTENT || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED;
}

19 View Complete Implementation : AndroidHttpClientConnection.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Sends the request line and all headers over the connection.
 * @param request the request whose headers to send.
 * @throws HttpException
 * @throws IOException
 */
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    replacedertOpen();
    this.requestWriter.write(request);
    this.metrics.incrementRequestCount();
}

19 View Complete Implementation : ResponseProtocolCompliance.java
Copyright Apache License 2.0
Author : apigee
private void unauthorizedResponseDidNotHaveAWWWAuthenticateHeader(HttpRequest request, HttpResponse response) throws ClientProtocolException {
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_UNAUTHORIZED)
        return;
    if (response.getFirstHeader(HeaderConstants.WWW_AUTHENTICATE) == null) {
        throw new ClientProtocolException("401 Response did not contain required WWW-Authenticate challenge header");
    }
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
// non-javadoc, see interface HttpClient
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
    return execute(target, request, responseHandler, null);
}

19 View Complete Implementation : HttpRequestExecutor.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Prepare a request for sending.
 *
 * @param request   the request to prepare
 * @param processor the processor to use
 * @param context   the context for sending the request
 *
 * @throws HttpException      in case of a protocol or processing problem
 * @throws IOException        in case of an I/O problem
 */
public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (processor == null) {
        throw new IllegalArgumentException("HTTP processor may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    processor.process(request, context);
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Determines the route for a request.
 * 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);
}

19 View Complete Implementation : ProxySelectorRoutePlanner.java
Copyright MIT License
Author : pivotal-legacy
/**
 * 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();
        // replacedume default scheme (http)
        result = new HttpHost(getHost(isa), isa.getPort());
    }
    return result;
}

19 View Complete Implementation : AbstractHttpClient.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Obtains parameters for executing a request.
 * The default implementation in this clreplaced creates a new
 * {@link ClientParamsStack} from the request parameters
 * and the client parameters.
 * <br/>
 * This method is called by the default implementation of
 * {@link #execute(HttpHost,HttpRequest,HttpContext)}
 * to obtain the parameters for the
 * {@link DefaultRequestDirector}.
 *
 * @param req    the request that will be executed
 *
 * @return  the parameters to use
 */
protected HttpParams determineParams(HttpRequest req) {
    return new ClientParamsStack(null, getParams(), req.getParams(), null);
}

19 View Complete Implementation : HttpRequestExecutor.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Prepare a request for sending.
 *
 * @param request   the request to prepare
 * @param processor the processor to use
 * @param context   the context for sending the request
 *
 * @throws HttpException      in case of a protocol or processing problem
 * @throws IOException        in case of an I/O problem
 */
public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (processor == null) {
        throw new IllegalArgumentException("HTTP processor may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    processor.process(request, context);
}

19 View Complete Implementation : DefaultRequestDirector.java
Copyright MIT License
Author : pivotal-legacy
// constructor
private RequestWrapper wrapRequest(final HttpRequest request) throws ProtocolException {
    if (request instanceof HttpEnreplacedyEnclosingRequest) {
        return new EnreplacedyEnclosingRequestWrapper((HttpEnreplacedyEnclosingRequest) request);
    } else {
        return new RequestWrapper(request);
    }
}