You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/01/15 03:04:54 UTC

[42/44] Revert "Merge remote-tracking branch 'origin/javelin' into javelin"

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/auth/s3/AuthenticationHandler.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/auth/s3/AuthenticationHandler.java b/awsapi/src/com/cloud/bridge/auth/s3/AuthenticationHandler.java
index b951916..5b20b02 100644
--- a/awsapi/src/com/cloud/bridge/auth/s3/AuthenticationHandler.java
+++ b/awsapi/src/com/cloud/bridge/auth/s3/AuthenticationHandler.java
@@ -18,197 +18,203 @@ package com.cloud.bridge.auth.s3;
 
 import java.sql.SQLException;
 
+import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPBody;
-import org.apache.log4j.Logger;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.engine.Handler;
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.description.HandlerDescription; 
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.Handler;
+import org.apache.log4j.Logger;
 
 import com.cloud.bridge.model.UserCredentialsVO;
 import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
 import com.cloud.bridge.service.UserContext;
 import com.cloud.bridge.util.S3SoapAuth;
-import com.cloud.utils.component.ComponentLocator;
 
 /*
  *  For SOAP compatibility.
  */
 
 public class AuthenticationHandler implements Handler {
-     protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
-     protected final UserCredentialsDaoImpl ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
-	 protected HandlerDescription handlerDesc = new HandlerDescription( "default handler" );
-     private String name = "S3AuthenticationHandler";
-    
-     public void init( HandlerDescription handlerdesc ) 
-     {
-   	  	 this.handlerDesc = handlerdesc;
-     }
-    	  	
-     public String getName() 
-     {
-    	 //logger.debug( "getName entry S3AuthenticationHandler" + name );
-         return name;
-     }
-
-     public String toString() 
-     {
-    	 return (name != null) ? name.toString() : null;
-     }
-     
-     public HandlerDescription getHandlerDesc() 
-     {
-       	 return handlerDesc;
-     }
-    	
-     public Parameter getParameter( String name ) 
-     {
-    	 return handlerDesc.getParameter( name );
-     } 
-     
-     
-     /**
-      * Verify the request's authentication signature by extracting all the 
-      * necessary parts of the request, obtaining the requestor's secret key, and
-      * recalculating the signature.
-      * 
-      * On Signature mismatch raise an AxisFault (i.e., a SoapFault) with what Amazon S3 
-      * defines as a "Client.SignatureMismatch" error.
-      * 
-      * Special case: need to deal with anonymous requests where no AWSAccessKeyId is
-      * given.   In this case just pass the request on.
-      */
-     public InvocationResponse invoke(MessageContext msgContext) throws AxisFault  
-     {
-    	 String accessKey  = null;
-    	 String operation  = null;
-    	 String msgSig     = null;
-    	 String timestamp  = null;
-    	 String secretKey  = null;
-    	 String temp       = null;
-    	 
-    	 // [A] Obtain the HttpServletRequest object 
-    	 HttpServletRequest httpObj =(HttpServletRequest)msgContext.getProperty("transport.http.servletRequest");
-    	 if (null != httpObj) System.out.println("S3 SOAP auth test header access - acceptable Encoding type: "+ httpObj.getHeader("Accept-Encoding"));
-    	 
-    	 // [A] Try to recalculate the signature for non-anonymous requests
-    	 try
-    	 {  SOAPEnvelope soapEnvelope = msgContext.getEnvelope();
-            SOAPBody     soapBody     = soapEnvelope.getBody();
-            String       xmlBody      = soapBody.toString();
-            //logger.debug( "xmlrequest: " + xmlBody );
-         
-            // -> did we get here yet its an EC2 request?
-            int offset = xmlBody.indexOf( "http://ec2.amazonaws.com" );
-            if (-1 != offset) return InvocationResponse.CONTINUE;
-            
-            
-            // -> if it is anonymous request, then no access key should exist
-            int start = xmlBody.indexOf( "AWSAccessKeyId>" );
-            if (-1 == start) {
-                UserContext.current().initContext();
-                return InvocationResponse.CONTINUE;
-            }           
-            temp = xmlBody.substring( start+15 );
-            int end   = temp.indexOf( "</" );
-            accessKey = temp.substring( 0, end );
-            //logger.debug( "accesskey " + accessKey );
-            
-            
-            // -> what if we cannot find the user's key?
-            if (null != (secretKey = lookupSecretKey( accessKey )))
+    protected final static Logger logger = Logger.getLogger(AuthenticationHandler.class);
+    @Inject UserCredentialsDaoImpl ucDao;
+    protected HandlerDescription handlerDesc = new HandlerDescription( "default handler" );
+    private String name = "S3AuthenticationHandler";
+
+    @Override
+    public void init( HandlerDescription handlerdesc ) 
+    {
+        this.handlerDesc = handlerdesc;
+    }
+
+    @Override
+    public String getName() 
+    {
+        //logger.debug( "getName entry S3AuthenticationHandler" + name );
+        return name;
+    }
+
+    @Override
+    public String toString() 
+    {
+        return (name != null) ? name.toString() : null;
+    }
+
+    @Override
+    public HandlerDescription getHandlerDesc() 
+    {
+        return handlerDesc;
+    }
+
+    @Override
+    public Parameter getParameter( String name ) 
+    {
+        return handlerDesc.getParameter( name );
+    } 
+
+
+    /**
+     * Verify the request's authentication signature by extracting all the 
+     * necessary parts of the request, obtaining the requestor's secret key, and
+     * recalculating the signature.
+     * 
+     * On Signature mismatch raise an AxisFault (i.e., a SoapFault) with what Amazon S3 
+     * defines as a "Client.SignatureMismatch" error.
+     * 
+     * Special case: need to deal with anonymous requests where no AWSAccessKeyId is
+     * given.   In this case just pass the request on.
+     */
+    @Override
+    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault  
+    {
+        String accessKey  = null;
+        String operation  = null;
+        String msgSig     = null;
+        String timestamp  = null;
+        String secretKey  = null;
+        String temp       = null;
+
+        // [A] Obtain the HttpServletRequest object 
+        HttpServletRequest httpObj =(HttpServletRequest)msgContext.getProperty("transport.http.servletRequest");
+        if (null != httpObj) System.out.println("S3 SOAP auth test header access - acceptable Encoding type: "+ httpObj.getHeader("Accept-Encoding"));
+
+        // [A] Try to recalculate the signature for non-anonymous requests
+        try
+        {  SOAPEnvelope soapEnvelope = msgContext.getEnvelope();
+        SOAPBody     soapBody     = soapEnvelope.getBody();
+        String       xmlBody      = soapBody.toString();
+        //logger.debug( "xmlrequest: " + xmlBody );
+
+        // -> did we get here yet its an EC2 request?
+        int offset = xmlBody.indexOf( "http://ec2.amazonaws.com" );
+        if (-1 != offset) return InvocationResponse.CONTINUE;
+
+
+        // -> if it is anonymous request, then no access key should exist
+        int start = xmlBody.indexOf( "AWSAccessKeyId>" );
+        if (-1 == start) {
+            UserContext.current().initContext();
+            return InvocationResponse.CONTINUE;
+        }           
+        temp = xmlBody.substring( start+15 );
+        int end   = temp.indexOf( "</" );
+        accessKey = temp.substring( 0, end );
+        //logger.debug( "accesskey " + accessKey );
+
+
+        // -> what if we cannot find the user's key?
+        if (null != (secretKey = lookupSecretKey( accessKey )))
+        {
+            // -> if any other field is missing, then the signature will not match
+            if ( null != (operation = soapBody.getFirstElementLocalName()))
+                operation = operation.trim();
+            else operation = "";
+            //logger.debug( "operation " + operation );
+
+            start = xmlBody.indexOf( "Timestamp>" );
+            if ( -1 < start )
             {
-                // -> if any other field is missing, then the signature will not match
-                if ( null != (operation = soapBody.getFirstElementLocalName()))
-                     operation = operation.trim();
-                else operation = "";
-                //logger.debug( "operation " + operation );
- 
-                start = xmlBody.indexOf( "Timestamp>" );
-                if ( -1 < start )
-                {
-                    temp = xmlBody.substring( start+10 );
-                    end  = temp.indexOf( "</" );
-                    timestamp = temp.substring( 0, end );
-                    //logger.debug( "timestamp " + timestamp );
-                }
-                else timestamp = "";
-        
-                start  = xmlBody.indexOf( "Signature>" );
-                if ( -1 < start )
-                {
-                    temp = xmlBody.substring( start+10 );
-                    end  = temp.indexOf( "</" );
-                    msgSig = temp.substring( 0, end );
-                    //logger.debug( "signature " + msgSig );
-                }
-                else msgSig = "";
+                temp = xmlBody.substring( start+10 );
+                end  = temp.indexOf( "</" );
+                timestamp = temp.substring( 0, end );
+                //logger.debug( "timestamp " + timestamp );
             }
-    	}
-    	catch( Exception e )
-    	{
+            else timestamp = "";
+
+            start  = xmlBody.indexOf( "Signature>" );
+            if ( -1 < start )
+            {
+                temp = xmlBody.substring( start+10 );
+                end  = temp.indexOf( "</" );
+                msgSig = temp.substring( 0, end );
+                //logger.debug( "signature " + msgSig );
+            }
+            else msgSig = "";
+        }
+        }
+        catch( Exception e )
+        {
             logger.error("Signature calculation failed due to: ", e);
-    		throw new AxisFault( e.toString(), "Server.InternalError" );
-    	}
-    	
-    	
-    	// [B] Verify that the given signature matches what we calculated here
-    	if (null == secretKey)
-    	{
-    	     logger.error( "Unknown AWSAccessKeyId: [" + accessKey + "]" );
-    		 throw new AxisFault( "Unknown AWSAccessKeyId: [" + accessKey + "]", "Client.InvalidAccessKeyId" );
-    	}
-    	
+            throw new AxisFault( e.toString(), "Server.InternalError" );
+        }
+
+
+        // [B] Verify that the given signature matches what we calculated here
+        if (null == secretKey)
+        {
+            logger.error( "Unknown AWSAccessKeyId: [" + accessKey + "]" );
+            throw new AxisFault( "Unknown AWSAccessKeyId: [" + accessKey + "]", "Client.InvalidAccessKeyId" );
+        }
+
         // -> for SOAP requests the Cloud API keys are sent here and only here
-    	S3SoapAuth.verifySignature( msgSig, operation, timestamp, accessKey, secretKey );   	
+        S3SoapAuth.verifySignature( msgSig, operation, timestamp, accessKey, secretKey );   	
         UserContext.current().initContext( accessKey, secretKey, accessKey, "S3 SOAP request", httpObj );
         return InvocationResponse.CONTINUE;
-     }
-
-     
-     public void revoke(MessageContext msgContext) 
-     {
-         logger.info(msgContext.getEnvelope().toString());
-     }
-
-     public void setName(String name) 
-     {
-    	 //logger.debug( "setName entry S3AuthenticationHandler " + name );
-         this.name = name;
-     }
-     
-     /**
-      * Given the user's access key, then obtain his secret key in the user database.
-      * 
-      * @param accessKey - a unique string allocated for each registered user
-      * @return the secret key or null of no matching user found
-      */
-     private String lookupSecretKey( String accessKey )
-	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-     {
-	    UserCredentialsVO cloudKeys = ucDao.getByAccessKey( accessKey );
-	    if ( null == cloudKeys ) {
-	    	 logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
-	         return null; 
-	    }
-		else return cloudKeys.getSecretKey(); 
-     }
-
-	 @Override
-	 public void cleanup() 
-	 {
-      	//logger.debug( "cleanup entry S3AuthenticationHandler " );
-	 }
-
-	 @Override
-	 public void flowComplete( MessageContext arg0 ) 
-	 {
-     	//logger.debug( "flowComplete entry S3AuthenticationHandler " );
-	 }
+    }
+
+
+    public void revoke(MessageContext msgContext) 
+    {
+        logger.info(msgContext.getEnvelope().toString());
+    }
+
+    public void setName(String name) 
+    {
+        //logger.debug( "setName entry S3AuthenticationHandler " + name );
+        this.name = name;
+    }
+
+    /**
+     * Given the user's access key, then obtain his secret key in the user database.
+     * 
+     * @param accessKey - a unique string allocated for each registered user
+     * @return the secret key or null of no matching user found
+     */
+    private String lookupSecretKey( String accessKey )
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+            {
+        UserCredentialsVO cloudKeys = ucDao.getByAccessKey( accessKey );
+        if ( null == cloudKeys ) {
+            logger.debug( accessKey + " is not defined in the S3 service - call SetUserKeys" );
+            return null; 
+        }
+        else return cloudKeys.getSecretKey(); 
+            }
+
+    @Override
+    public void cleanup() 
+    {
+        //logger.debug( "cleanup entry S3AuthenticationHandler " );
+    }
+
+    @Override
+    public void flowComplete( MessageContext arg0 ) 
+    {
+        //logger.debug( "flowComplete entry S3AuthenticationHandler " );
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
index ce230c3..dd354a3 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
@@ -23,7 +23,6 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.bridge.model.BucketPolicyVO;
-import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -33,43 +32,43 @@ import com.cloud.utils.db.Transaction;
 @Local(value={BucketPolicyDao.class})
 public class BucketPolicyDaoImpl extends GenericDaoBase<BucketPolicyVO, Long> implements BucketPolicyDao{
     public static final Logger logger = Logger.getLogger(BucketPolicyDaoImpl.class);
-	public BucketPolicyDaoImpl(){ }
+    public BucketPolicyDaoImpl(){ }
 
-	/**
-	 * Since a bucket policy can exist before its bucket we also need to keep the policy's owner
-	 * so we can restrict who modifies it (because of the "s3:CreateBucket" action).
-	 */
-	@Override
-	public BucketPolicyVO getByName( String bucketName ) {
-	    SearchBuilder <BucketPolicyVO> searchByBucket = createSearchBuilder();
-	    searchByBucket.and("BucketName", searchByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
-	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+    /**
+     * Since a bucket policy can exist before its bucket we also need to keep the policy's owner
+     * so we can restrict who modifies it (because of the "s3:CreateBucket" action).
+     */
+    @Override
+    public BucketPolicyVO getByName( String bucketName ) {
+        SearchBuilder <BucketPolicyVO> searchByBucket = createSearchBuilder();
+        searchByBucket.and("BucketName", searchByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
         try {
             txn.start();
             SearchCriteria<BucketPolicyVO> sc = searchByBucket.create();
             sc.setParameters("BucketName", bucketName);
             return findOneBy(sc);
 
-	    }finally {
-		txn.close();
-	    }
-	    
-	}
-	
-	@Override
-	public void deletePolicy( String bucketName ) {
-	    SearchBuilder <BucketPolicyVO> deleteByBucket = createSearchBuilder();
-	    deleteByBucket.and("BucketName", deleteByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
-	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
-	    try {
+        }finally {
+            txn.close();
+        }
+
+    }
+
+    @Override
+    public void deletePolicy( String bucketName ) {
+        SearchBuilder <BucketPolicyVO> deleteByBucket = createSearchBuilder();
+        deleteByBucket.and("BucketName", deleteByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        try {
             txn.start();
             SearchCriteria<BucketPolicyVO> sc = deleteByBucket.create();
             sc.setParameters("BucketName", bucketName);
             remove(sc);
-		
-	    }finally {
-		txn.close();
-	    }
-	    
-	}
+
+        }finally {
+            txn.close();
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
index 511cfa7..e770611 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
@@ -16,18 +16,12 @@
 // under the License.
 package com.cloud.bridge.persist.dao;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
 import javax.ejb.Local;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.bridge.model.CloudStackConfigurationVO;
-import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
@@ -37,31 +31,31 @@ import com.cloud.utils.db.Transaction;
 @Component
 @Local(value={CloudStackConfigurationDao.class})
 public class CloudStackConfigurationDaoImpl extends GenericDaoBase<CloudStackConfigurationVO, String> implements CloudStackConfigurationDao {
-	private static final Logger s_logger = Logger.getLogger(CloudStackConfigurationDaoImpl.class);
-	
-	final SearchBuilder<CloudStackConfigurationVO> NameSearch= createSearchBuilder();
-	
-	public CloudStackConfigurationDaoImpl() { }
-	
-	
-	@Override
-	@DB
-	public String getConfigValue(String name) {
+    private static final Logger s_logger = Logger.getLogger(CloudStackConfigurationDaoImpl.class);
+
+    final SearchBuilder<CloudStackConfigurationVO> NameSearch= createSearchBuilder();
+
+    public CloudStackConfigurationDaoImpl() { }
+
+
+    @Override
+    @DB
+    public String getConfigValue(String name) {
         NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
         Transaction txn = Transaction.currentTxn();
-		try {
-			txn.start();
-			SearchCriteria<CloudStackConfigurationVO> sc = NameSearch.create();
-			sc.setParameters("name", name);
-			CloudStackConfigurationVO configItem = findOneBy(sc);
-			if (configItem == null) {
-				s_logger.warn("No configuration item found with name " + name);
-				return null;
-			}
-			return configItem.getValue();
+        try {
+            txn.start();
+            SearchCriteria<CloudStackConfigurationVO> sc = NameSearch.create();
+            sc.setParameters("name", name);
+            CloudStackConfigurationVO configItem = findOneBy(sc);
+            if (configItem == null) {
+                s_logger.warn("No configuration item found with name " + name);
+                return null;
+            }
+            return configItem.getValue();
         }finally {
-		
-		}
-	}
-	
+
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
index c9b5ec7..c1a69dc 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MultipartLoadDao.java
@@ -16,21 +16,13 @@
 // under the License.
 package com.cloud.bridge.persist.dao;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
-import java.util.Properties;
+
+import javax.inject.Inject;
 
 import org.apache.log4j.Logger;
 
@@ -40,71 +32,69 @@ import com.cloud.bridge.model.MultipartMetaVO;
 import com.cloud.bridge.service.core.s3.S3MetaDataEntry;
 import com.cloud.bridge.service.core.s3.S3MultipartPart;
 import com.cloud.bridge.service.core.s3.S3MultipartUpload;
-import com.cloud.bridge.util.ConfigurationHelper;
 import com.cloud.bridge.util.OrderedPair;
-import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.Transaction;
 
 public class MultipartLoadDao {
-	public static final Logger logger = Logger.getLogger(MultipartLoadDao.class);
-	
-	protected final MultipartMetaDao mpartMetaDao = ComponentLocator.inject(MultipartMetaDaoImpl.class);
-	protected final MultiPartPartsDao mpartPartsDao = ComponentLocator.inject(MultiPartPartsDaoImpl.class);
-	protected final MultiPartUploadsDao mpartUploadDao = ComponentLocator.inject(MultiPartUploadsDaoImpl.class);
-	
-	public MultipartLoadDao() {}
-	
-	/**
-	 * If a multipart upload exists with the uploadId value then return the non-null creators
-	 * accessKey.
-	 * 
-	 * @param uploadId
-	 * @return creator of the multipart upload, and NameKey of upload
-	 */
-	
-	
-	public OrderedPair<String,String> multipartExits( int uploadId ) 
-	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-	    return mpartUploadDao.multipartExits(uploadId);
-	}
-	
-	/**
-	 * The multipart upload was either successfully completed or was aborted.   In either case, we need
-	 * to remove all of its state from the tables.   Note that we have cascade deletes so all tables with
-	 * uploadId as a foreign key are automatically cleaned.
-	 * 
-	 * @param uploadId
-	 * 
-	 */
-	public void deleteUpload( int uploadId ) {
-	    mpartUploadDao.deleteUpload(uploadId);
-	}
-	
-	/**
-	 * The caller needs to know who initiated the multipart upload.
-	 * 
-	 * @param uploadId
-	 * @return the access key value defining the initiator
-	 */
-	public String getInitiator( int uploadId ) {
-	    return mpartUploadDao.getAtrributeValue("AccessKey", uploadId);
-	}
-	
-	/**
-	 * Create a new "in-process" multipart upload entry to keep track of its state.
-	 * 
-	 * @param accessKey
-	 * @param bucketName
-	 * @param key
-	 * @param cannedAccess
-	 * 
-	 * @return if positive its the uploadId to be returned to the client
-	 *
-	 */
-	public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta ) {
-		int uploadId = -1;
-		Transaction txn = null;
+    public static final Logger logger = Logger.getLogger(MultipartLoadDao.class);
+
+    @Inject MultipartMetaDao mpartMetaDao;
+    @Inject MultiPartPartsDao mpartPartsDao;
+    @Inject MultiPartUploadsDao mpartUploadDao;
+
+    public MultipartLoadDao() {}
+
+    /**
+     * If a multipart upload exists with the uploadId value then return the non-null creators
+     * accessKey.
+     * 
+     * @param uploadId
+     * @return creator of the multipart upload, and NameKey of upload
+     */
+
+
+    public OrderedPair<String,String> multipartExits( int uploadId ) 
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+            {
+        return mpartUploadDao.multipartExits(uploadId);
+            }
+
+    /**
+     * The multipart upload was either successfully completed or was aborted.   In either case, we need
+     * to remove all of its state from the tables.   Note that we have cascade deletes so all tables with
+     * uploadId as a foreign key are automatically cleaned.
+     * 
+     * @param uploadId
+     * 
+     */
+    public void deleteUpload( int uploadId ) {
+        mpartUploadDao.deleteUpload(uploadId);
+    }
+
+    /**
+     * The caller needs to know who initiated the multipart upload.
+     * 
+     * @param uploadId
+     * @return the access key value defining the initiator
+     */
+    public String getInitiator( int uploadId ) {
+        return mpartUploadDao.getAtrributeValue("AccessKey", uploadId);
+    }
+
+    /**
+     * Create a new "in-process" multipart upload entry to keep track of its state.
+     * 
+     * @param accessKey
+     * @param bucketName
+     * @param key
+     * @param cannedAccess
+     * 
+     * @return if positive its the uploadId to be returned to the client
+     *
+     */
+    public int initiateUpload( String accessKey, String bucketName, String key, String cannedAccess, S3MetaDataEntry[] meta ) {
+        int uploadId = -1;
+        Transaction txn = null;
         try {
             txn = Transaction.open(Transaction.AWSAPI_DB);
             Date tod = new Date();
@@ -126,26 +116,26 @@ public class MultipartLoadDao {
                     txn.commit();
                 }
             }
-            
+
             return uploadId;
         } finally {
             txn.close();
         }
     }
-	
-	/**
-	 * Remember all the individual parts that make up the entire multipart upload so that once
-	 * the upload is complete all the parts can be glued together into a single object.  Note, 
-	 * the caller can over write an existing part.
-	 * 
-	 * @param uploadId
-	 * @param partNumber
-	 * @param md5
-	 * @param storedPath
-	 * @param size
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	 */
-	public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size ) {
+
+    /**
+     * Remember all the individual parts that make up the entire multipart upload so that once
+     * the upload is complete all the parts can be glued together into a single object.  Note, 
+     * the caller can over write an existing part.
+     * 
+     * @param uploadId
+     * @param partNumber
+     * @param md5
+     * @param storedPath
+     * @param size
+     * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+     */
+    public void savePart( int uploadId, int partNumber, String md5, String storedPath, int size ) {
 
         try {
             MultiPartPartsVO partVO = null;
@@ -169,32 +159,32 @@ public class MultipartLoadDao {
         } finally {
         }
     }
-	
-	/**
-	 * It is possible for there to be a null canned access policy defined.
-	 * @param uploadId
-	 * @return the value defined in the x-amz-acl header or null
-	 */
-	public String getCannedAccess( int uploadId ) {
-	    return mpartUploadDao.getAtrributeValue("x_amz_acl", uploadId);
-	}
-	
-	/**
-	 * When the multipart are being composed into one object we need any meta data to be saved with
-	 * the new re-constituted object.
-	 * 
-	 * @param uploadId
-	 * @return an array of S3MetaDataEntry (will be null if no meta values exist)
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	 */
-	public S3MetaDataEntry[] getMeta( int uploadId )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-		List<S3MetaDataEntry> metaList = new ArrayList<S3MetaDataEntry>();
-	    int count = 0;
-	    List<MultipartMetaVO> metaVO; 
+
+    /**
+     * It is possible for there to be a null canned access policy defined.
+     * @param uploadId
+     * @return the value defined in the x-amz-acl header or null
+     */
+    public String getCannedAccess( int uploadId ) {
+        return mpartUploadDao.getAtrributeValue("x_amz_acl", uploadId);
+    }
+
+    /**
+     * When the multipart are being composed into one object we need any meta data to be saved with
+     * the new re-constituted object.
+     * 
+     * @param uploadId
+     * @return an array of S3MetaDataEntry (will be null if no meta values exist)
+     * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+     */
+    public S3MetaDataEntry[] getMeta( int uploadId )
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+            {
+        List<S3MetaDataEntry> metaList = new ArrayList<S3MetaDataEntry>();
+        int count = 0;
+        List<MultipartMetaVO> metaVO; 
         try {
-            
+
             metaVO = mpartMetaDao.getByUploadID(uploadId);
             for (MultipartMetaVO multipartMetaVO : metaVO) {
                 S3MetaDataEntry oneMeta = new S3MetaDataEntry();
@@ -203,42 +193,42 @@ public class MultipartLoadDao {
                 metaList.add( oneMeta );
                 count++;
             }
-            
+
             if ( 0 == count )
                 return null;
             else return metaList.toArray(new S3MetaDataEntry[0]);
-        
+
         } finally {
 
         }
-	}
-	
-	/** 
-	 * The result has to be ordered by key and if there is more than one identical key then all the 
-	 * identical keys are ordered by create time.
-	 * 
-	 * @param bucketName
-	 * @param maxParts
-	 * @param prefix - can be null
-	 * @param keyMarker - can be null
-	 * @param uploadIdMarker - can be null, should only be defined if keyMarker is not-null
-	 * @return OrderedPair<S3MultipartUpload[], isTruncated>
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	 */
-	public OrderedPair<S3MultipartUpload[],Boolean> getInitiatedUploads( String bucketName, int maxParts, String prefix, String keyMarker, String uploadIdMarker )
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-		S3MultipartUpload[] inProgress = new S3MultipartUpload[maxParts];
-	    boolean isTruncated = false;
-	    int i = 0;
-	    int pos = 1;
-	    List<MultiPartUploadsVO> uploadList;
-	    // -> SQL like condition requires the '%' as a wildcard marker
-	    if (null != prefix) prefix = prefix + "%";
-	    
+            }
+
+    /** 
+     * The result has to be ordered by key and if there is more than one identical key then all the 
+     * identical keys are ordered by create time.
+     * 
+     * @param bucketName
+     * @param maxParts
+     * @param prefix - can be null
+     * @param keyMarker - can be null
+     * @param uploadIdMarker - can be null, should only be defined if keyMarker is not-null
+     * @return OrderedPair<S3MultipartUpload[], isTruncated>
+     * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+     */
+    public OrderedPair<S3MultipartUpload[],Boolean> getInitiatedUploads( String bucketName, int maxParts, String prefix, String keyMarker, String uploadIdMarker )
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+            {
+        S3MultipartUpload[] inProgress = new S3MultipartUpload[maxParts];
+        boolean isTruncated = false;
+        int i = 0;
+        int pos = 1;
+        List<MultiPartUploadsVO> uploadList;
+        // -> SQL like condition requires the '%' as a wildcard marker
+        if (null != prefix) prefix = prefix + "%";
+
 
         try {
-		    uploadList = mpartUploadDao.getInitiatedUploads(bucketName, maxParts, prefix, keyMarker, uploadIdMarker);
+            uploadList = mpartUploadDao.getInitiatedUploads(bucketName, maxParts, prefix, keyMarker, uploadIdMarker);
             for (MultiPartUploadsVO uploadsVO : uploadList) {
                 Calendar tod = Calendar.getInstance();
                 tod.setTime(uploadsVO.getCreateTime());
@@ -258,33 +248,33 @@ public class MultipartLoadDao {
         }finally {
         }
 
-	}
-	
-	/**
-	 * Return info on a range of upload parts that have already been stored in disk.
-	 * Note that parts can be uploaded in any order yet we must returned an ordered list
-	 * of parts thus we use the "ORDERED BY" clause to sort the list.
-	 * 
-	 * @param uploadId
-	 * @param maxParts
-	 * @param startAt
-	 * @return an array of S3MultipartPart objects
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	 */
-	public S3MultipartPart[] getParts( int uploadId, int maxParts, int startAt ) 
-	    throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	{
-		S3MultipartPart[] parts = new S3MultipartPart[maxParts];
-	    int i = 0;
-	    List<MultiPartPartsVO> partsVO;
-	    try {
-	        
-	        partsVO = mpartPartsDao.getParts(uploadId, startAt + maxParts + 1, startAt);
-	        
-	        for (MultiPartPartsVO partVO : partsVO) {
+            }
+
+    /**
+     * Return info on a range of upload parts that have already been stored in disk.
+     * Note that parts can be uploaded in any order yet we must returned an ordered list
+     * of parts thus we use the "ORDERED BY" clause to sort the list.
+     * 
+     * @param uploadId
+     * @param maxParts
+     * @param startAt
+     * @return an array of S3MultipartPart objects
+     * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+     */
+    public S3MultipartPart[] getParts( int uploadId, int maxParts, int startAt ) 
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+            {
+        S3MultipartPart[] parts = new S3MultipartPart[maxParts];
+        int i = 0;
+        List<MultiPartPartsVO> partsVO;
+        try {
+
+            partsVO = mpartPartsDao.getParts(uploadId, startAt + maxParts + 1, startAt);
+
+            for (MultiPartPartsVO partVO : partsVO) {
                 Calendar tod = Calendar.getInstance();
                 tod.setTime(partVO.getCreateTime());
-                
+
                 parts[i] = new S3MultipartPart();
                 parts[i].setPartNumber(partVO.getPartNumber());
                 parts[i].setEtag(partVO.getMd5());
@@ -293,74 +283,74 @@ public class MultipartLoadDao {
                 parts[i].setPath(partVO.getStoredPath());
                 i++;
             }
-	        
+
             if (i < maxParts) parts = (S3MultipartPart[])resizeArray(parts,i);
             return parts;
-        
+
         } finally {
 
         }
-	}
-  
-	/**
-	 * How many parts exist after the endMarker part number?
-	 * 
-	 * @param uploadId
-	 * @param endMarker - can be used to see if getUploadedParts was truncated
-	 * @return number of parts with partNumber greater than endMarker
-	 * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-	 */
-	public int numParts( int uploadId, int endMarker ) {
-	    return mpartPartsDao.getnumParts(uploadId, endMarker);
+            }
+
+    /**
+     * How many parts exist after the endMarker part number?
+     * 
+     * @param uploadId
+     * @param endMarker - can be used to see if getUploadedParts was truncated
+     * @return number of parts with partNumber greater than endMarker
+     * @throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+     */
+    public int numParts( int uploadId, int endMarker ) {
+        return mpartPartsDao.getnumParts(uploadId, endMarker);
     }
 
-	/**
-	 * A multipart upload request can have zero to many meta data entries to be applied to the
-	 * final object.   We need to remember all of the objects meta data until the multipart is complete.
-	 * 
-	 * @param uploadId - defines an in-process multipart upload
-	 * @param meta - an array of meta data to be assocated with the uploadId value
-	 * 
-	 */
-	private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta ) {
-		if (null == meta) return;
-		
-		Transaction txn = null;
+    /**
+     * A multipart upload request can have zero to many meta data entries to be applied to the
+     * final object.   We need to remember all of the objects meta data until the multipart is complete.
+     * 
+     * @param uploadId - defines an in-process multipart upload
+     * @param meta - an array of meta data to be assocated with the uploadId value
+     * 
+     */
+    private void saveMultipartMeta( int uploadId, S3MetaDataEntry[] meta ) {
+        if (null == meta) return;
+
+        Transaction txn = null;
         try {
             txn = Transaction.open(Transaction.AWSAPI_DB);
             for( int i=0; i < meta.length; i++ ) 
             {
-               S3MetaDataEntry entry = meta[i];
-               MultipartMetaVO metaVO = new MultipartMetaVO();
-               metaVO.setUploadID(uploadId);
-               metaVO.setName(entry.getName());
-               metaVO.setValue(entry.getValue());
-               metaVO=mpartMetaDao.persist(metaVO);
+                S3MetaDataEntry entry = meta[i];
+                MultipartMetaVO metaVO = new MultipartMetaVO();
+                metaVO.setUploadID(uploadId);
+                metaVO.setName(entry.getName());
+                metaVO.setValue(entry.getValue());
+                metaVO=mpartMetaDao.persist(metaVO);
             }
             txn.commit();
         } finally {
             txn.close();
         }
-	}
-	
-
-	/**
-    * Reallocates an array with a new size, and copies the contents
-    * of the old array to the new array.
-    * 
-    * @param oldArray  the old array, to be reallocated.
-    * @param newSize   the new array size.
-    * @return          A new array with the same contents.
-    */
+    }
+
+
+    /**
+     * Reallocates an array with a new size, and copies the contents
+     * of the old array to the new array.
+     * 
+     * @param oldArray  the old array, to be reallocated.
+     * @param newSize   the new array size.
+     * @return          A new array with the same contents.
+     */
     private static Object resizeArray(Object oldArray, int newSize) 
     {
-       int oldSize = java.lang.reflect.Array.getLength(oldArray);
-       Class elementType = oldArray.getClass().getComponentType();
-       Object newArray = java.lang.reflect.Array.newInstance(
-             elementType,newSize);
-       int preserveLength = Math.min(oldSize,newSize);
-       if (preserveLength > 0)
-          System.arraycopy (oldArray,0,newArray,0,preserveLength);
-       return newArray; 
+        int oldSize = java.lang.reflect.Array.getLength(oldArray);
+        Class elementType = oldArray.getClass().getComponentType();
+        Object newArray = java.lang.reflect.Array.newInstance(
+                elementType,newSize);
+        int preserveLength = Math.min(oldSize,newSize);
+        if (preserveLength > 0)
+            System.arraycopy (oldArray,0,newArray,0,preserveLength);
+        return newArray; 
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
index 3e68152..6d23757 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/SObjectDaoImpl.java
@@ -22,16 +22,13 @@ import java.util.List;
 import java.util.Set;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import org.springframework.stereotype.Component;
 
-import com.cloud.bridge.model.SBucket;
 import com.cloud.bridge.model.SBucketVO;
 import com.cloud.bridge.model.SObjectItemVO;
 import com.cloud.bridge.model.SObjectVO;
-import com.cloud.bridge.util.EntityParam;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -40,18 +37,18 @@ import com.cloud.utils.db.Transaction;
 @Component
 @Local(value={SObjectDao.class})
 public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements SObjectDao {
-    protected final SObjectItemDao itemDao = ComponentLocator.inject(SObjectItemDaoImpl.class);
-    
-	public SObjectDaoImpl() {}
+    @Inject SObjectItemDao itemDao;
 
-	@Override
-	public SObjectVO getByNameKey(SBucketVO bucket, String nameKey) {
-		SObjectVO object = null; 
-	    SearchBuilder<SObjectVO> SearchByName = createSearchBuilder();
-	    SearchByName.and("SBucketID", SearchByName.entity().getBucketID() , SearchCriteria.Op.EQ);
-	    SearchByName.and("NameKey", SearchByName.entity().getNameKey() , SearchCriteria.Op.EQ);
-	    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
-	    try {
+    public SObjectDaoImpl() {}
+
+    @Override
+    public SObjectVO getByNameKey(SBucketVO bucket, String nameKey) {
+        SObjectVO object = null; 
+        SearchBuilder<SObjectVO> SearchByName = createSearchBuilder();
+        SearchByName.and("SBucketID", SearchByName.entity().getBucketID() , SearchCriteria.Op.EQ);
+        SearchByName.and("NameKey", SearchByName.entity().getNameKey() , SearchCriteria.Op.EQ);
+        Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+        try {
             txn.start();
             SearchCriteria<SObjectVO> sc = SearchByName.create();
             sc.setParameters("SBucketID", bucket.getId());
@@ -62,23 +59,23 @@ public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements S
                         itemDao.getItems(object.getId()));
                 object.setItems(items);
             }
-		return object;
-		
-	    }finally {
+            return object;
+
+        }finally {
             txn.close();
-	    }
-	    
-	}
-	
-	@Override
-	public List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
-		StringBuffer sb = new StringBuffer();
-		List<Object> params = new ArrayList<Object>();
-		SearchBuilder<SObjectVO> SearchByBucket = createSearchBuilder();
-		List<SObjectVO> objects = new ArrayList<SObjectVO>();
-		
-		SearchByBucket.and("SBucketID", SearchByBucket.entity().getBucketID(), SearchCriteria.Op.EQ);
-		SearchByBucket.and("DeletionMark", SearchByBucket.entity().getDeletionMark(), SearchCriteria.Op.NULL);		
+        }
+
+    }
+
+    @Override
+    public List<SObjectVO> listBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
+        StringBuffer sb = new StringBuffer();
+        List<Object> params = new ArrayList<Object>();
+        SearchBuilder<SObjectVO> SearchByBucket = createSearchBuilder();
+        List<SObjectVO> objects = new ArrayList<SObjectVO>();
+
+        SearchByBucket.and("SBucketID", SearchByBucket.entity().getBucketID(), SearchCriteria.Op.EQ);
+        SearchByBucket.and("DeletionMark", SearchByBucket.entity().getDeletionMark(), SearchCriteria.Op.NULL);		
         Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
         try {
             txn.start();
@@ -91,19 +88,19 @@ public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements S
             }
             return objects;
         }finally {
-        txn.close();
+            txn.close();
         }
-	}
-	
-	@Override
-	public List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
-		StringBuffer sb = new StringBuffer();
-		List<Object> params = new ArrayList<Object>();
-		SearchBuilder<SObjectVO> getAllBuckets = createSearchBuilder();
-		List<SObjectVO> objects = new ArrayList<SObjectVO>();
-		getAllBuckets.and("SBucketID", getAllBuckets.entity().getBucketID(), SearchCriteria.Op.EQ);
+    }
+
+    @Override
+    public List<SObjectVO> listAllBucketObjects(SBucketVO bucket, String prefix, String marker, int maxKeys) {
+        StringBuffer sb = new StringBuffer();
+        List<Object> params = new ArrayList<Object>();
+        SearchBuilder<SObjectVO> getAllBuckets = createSearchBuilder();
+        List<SObjectVO> objects = new ArrayList<SObjectVO>();
+        getAllBuckets.and("SBucketID", getAllBuckets.entity().getBucketID(), SearchCriteria.Op.EQ);
 
-		Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+        Transaction txn = Transaction.currentTxn();  // Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
         try {
             txn.start();
             SearchCriteria<SObjectVO> sc = getAllBuckets.create();
@@ -115,8 +112,8 @@ public class SObjectDaoImpl extends GenericDaoBase<SObjectVO, Long> implements S
             }
             return objects;
         }finally {
-        txn.close();
+            txn.close();
         }
-		
-	}
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java b/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java
index e8ccb0c..f5a2d21 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.util.UUID;
 
+import javax.inject.Inject;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -30,50 +31,48 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.log4j.Logger;
 
 import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
-import com.cloud.bridge.persist.dao.CloudStackConfigurationDaoImpl;
 import com.cloud.bridge.util.ConfigurationHelper;
-import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
-
-import net.sf.ehcache.Cache;
 @DB
 public class EC2MainServlet extends HttpServlet{
 
-	private static final long serialVersionUID = 2201599478145974479L;
-	
-	public static final String EC2_REST_SERVLET_PATH="/rest/AmazonEC2/";
-	public static final String EC2_SOAP_SERVLET_PATH="/services/AmazonEC2/";
-	public static final String ENABLE_EC2_API="enable.ec2.api";
-	private static boolean isEC2APIEnabled = false;
-	public static final Logger logger = Logger.getLogger(EC2MainServlet.class);
-	CloudStackConfigurationDao csDao = ComponentLocator.inject(CloudStackConfigurationDaoImpl.class);
-	
-	/**
-	 * We build the path to where the keystore holding the WS-Security X509 certificates
-	 * are stored.
-	 */
-	@DB
-	public void init( ServletConfig config ) throws ServletException {
-		try{
-		    ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
-    		// check if API is enabled
-    		String value = csDao.getConfigValue(ENABLE_EC2_API);
-    		if(value != null){
-    		    isEC2APIEnabled = Boolean.valueOf(value);
-    		}
-    		logger.info("Value of EC2 API Flag ::" + value);
-		}catch(Exception e){
-		    throw new ServletException("Error initializing awsapi: " + e.getMessage(), e);
-		}
-	}
-	
-	protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
-	    doGetOrPost(req, resp);
+    private static final long serialVersionUID = 2201599478145974479L;
+
+    public static final String EC2_REST_SERVLET_PATH="/rest/AmazonEC2/";
+    public static final String EC2_SOAP_SERVLET_PATH="/services/AmazonEC2/";
+    public static final String ENABLE_EC2_API="enable.ec2.api";
+    private static boolean isEC2APIEnabled = false;
+    public static final Logger logger = Logger.getLogger(EC2MainServlet.class);
+    @Inject CloudStackConfigurationDao csDao;
+
+    /**
+     * We build the path to where the keystore holding the WS-Security X509 certificates
+     * are stored.
+     */
+    @Override
+    @DB
+    public void init( ServletConfig config ) throws ServletException {
+        try{
+            ConfigurationHelper.preConfigureConfigPathFromServletContext(config.getServletContext());
+            // check if API is enabled
+            String value = csDao.getConfigValue(ENABLE_EC2_API);
+            if(value != null){
+                isEC2APIEnabled = Boolean.valueOf(value);
+            }
+            logger.info("Value of EC2 API Flag ::" + value);
+        }catch(Exception e){
+            throw new ServletException("Error initializing awsapi: " + e.getMessage(), e);
+        }
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
+        doGetOrPost(req, resp);
     }
-	
+
+    @Override
     protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
-	    doGetOrPost(req, resp);
+        doGetOrPost(req, resp);
     }
 
     protected void doGetOrPost(HttpServletRequest request, HttpServletResponse response) {
@@ -84,30 +83,30 @@ public class EC2MainServlet extends HttpServlet{
             faultResponse(response, "404" , "EC2 API is disabled.");
             return;
         }
-        
-    	if(action != null){
-    		//We presume it's a Query/Rest call
-    		try {
-				RequestDispatcher dispatcher = request.getRequestDispatcher(EC2_REST_SERVLET_PATH);
-				dispatcher.forward(request, response);
-			} catch (ServletException e) {
-				throw new RuntimeException(e);
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
-    	}
-    	else {
-    		try {
-				request.getRequestDispatcher(EC2_SOAP_SERVLET_PATH).forward(request, response);
-			} catch (ServletException e) {
-				throw new RuntimeException(e);
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
-    	}
-    	
+
+        if(action != null){
+            //We presume it's a Query/Rest call
+            try {
+                RequestDispatcher dispatcher = request.getRequestDispatcher(EC2_REST_SERVLET_PATH);
+                dispatcher.forward(request, response);
+            } catch (ServletException e) {
+                throw new RuntimeException(e);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        else {
+            try {
+                request.getRequestDispatcher(EC2_SOAP_SERVLET_PATH).forward(request, response);
+            } catch (ServletException e) {
+                throw new RuntimeException(e);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
     }
-    
+
     private void faultResponse(HttpServletResponse response, String errorCode, String errorMessage) {
         try {
             OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());