Search in sources :

Example 1 with CommonHttpClientBuilder

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

Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 IOException (java.io.IOException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 CommonHttpClientBuilder (org.ow2.proactive.http.CommonHttpClientBuilder)1 HttpClientBuilder (org.ow2.proactive.http.HttpClientBuilder)1 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)1 HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)1 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)1