private InputStream post()

in src/main/java/com/vmware/vim25/ws/ApacheHttpClient.java [153:206]


    private InputStream post(String payload) throws IOException {
        CloseableHttpClient httpclient;
        RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(this.connectTimeout)
            .setSocketTimeout(this.readTimeout)
            .build();

        if (trustAllSSL) {
            httpclient = HttpClients.custom().setSSLSocketFactory(ApacheTrustSelfSigned.trust()).build();
        } else {
            httpclient = HttpClients.createDefault();
        }
        HttpPost httpPost;
        StringEntity stringEntity;
        try {
            stringEntity = new StringEntity(payload);
            if (log.isTraceEnabled())
                log.trace("Converted payload to String entity.");
        }
        catch (UnsupportedEncodingException e) {
            log.error("Failed to convert payload to StringEntity. Unsupported Encoding Exception caught. Payload: " + payload, e);
            return null;
        }
        try {
            httpPost = new HttpPost(this.baseUrl.toURI());
        }
        catch (URISyntaxException e) {
            log.error("Malformed URI sent: " + this.baseUrl.toString(), e);
            return null;
        }
        httpPost.setConfig(requestConfig);
        httpPost.setHeader(SoapAction.SOAP_ACTION_HEADER.toString(), soapAction);
        httpPost.setHeader("Content-Type", "text/xml; charset=utf-8");
        if (cookie != null) {
            if (log.isTraceEnabled())
                log.trace("Setting Cookie " + cookie);
            httpPost.setHeader("Cookie", cookie);
        }
        httpPost.setEntity(stringEntity);

        CloseableHttpResponse response = httpclient.execute(httpPost);
        InputStream inputStream = response.getEntity().getContent();
        if (cookie == null) {

            Header[] headers = response.getAllHeaders();
            for (Header header : headers) {
                if (header.getName().equals("Set-Cookie")) {
                    cookie = header.getValue();
                    break;
                }
            }
        }
        return inputStream;
    }