cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [27/50] [abbrv] git commit: refs/heads/master - Spring hack for Ec2RestServlet
Date Fri, 01 Feb 2013 23:27:31 GMT
Spring hack for Ec2RestServlet


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

Branch: refs/heads/master
Commit: 4dc63f50a7f0c573fba1071403eca46705f7665a
Parents: 1765232
Author: Prachi Damle <prachi@cloud.com>
Authored: Wed Jan 30 15:40:51 2013 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Wed Jan 30 15:56:56 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/bridge/service/EC2RestServlet.java   |   30 ++++++++++++++-
 awsapi/web/web.xml                                 |    7 ++-
 2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4dc63f50/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
index 8309bfd..1023e8d 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
@@ -39,6 +39,7 @@ import java.util.List;
 import java.util.Properties;
 import java.util.UUID;
 
+import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -57,6 +58,7 @@ import org.apache.axis2.databinding.ADBException;
 import org.apache.axis2.databinding.utils.writer.MTOMAwareXMLSerializer;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.amazon.ec2.AllocateAddressResponse;
 import com.amazon.ec2.AssociateAddressResponse;
@@ -96,6 +98,7 @@ import com.amazon.ec2.StartInstancesResponse;
 import com.amazon.ec2.StopInstancesResponse;
 import com.amazon.ec2.TerminateInstancesResponse;
 import com.cloud.bridge.model.UserCredentialsVO;
+import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
 import com.cloud.bridge.persist.dao.OfferingDaoImpl;
 import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
 import com.cloud.bridge.service.controller.s3.ServiceProvider;
@@ -142,13 +145,16 @@ import com.cloud.bridge.util.EC2RestAuth;
 import com.cloud.stack.models.CloudStackAccount;
 import com.cloud.utils.db.Transaction;
 
-
+@Component("EC2RestServlet")
 public class EC2RestServlet extends HttpServlet {
 
     private static final long serialVersionUID = -6168996266762804888L;
     @Inject UserCredentialsDaoImpl ucDao;
     @Inject OfferingDaoImpl ofDao;
 
+    static UserCredentialsDaoImpl s_ucDao;
+    static OfferingDaoImpl s_ofDao;
+    
     public static final Logger logger = Logger.getLogger(EC2RestServlet.class);
 
     private final OMFactory factory = OMAbstractFactory.getOMFactory();
@@ -161,13 +167,35 @@ public class EC2RestServlet extends HttpServlet {
 
     boolean debug=true;
 
+    public EC2RestServlet() {
+    }
 
+    @PostConstruct
+    void initComponent() {  
+        // Servlet injection does not always work for servlet container
+        // We use a hacking here to initialize static variables at Spring wiring time
+        if(ucDao != null) {
+            s_ucDao = ucDao;
+        } else {
+            ucDao = s_ucDao;
+        }
+        
+        if(ofDao != null) {
+            s_ofDao = ofDao;
+        } else {
+            ofDao = s_ofDao;
+        }
+        
+    }
+    
+    
     /**
      * We build the path to where the keystore holding the WS-Security X509 certificates
      * are stored.
      */
     @Override
     public void init( ServletConfig config ) throws ServletException {
+        initComponent();
         File propertiesFile = ConfigurationHelper.findConfigurationFile("ec2-service.properties");
         Properties EC2Prop = null;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4dc63f50/awsapi/web/web.xml
----------------------------------------------------------------------
diff --git a/awsapi/web/web.xml b/awsapi/web/web.xml
index 923a29b..7efe43d 100644
--- a/awsapi/web/web.xml
+++ b/awsapi/web/web.xml
@@ -70,9 +70,10 @@
         </init-param>
     </servlet>
     <servlet>
-        <servlet-name>CloudBridgeEC2Servlet</servlet-name>
+        <servlet-name>EC2RestServlet</servlet-name>
         <display-name>Cloud.com Bridge EC2 Service REST Servlet</display-name>
         <servlet-class>com.cloud.bridge.service.EC2RestServlet</servlet-class>
+		<load-on-startup>3</load-on-startup>
     </servlet>
 
     <servlet-mapping>
@@ -92,13 +93,13 @@
    
     <!-- EC2 examples are using that last '/' --> 
     <servlet-mapping>
-        <servlet-name>CloudBridgeEC2Servlet</servlet-name>
+        <servlet-name>EC2RestServlet</servlet-name>
         <url-pattern>/rest/AmazonEC2/*</url-pattern>
     </servlet-mapping>
     
     <!-- handle the common error of leaving off the last '/' -->
     <servlet-mapping>
-        <servlet-name>CloudBridgeEC2Servlet</servlet-name>
+        <servlet-name>EC2RestServlet</servlet-name>
         <url-pattern>/rest/AmazonEC2</url-pattern>
     </servlet-mapping>
     


Mime
View raw message