Search in sources :

Example 6 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder 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

HttpClientBuilder (org.ow2.proactive.http.HttpClientBuilder)6 HttpResponse (org.apache.http.HttpResponse)4 IOException (java.io.IOException)2 HttpClient (org.apache.http.client.HttpClient)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 Callable (java.util.concurrent.Callable)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 StringEntity (org.apache.http.entity.StringEntity)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 CommonHttpClientBuilder (org.ow2.proactive.http.CommonHttpClientBuilder)1 OctetStreamReader (org.ow2.proactive.scheduler.rest.readers.OctetStreamReader)1 TaskResultReader (org.ow2.proactive.scheduler.rest.readers.TaskResultReader)1 WildCardTypeReader (org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader)1 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)1