Search in sources :

Example 61 with HttpRequestBase

use of org.apache.http.client.methods.HttpRequestBase in project linuxtools by eclipse.

the class OSIORestRequest method execute.

protected T execute(IOperationMonitor monitor) throws IOException, OSIORestException {
    HttpRequestBase request = createHttpRequestBase();
    addHttpRequestEntities(request);
    CommonHttpResponse response = execute(request, monitor);
    return processAndRelease(response, monitor);
}
Also used : CommonHttpResponse(org.eclipse.mylyn.commons.repositories.http.core.CommonHttpResponse) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase)

Example 62 with HttpRequestBase

use of org.apache.http.client.methods.HttpRequestBase in project suite by stupidsing.

the class HttpUtil method httpApache.

private static HttpResult httpApache(String method, URL url, Outlet<Bytes> in, Map<String, String> headers) throws IOException {
    LogUtil.info("START " + method + " " + url);
    CloseableHttpClient client = HttpClients.createDefault();
    HttpRequestBase request = new HttpRequestBase() {

        {
            setURI(URI.create(url.toString()));
            headers.entrySet().forEach(e -> addHeader(e.getKey(), e.getValue()));
        }

        public String getMethod() {
            return method;
        }
    };
    CloseableHttpResponse response = client.execute(request);
    StatusLine statusLine = response.getStatusLine();
    int statusCode = statusLine.getStatusCode();
    InputStream inputStream = response.getEntity().getContent();
    Outlet<Bytes> out = // 
    To.outlet(inputStream).closeAtEnd(// 
    inputStream).closeAtEnd(// 
    response).closeAtEnd(// 
    client).closeAtEnd(() -> LogUtil.info("END__ " + method + " " + url));
    if (statusCode == HttpURLConnection.HTTP_OK)
        return new HttpResult(statusCode, out);
    else
        throw new IOException(// 
        "HTTP returned " + statusCode + ": " + // 
        url + ": " + // 
        statusLine.getReasonPhrase() + ": " + out.collect(As::string));
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Bytes(suite.primitive.Bytes) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) InputStream(java.io.InputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 63 with HttpRequestBase

use of org.apache.http.client.methods.HttpRequestBase in project scheduling by ow2-proactive.

the class AbstractCommand method execute.

protected HttpResponseWrapper execute(HttpUriRequest request, ApplicationContext currentContext) {
    String sessionId = currentContext.getSessionId();
    if (sessionId != null) {
        request.setHeader("sessionid", sessionId);
    }
    CommonHttpClientBuilder httpClientBuilder = new HttpClientBuilder().useSystemProperties();
    try {
        if ("https".equals(request.getURI().getScheme()) && currentContext.canInsecureAccess()) {
            httpClientBuilder.insecure(true);
        }
        HttpResponse response = httpClientBuilder.build().execute(request);
        return new HttpResponseWrapper(response);
    } catch (SSLPeerUnverifiedException sslException) {
        throw new CLIException(CLIException.REASON_OTHER, "SSL error. Perhaps HTTPS certificate could not be validated, " + "you can try with -k or insecure() for insecure SSL connection.", sslException);
    } catch (Exception e) {
        throw new CLIException(CLIException.REASON_OTHER, e.getMessage(), e);
    } finally {
        ((HttpRequestBase) request).releaseConnection();
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) HttpResponse(org.apache.http.HttpResponse) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) CommonHttpClientBuilder(org.ow2.proactive.http.CommonHttpClientBuilder) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) IOException(java.io.IOException) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) CommonHttpClientBuilder(org.ow2.proactive.http.CommonHttpClientBuilder)

Aggregations

HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)63 HttpResponse (org.apache.http.HttpResponse)28 HttpGet (org.apache.http.client.methods.HttpGet)20 IOException (java.io.IOException)18 Header (org.apache.http.Header)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 HttpPost (org.apache.http.client.methods.HttpPost)13 HttpEntity (org.apache.http.HttpEntity)10 StringEntity (org.apache.http.entity.StringEntity)10 URI (java.net.URI)9 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)9 Test (org.junit.Test)9 InputStream (java.io.InputStream)7 URISyntaxException (java.net.URISyntaxException)7 ArrayList (java.util.ArrayList)7 HttpHead (org.apache.http.client.methods.HttpHead)7 HttpPut (org.apache.http.client.methods.HttpPut)6 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)5 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)5 HashMap (java.util.HashMap)4