Skip to content

Commit 2bfdce0

Browse files
author
Prachi Damle
committed
Spring changes in awsapi
1 parent 4c1a69a commit 2bfdce0

6 files changed

Lines changed: 125 additions & 2 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:context="http://www.springframework.org/schema/context"
22+
xmlns:tx="http://www.springframework.org/schema/tx"
23+
xmlns:aop="http://www.springframework.org/schema/aop"
24+
xsi:schemaLocation="http://www.springframework.org/schema/beans
25+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
26+
http://www.springframework.org/schema/tx
27+
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
28+
http://www.springframework.org/schema/aop
29+
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
30+
http://www.springframework.org/schema/context
31+
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
32+
33+
<context:annotation-config />
34+
35+
<context:component-scan base-package="com.amazon, com.cloud" />
36+
37+
<!--
38+
@DB support
39+
-->
40+
<aop:config proxy-target-class="true">
41+
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
42+
<aop:pointcut id="captureAnyMethod"
43+
expression="execution(* *(..))"
44+
/>
45+
46+
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod"/>
47+
</aop:aspect>
48+
49+
</aop:config>
50+
51+
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
52+
53+
</beans>

awsapi/pom.xml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@
304304
</resource>
305305
</resources>
306306
<plugins>
307+
<plugin>
308+
<groupId>org.apache.maven.plugins</groupId>
309+
<artifactId>maven-war-plugin</artifactId>
310+
<version>2.3</version>
311+
<configuration>
312+
<webXml>./web/web.xml</webXml>
313+
<warSourceDirectory>./target/generated-webapp</warSourceDirectory>
314+
</configuration>
315+
</plugin>
307316
<plugin>
308317
<groupId>org.mortbay.jetty</groupId>
309318
<artifactId>maven-jetty-plugin</artifactId>
@@ -319,7 +328,38 @@
319328
<webXml>${basedir}/web/web.xml</webXml>
320329
<webAppSourceDirectory>${basedir}/target/cloud-awsapi-${project.version}</webAppSourceDirectory>
321330
</configuration>
322-
</plugin>
331+
</plugin>
332+
<plugin>
333+
<artifactId>maven-antrun-plugin</artifactId>
334+
<version>1.7</version>
335+
<executions>
336+
<execution>
337+
<id>generate-resource</id>
338+
<phase>generate-resources</phase>
339+
<goals>
340+
<goal>run</goal>
341+
</goals>
342+
<configuration>
343+
<target>
344+
<copy
345+
todir="${basedir}/target/generated-webapp/WEB-INF/classes">
346+
<fileset dir="${basedir}/conf">
347+
<include name="*.*" />
348+
</fileset>
349+
<globmapper from="*.in" to="*" />
350+
<filterchain>
351+
<filterreader
352+
classname="org.apache.tools.ant.filters.ReplaceTokens">
353+
<param type="propertiesfile"
354+
value="${basedir}/../build/replace.properties" />
355+
</filterreader>
356+
</filterchain>
357+
</copy>
358+
</target>
359+
</configuration>
360+
</execution>
361+
</executions>
362+
</plugin>
323363
</plugins>
324364
<!--
325365
<plugins>

awsapi/src/com/cloud/bridge/service/EC2MainServlet.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.cloud.bridge.service;
1818

1919
import java.io.IOException;
20+
2021
import java.io.OutputStreamWriter;
2122
import java.util.UUID;
2223

24+
import javax.annotation.PostConstruct;
2325
import javax.inject.Inject;
2426
import javax.servlet.RequestDispatcher;
2527
import javax.servlet.ServletConfig;
@@ -29,10 +31,13 @@
2931
import javax.servlet.http.HttpServletResponse;
3032

3133
import org.apache.log4j.Logger;
34+
import org.springframework.stereotype.Component;
3235

3336
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
3437
import com.cloud.bridge.util.ConfigurationHelper;
3538
import com.cloud.utils.db.DB;
39+
40+
@Component("EC2MainServlet")
3641
@DB
3742
public class EC2MainServlet extends HttpServlet{
3843

@@ -44,7 +49,23 @@ public class EC2MainServlet extends HttpServlet{
4449
private static boolean isEC2APIEnabled = false;
4550
public static final Logger logger = Logger.getLogger(EC2MainServlet.class);
4651
@Inject CloudStackConfigurationDao csDao;
47-
52+
static CloudStackConfigurationDao s_csDao;
53+
54+
public EC2MainServlet() {
55+
}
56+
57+
@PostConstruct
58+
void initComponent() {
59+
// Servlet injection does not always work for servlet container
60+
// We use a hacking here to initialize static variables at Spring wiring time
61+
if(csDao != null) {
62+
s_csDao = csDao;
63+
} else {
64+
csDao = s_csDao;
65+
}
66+
}
67+
68+
4869
/**
4970
* We build the path to where the keystore holding the WS-Security X509 certificates
5071
* are stored.

awsapi/web/web.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
2323

2424
<web-app>
25+
26+
<listener>
27+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
28+
</listener>
29+
<context-param>
30+
<param-name>contextConfigLocation</param-name>
31+
<param-value>classpath:applicationContext.xml</param-value>
32+
</context-param>
33+
2534
<display-name>CloudBridge</display-name>
2635
<servlet>
2736
<servlet-name>EC2MainServlet</servlet-name>

0 commit comments

Comments
 (0)