summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/host-webapp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/host-webapp/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java5
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java3
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java3
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java50
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebContextConfigurator.java22
5 files changed, 46 insertions, 37 deletions
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
index d71abdacb2..8959293d71 100644
--- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
@@ -25,7 +25,6 @@ import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import org.apache.tuscany.sca.host.webapp.WebAppHelper.Configurator;
/**
* A ServletContextListener to create and close the SCADomain
@@ -38,7 +37,7 @@ public class TuscanyContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
logger.info(event.getServletContext().getServletContextName() + " is starting.");
try {
- Configurator configurator = WebAppHelper.getConfigurator(event.getServletContext());
+ WebContextConfigurator configurator = WebAppHelper.getConfigurator(event.getServletContext());
WebAppHelper.init(configurator);
} catch (Throwable e) {
logger.log(Level.SEVERE, e.getMessage(), e);
@@ -52,7 +51,7 @@ public class TuscanyContextListener implements ServletContextListener {
return;
}
try {
- Configurator configurator = WebAppHelper.getConfigurator(event.getServletContext());
+ WebContextConfigurator configurator = WebAppHelper.getConfigurator(event.getServletContext());
WebAppHelper.stop(configurator);
} catch (Throwable e) {
logger.log(Level.SEVERE, e.getMessage(), e);
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
index 6f5c35d3fb..e8c8d941ff 100644
--- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
@@ -26,7 +26,6 @@ import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
-import org.apache.tuscany.sca.host.webapp.WebAppHelper.Configurator;
/**
* A Servlet that provides a hook to control the lifecycle of Tuscany node
@@ -37,7 +36,7 @@ public class TuscanyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(TuscanyServlet.class.getName());
- private transient Configurator configurator;
+ private transient WebContextConfigurator configurator;
public TuscanyServlet() {
super();
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
index a3800f221b..f058e03788 100644
--- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
@@ -32,7 +32,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.tuscany.sca.host.http.ServletHost;
-import org.apache.tuscany.sca.host.webapp.WebAppHelper.Configurator;
/**
* A Servlet filter that forwards service requests to the Servlets registered with
@@ -44,7 +43,7 @@ public class TuscanyServletFilter implements Filter {
private static final long serialVersionUID = 1L;
private Logger logger = Logger.getLogger(TuscanyServletFilter.class.getName());
- private transient Configurator configurator;
+ private transient WebContextConfigurator configurator;
private transient ServletHost servletHost;
public TuscanyServletFilter() {
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java
index 2001067e16..41503f1cac 100644
--- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java
@@ -106,7 +106,7 @@ public class WebAppHelper {
return host;
}
- public static Node init(final Configurator configurator) {
+ public static Node init(final WebContextConfigurator configurator) {
synchronized (configurator) {
bootstrapRuntime(configurator);
@@ -127,7 +127,7 @@ public class WebAppHelper {
* Bootstrap the Tuscany runtime for the given scope
* @param configurator
*/
- private synchronized static void bootstrapRuntime(final Configurator configurator) {
+ private synchronized static void bootstrapRuntime(final WebContextConfigurator configurator) {
if (host == null) {
try {
@@ -154,7 +154,7 @@ public class WebAppHelper {
}
}
- private static WebAppServletHost getServletHost(final Configurator configurator) throws ServletException {
+ private static WebAppServletHost getServletHost(final WebContextConfigurator configurator) throws ServletException {
ExtensionPointRegistry registry = factory.getExtensionPointRegistry();
WebAppServletHost host =
(WebAppServletHost)org.apache.tuscany.sca.host.http.ServletHostHelper.getServletHost(registry);
@@ -179,7 +179,7 @@ public class WebAppHelper {
return host;
}
- private static Node createAndStartNode(final Configurator configurator) throws ServletException {
+ private static Node createAndStartNode(final WebContextConfigurator configurator) throws ServletException {
NodeConfiguration configuration = null;
try {
configuration = getNodeConfiguration(configurator);
@@ -195,7 +195,7 @@ public class WebAppHelper {
return node;
}
- public static void stop(Configurator configurator) {
+ public static void stop(WebContextConfigurator configurator) {
Node node = (Node)configurator.getAttribute(SCA_NODE_ATTRIBUTE);
if (node != null) {
node.stop();
@@ -215,7 +215,7 @@ public class WebAppHelper {
return factory;
}
- private static String getDefaultComposite(Configurator configurator) {
+ private static String getDefaultComposite(WebContextConfigurator configurator) {
String name = configurator.getName();
if ("".equals(name)) {
return "/WEB-INF/web.composite";
@@ -224,7 +224,7 @@ public class WebAppHelper {
}
}
- private static NodeConfiguration getNodeConfiguration(Configurator configurator) throws IOException,
+ private static NodeConfiguration getNodeConfiguration(WebContextConfigurator configurator) throws IOException,
URISyntaxException {
NodeConfiguration configuration = null;
String nodeConfigURI = configurator.getInitParameter(NODE_CONFIGURATION);
@@ -234,6 +234,11 @@ public class WebAppHelper {
configuration = factory.loadConfiguration(url.openStream(), url);
} else {
configuration = factory.createNodeConfiguration();
+
+ configuration.setAttribute(ServletContext.class.getName(), servletContext);
+ if(configurator instanceof ServletConfigurator) {
+ configuration.setAttribute(Servlet.class.getName(), ((ServletConfigurator) configurator).servlet);
+ }
boolean explicitContributions = false;
Enumeration<String> names = configurator.getInitParameterNames();
@@ -320,36 +325,19 @@ public class WebAppHelper {
return configuration;
}
- static Configurator getConfigurator(FilterConfig config) {
+ public static WebContextConfigurator getConfigurator(FilterConfig config) {
return new FilterConfigurator(config);
}
- static Configurator getConfigurator(ServletContext context) {
+ public static WebContextConfigurator getConfigurator(ServletContext context) {
return new ServletContextConfigurator(context);
}
- static Configurator getConfigurator(Servlet context) {
+ public static WebContextConfigurator getConfigurator(Servlet context) {
return new ServletConfigurator(context);
}
- /**
- * The interface that represents a given scope (Webapp vs Servlet) that provides the configuration of the Tuscany node
- */
- public static interface Configurator {
- String getInitParameter(String name);
-
- Enumeration<String> getInitParameterNames();
-
- ServletContext getServletContext();
-
- void setAttribute(String name, Object value);
-
- <T> T getAttribute(String name);
-
- String getName();
- }
-
- public static class FilterConfigurator implements Configurator {
+ public static class FilterConfigurator implements WebContextConfigurator {
private FilterConfig config;
public FilterConfigurator(FilterConfig config) {
@@ -395,7 +383,7 @@ public class WebAppHelper {
}
- public static class ServletContextConfigurator implements Configurator {
+ public static class ServletContextConfigurator implements WebContextConfigurator {
private ServletContext context;
public ServletContextConfigurator(ServletContext context) {
@@ -428,11 +416,13 @@ public class WebAppHelper {
}
}
- public static class ServletConfigurator implements Configurator {
+ public static class ServletConfigurator implements WebContextConfigurator {
private ServletConfig config;
+ private Servlet servlet;
public ServletConfigurator(Servlet servlet) {
super();
+ this.servlet = servlet;
this.config = servlet.getServletConfig();
}
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebContextConfigurator.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebContextConfigurator.java
new file mode 100644
index 0000000000..66408f26d4
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebContextConfigurator.java
@@ -0,0 +1,22 @@
+package org.apache.tuscany.sca.host.webapp;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletContext;
+
+/**
+ * The interface that represents a given scope (Webapp vs Servlet) that provides the configuration of the Tuscany node
+ */
+public interface WebContextConfigurator {
+ String getInitParameter(String name);
+
+ Enumeration<String> getInitParameterNames();
+
+ ServletContext getServletContext();
+
+ void setAttribute(String name, Object value);
+
+ <T> T getAttribute(String name);
+
+ String getName();
+} \ No newline at end of file