mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix a bug in retrieving cookie from Vmware connection by replacing
Kawai's patch by parsing request header ourselves instead of using BrowserCompatSpec.
This commit is contained in:
parent
89f4ac0439
commit
eca1a7089a
@ -17,11 +17,11 @@
|
|||||||
package com.cloud.hypervisor.vmware.util;
|
package com.cloud.hypervisor.vmware.util;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
@ -29,10 +29,6 @@ import javax.net.ssl.HttpsURLConnection;
|
|||||||
import javax.xml.ws.BindingProvider;
|
import javax.xml.ws.BindingProvider;
|
||||||
import javax.xml.ws.handler.MessageContext;
|
import javax.xml.ws.handler.MessageContext;
|
||||||
|
|
||||||
import org.apache.http.cookie.Cookie;
|
|
||||||
import org.apache.http.cookie.CookieOrigin;
|
|
||||||
import org.apache.http.impl.cookie.BrowserCompatSpec;
|
|
||||||
import org.apache.http.message.BasicHeader;
|
|
||||||
|
|
||||||
import com.vmware.vim25.DynamicProperty;
|
import com.vmware.vim25.DynamicProperty;
|
||||||
import com.vmware.vim25.InvalidCollectorVersionFaultMsg;
|
import com.vmware.vim25.InvalidCollectorVersionFaultMsg;
|
||||||
@ -143,19 +139,14 @@ public class VmwareClient {
|
|||||||
serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
|
serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
|
||||||
|
|
||||||
// Extract a cookie. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
|
// Extract a cookie. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
|
||||||
URL urlUrl = new URL(url);
|
|
||||||
Map<String, List<String>> headers = (Map<String, List<String>>) ((BindingProvider) vimPort)
|
Map<String, List<String>> headers = (Map<String, List<String>>) ((BindingProvider) vimPort)
|
||||||
.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
|
.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
|
||||||
for (String header_raw_value : (List<String>) headers.get("Set-cookie")) {
|
List<String> cookies = (List<String>) headers.get("Set-cookie");
|
||||||
List<Cookie> cookies = new BrowserCompatSpec().parse(
|
String cookieValue = cookies.get(0);
|
||||||
new BasicHeader("Set-cookie", header_raw_value),
|
StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");
|
||||||
new CookieOrigin(urlUrl.getHost(), urlUrl.getPort(),
|
cookieValue = tokenizer.nextToken();
|
||||||
urlUrl.getPath(), true));
|
String pathData = "$" + tokenizer.nextToken();
|
||||||
if (cookies.size() > 0) {
|
serviceCookie = "$Version=\"1\"; " + cookieValue + "; " + pathData;
|
||||||
serviceCookie = cookies.get(0).getValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vimPort.login(serviceContent.getSessionManager(), userName, password, null);
|
vimPort.login(serviceContent.getSessionManager(), userName, password, null);
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user