diff options
Diffstat (limited to 'java/sca/samples/webapps')
3 files changed, 20 insertions, 10 deletions
diff --git a/java/sca/samples/webapps/helloworld-servlet/pom.xml b/java/sca/samples/webapps/helloworld-servlet/pom.xml index 31031ac5f5..e8d4d28230 100644 --- a/java/sca/samples/webapps/helloworld-servlet/pom.xml +++ b/java/sca/samples/webapps/helloworld-servlet/pom.xml @@ -34,21 +34,21 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-sca-api</artifactId> + <artifactId>tuscany-implementation-web-runtime</artifactId> <version>2.0-SNAPSHOT</version> - <scope>provided</scope> </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.5</version> - <scope>provided</scope> - </dependency> </dependencies> <build> <finalName>${artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>maven-jetty-plugin</artifactId> + <version>6.1.18</version> + </plugin> + </plugins> </build> </project> diff --git a/java/sca/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java b/java/sca/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java index 2265bfa8ea..bb72c50f6a 100644 --- a/java/sca/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java +++ b/java/sca/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java @@ -21,10 +21,13 @@ package sample; import java.io.IOException; import java.io.Writer; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.oasisopen.sca.ComponentContext; import org.oasisopen.sca.annotation.Reference; /** @@ -35,8 +38,13 @@ public class HelloworldServlet extends HttpServlet { @Reference protected HelloworldService service; - public HelloworldServlet() { - System.out.println("HelloworldServlet"); + @Override + public void init(ServletConfig servletConfig) throws ServletException { + if (service == null) { + System.out.println("HelloworldServlet reference injection failed, using ComponentContext"); + ComponentContext cc = (ComponentContext)servletConfig.getServletContext().getAttribute("org.oasisopen.sca.ComponentContext"); + service = cc.getService(HelloworldService.class, "service"); + } } @Override diff --git a/java/sca/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml b/java/sca/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml index 6cfcae0005..a91b3fc96b 100644 --- a/java/sca/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml +++ b/java/sca/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml @@ -24,6 +24,8 @@ <display-name>Apache Tuscany Helloworld Servlet Sample</display-name> + <listener><listener-class>org.apache.tuscany.sca.host.webapp.TuscanyContextListener</listener-class></listener> + <servlet> <servlet-name>HelloworldServlet</servlet-name> <servlet-class>sample.HelloworldServlet</servlet-class> |