cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [19/29] git commit: refs/heads/ui-multiple-nics - Remove invalid use of internal library class in VmwareContext.
Date Wed, 06 Mar 2013 18:00:03 GMT
Remove invalid use of internal library class in VmwareContext.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0fd30af5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0fd30af5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0fd30af5

Branch: refs/heads/ui-multiple-nics
Commit: 0fd30af5f87a0c3f1eb9496a2c0a409d7987028b
Parents: 9aa624a
Author: Hiroaki Kawai <kawai@stratosphere.co.jp>
Authored: Tue Mar 5 22:12:31 2013 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue Mar 5 22:12:31 2013 -0800

----------------------------------------------------------------------
 .../cloud/hypervisor/vmware/util/VmwareClient.java |   31 +++++++++++++++
 .../hypervisor/vmware/util/VmwareContext.java      |   16 ++------
 2 files changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0fd30af5/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
index 344fbdd..cbae5a9 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
@@ -17,6 +17,7 @@
 package com.cloud.hypervisor.vmware.util;
 
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -26,6 +27,12 @@ import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.SSLSession;
 import javax.net.ssl.HttpsURLConnection;
 import javax.xml.ws.BindingProvider;
+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.InvalidCollectorVersionFaultMsg;
@@ -94,6 +101,7 @@ public class VmwareClient {
     private VimService vimService;
     private VimPortType vimPort;
     private ServiceContent serviceContent;
+    private String serviceCookie;
     private final String SVC_INST_NAME = "ServiceInstance";
 
     private boolean isConnected = false;
@@ -133,6 +141,22 @@ public class VmwareClient {
         ctxt.put("com.sun.xml.internal.ws.connect.timeout", 600000);
 
         serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
+
+        // 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)
+                .getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
+        for (String header_raw_value : (List<String>) headers.get("Set-cookie")) {
+            List<Cookie> cookies = new BrowserCompatSpec().parse(
+                    new BasicHeader("Set-cookie", header_raw_value),
+                    new CookieOrigin(urlUrl.getHost(), urlUrl.getPort(), 
+                            urlUrl.getPath(), true));
+            if (cookies.size() > 0) {
+                serviceCookie = cookies.get(0).getValue();
+                break;
+            }
+        }
+        
         vimPort.login(serviceContent.getSessionManager(), userName, password, null);
         isConnected = true;
 
@@ -167,6 +191,13 @@ public class VmwareClient {
     }
 
     /**
+     * @return cookie used in service connection
+     */
+    public String getServiceCookie() {
+        return serviceCookie;
+    }
+
+    /**
      * @return Service property collector
      */
     public ManagedObjectReference getPropCol() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0fd30af5/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
index 091ce77..265fa64 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
@@ -38,8 +38,6 @@ import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLSession;
 import javax.xml.ws.BindingProvider;
-import com.sun.xml.internal.ws.transport.http.client.CookieJar;
-import com.sun.xml.internal.ws.client.BindingProviderProperties;
 
 import org.apache.log4j.Logger;
 
@@ -381,12 +379,12 @@ public class VmwareContext {
 			long totalBytesDownloaded, ActionDelegate progressUpdater) throws Exception {
 		HttpURLConnection conn = getRawHTTPConnection(urlString);
 
-		CookieJar cookie = getServiceCookie();
+		String cookie = _vimClient.getServiceCookie();
         if ( cookie == null ){
             s_logger.error("No cookie is found in vwware web service request context!");
             throw new Exception("No cookie is found in vmware web service request context!");
         }
-		cookie.applyRelevantCookies(conn);
+        conn.addRequestProperty("Cookie", cookie);
 	    conn.setDoInput(true);
 	    conn.setDoOutput(true);
 	    conn.setAllowUserInteraction(true);
@@ -537,7 +535,7 @@ public class VmwareContext {
 	}
 
 	public HttpURLConnection getHTTPConnection(String urlString, String httpMethod) throws Exception
{
-		CookieJar cookie = getServiceCookie();
+		String cookie = _vimClient.getServiceCookie();
 		if ( cookie == null ){
 		    s_logger.error("No cookie is found in vmware web service request context!");
             throw new Exception("No cookie is found in vmware web service request context!");
@@ -556,7 +554,7 @@ public class VmwareContext {
 	    conn.setDoInput(true);
 	    conn.setDoOutput(true);
 	    conn.setAllowUserInteraction(true);
-	    cookie.applyRelevantCookies(conn);
+	    conn.addRequestProperty("Cookie", cookie);
 	    conn.setRequestMethod(httpMethod);
         connectWithRetry(conn);
 	    return conn;
@@ -575,12 +573,6 @@ public class VmwareContext {
 	    return (HttpURLConnection)url.openConnection();
 	}
 
-	private CookieJar getServiceCookie() throws Exception {
-		VimPortType port = getService();
-        Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
-        return (CookieJar)ctxt.get(BindingProviderProperties.HTTP_COOKIE_JAR);
-	}
-
 	private static void connectWithRetry(HttpURLConnection conn) throws Exception {
 	    boolean connected = false;
 	    for(int i = 0; i < MAX_CONNECT_RETRY && !connected; i++) {


Mime
View raw message