Search in sources :

Example 1 with EasySSLProtocolSocketFactory

use of org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory in project cloudstack by apache.

the class CiscoVnmcConnectionImpl method sendRequest.

private String sendRequest(String service, String xmlRequest) throws ExecutionException {
    HttpClient client = new HttpClient();
    String response = null;
    PostMethod method = new PostMethod("/xmlIM/" + service);
    method.setRequestBody(xmlRequest);
    try {
        org.apache.commons.httpclient.protocol.Protocol myhttps = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        client.getHostConfiguration().setHost(_ip, 443, myhttps);
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new Exception("Error code : " + statusCode);
        }
        response = method.getResponseBodyAsString();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new ExecutionException(e.getMessage());
    }
    System.out.println(response);
    return response;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) ExecutionException(com.cloud.utils.exception.ExecutionException) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) HttpClient(org.apache.commons.httpclient.HttpClient) ExecutionException(com.cloud.utils.exception.ExecutionException)

Aggregations

ExecutionException (com.cloud.utils.exception.ExecutionException)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 EasySSLProtocolSocketFactory (org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory)1 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1