Example usage for org.apache.http.impl.client AbstractHttpClient execute

List of usage examples for org.apache.http.impl.client AbstractHttpClient execute

Introduction

In this page you can find the example usage for org.apache.http.impl.client AbstractHttpClient execute.

Prototype

public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request,
        final HttpContext context) throws IOException, ClientProtocolException 

Source Link

Usage

From source file:org.eclipse.mylyn.commons.http.HttpUtil.java

public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host,
        final HttpContext context, final HttpRequestBase method, IProgressMonitor monitor) throws IOException {
    Assert.isNotNull(client);//  w  w  w .j  ava2  s. c  om
    Assert.isNotNull(method);

    monitor = Policy.monitorFor(monitor);

    MonitoredRequest<HttpResponse> executor = new MonitoredRequest<HttpResponse>(monitor) {
        @Override
        public void abort() {
            super.abort();
            method.abort();
        }

        @Override
        public HttpResponse execute() throws Exception {
            return client.execute(host, method, context);
        }
    };

    return executeInternal(monitor, executor);
}

From source file:org.eclipse.mylyn.commons.repositories.http.core.HttpUtil.java

public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host,
        final HttpContext context, final HttpRequestBase method, final IProgressMonitor progress)
        throws IOException {
    Assert.isNotNull(client);//from  w ww.  ja v  a  2s .c  om
    Assert.isNotNull(method);

    final IOperationMonitor monitor = OperationUtil.convert(progress);
    ICancellableOperation operation = new ICancellableOperation() {
        @Override
        public void abort() {
            method.abort();
        }

        @Override
        public boolean isCanceled() {
            return monitor.isCanceled();
        }
    };

    CancellableOperationMonitorThread thread = null;
    if (context != null) {
        thread = (CancellableOperationMonitorThread) context.getAttribute(CONTEXT_KEY_MONITOR_THREAD);
    }
    if (thread != null) {
        thread.addOperation(operation);
    }
    try {
        return client.execute(host, method, context);
    } catch (InterruptedIOException e) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        throw e;
    } finally {
        if (thread != null) {
            thread.removeOperation(operation);
        }
    }
}

From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.java

protected HttpResponse executeMethod(AbstractHttpClient httpClient, MessageContext msgContext, URL url,
        HttpRequestBase method) throws IOException {
    HttpHost httpHost = this.getHostConfiguration(httpClient, msgContext, url);

    // set the custom headers, if available
    addCustomHeaders(method, msgContext);

    // add compression headers if needed
    if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
        method.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP);
    }/* w  w  w  .j av a 2s .com*/

    if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
        method.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING, HTTPConstants.COMPRESSION_GZIP);
    }

    if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
        HttpParams params = (HttpParams) msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS);
        method.setParams(params);
    }

    String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
    if (cookiePolicy != null) {
        method.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
    }

    setTimeouts(msgContext, method);
    HttpContext localContext = new BasicHttpContext();
    // Why do we have add context here
    return httpClient.execute(httpHost, method, localContext);
}