in src/main/java/com/vmware/vim25/ws/WSClient.java [140:199]
protected InputStream post(String soapMsg) throws IOException {
HttpURLConnection postCon = (HttpURLConnection) baseUrl.openConnection();
if (sslSocketFactory != null && baseUrl.getProtocol().equalsIgnoreCase("https")) {
((HttpsURLConnection) postCon).setSSLSocketFactory(sslSocketFactory);
}
if (log.isTraceEnabled()) {
log.trace("POST: " + soapAction);
log.trace("Payload: " + soapMsg);
}
if (connectTimeout > 0) {
postCon.setConnectTimeout(connectTimeout);
}
if (readTimeout > 0) {
postCon.setReadTimeout(readTimeout);
}
try {
postCon.setRequestMethod("POST");
}
catch (ProtocolException e) {
log.debug("ProtocolException caught.", e);
}
postCon.setDoOutput(true);
postCon.setDoInput(true);
String soapAction = this.soapAction;
if (soapAction == null) {
soapAction = "";
}
postCon.setRequestProperty(SoapAction.SOAP_ACTION_HEADER.toString(), soapAction);
postCon.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
if (cookie != null) {
if (log.isTraceEnabled()) {
log.trace("Setting Cookie " + cookie);
}
postCon.setRequestProperty("Cookie", cookie);
}
OutputStream os = postCon.getOutputStream();
OutputStreamWriter out = createOutputStreamWriter(os);
out.write(soapMsg);
out.close();
InputStream is = getInputStreamFromConnection(postCon);
if (postCon.getResponseCode() >= 300){
String newUrl = postCon.getHeaderField("Location");
String extraMsg = newUrl == null? "" : ". Please use URL '" + newUrl + "' instead";
throw new IOException("Unable to call " + baseUrl + ": " + postCon.getResponseMessage() + extraMsg);
}
if (cookie == null) {
cookie = postCon.getHeaderField("Set-Cookie");
log.trace("Cookie was null. Fetching Set-Cookie header to get new Cookie.");
}
return is;
}