summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 12:18:38 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 12:18:38 +0000
commit1e498f068f962121836b475b2c22d45b713da71a (patch)
tree30ff9e6abf7e31cffd305468ba74a71bea7f28ba /java/sca/modules
parent60bc3fda9aaed67c76535ea34521397e327f098d (diff)
CHange webapp host so it doesn't need any static singleton (TUSCANY-2881) and make webapp host only be used if no other hosts (like jetty) are in the classpath
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@748109 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/host-webapp/pom.xml2
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java39
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java7
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java12
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java10
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java4
6 files changed, 46 insertions, 28 deletions
diff --git a/java/sca/modules/host-webapp/pom.xml b/java/sca/modules/host-webapp/pom.xml
index 7db27b458b..60e1a21cdd 100644
--- a/java/sca/modules/host-webapp/pom.xml
+++ b/java/sca/modules/host-webapp/pom.xml
@@ -46,14 +46,12 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-api</artifactId>
<version>2.0-SNAPSHOT</version>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl</artifactId>
<version>2.0-SNAPSHOT</version>
- <scope>runtime</scope>
</dependency>
<dependency>
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
index 9cbd9de57f..470428bb05 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
@@ -29,6 +29,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.List;
import java.util.logging.Logger;
import javax.naming.InitialContext;
@@ -37,10 +38,13 @@ import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
import org.oasisopen.sca.ServiceRuntimeException;
public class ServletHostHelper {
@@ -48,31 +52,30 @@ public class ServletHostHelper {
public static final String SCA_NODE_ATTRIBUTE = Node.class.getName();
- public static ServletHost getServletHost() {
- return WebAppServletHost.getInstance();
- }
+// public static ServletHost getServletHost() {
+// return WebAppServletHost.getInstance();
+// }
public static void init(ServletConfig servletConfig) {
init(servletConfig.getServletContext());
}
- public static void init(final ServletContext servletContext) {
- if (servletContext.getAttribute(SCA_NODE_ATTRIBUTE) == null) {
+ public static ServletHost init(final ServletContext servletContext) {
+ Node node = (Node)servletContext.getAttribute(SCA_NODE_ATTRIBUTE);
+ if (node == null) {
try {
- servletContext.setAttribute(SCA_NODE_ATTRIBUTE, createNode(servletContext));
- WebAppServletHost.getInstance().init(new ServletConfig() {
+ node = createNode(servletContext);
+ servletContext.setAttribute(SCA_NODE_ATTRIBUTE, node);
+ getServletHost(node).init(new ServletConfig() {
public String getInitParameter(String name) {
return servletContext.getInitParameter(name);
}
-
public Enumeration<?> getInitParameterNames() {
return servletContext.getInitParameterNames();
}
-
public ServletContext getServletContext() {
return servletContext;
}
-
public String getServletName() {
return servletContext.getServletContextName();
}});
@@ -80,8 +83,24 @@ public class ServletHostHelper {
throw new RuntimeException(e);
}
}
+ return getServletHost(node);
}
+ private static WebAppServletHost getServletHost(Node node) {
+ NodeImpl nodeImpl = (NodeImpl) node;
+ ExtensionPointRegistry eps = nodeImpl.getExtensionPoints();
+ ServletHostExtensionPoint servletHosts = eps.getExtensionPoint(ServletHostExtensionPoint.class);
+ List<ServletHost> hosts = servletHosts.getServletHosts();
+ if (hosts == null || hosts.size() < 1) {
+ throw new IllegalStateException("No ServletHost found");
+ }
+ ServletHost servletHost = hosts.get(0);
+ if (!(servletHost instanceof WebAppServletHost)) {
+ throw new IllegalStateException("unexpected ServletHost type: " + servletHost);
+ }
+ return (WebAppServletHost) servletHost;
+ }
+
private static Node createNode(final ServletContext servletContext) throws ServletException {
String contextPath = initContextPath(servletContext);
String contributionRoot = getContributionRoot(servletContext);
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
index 599d852c0e..359817e024 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
@@ -30,6 +30,8 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import org.apache.tuscany.sca.host.http.ServletHost;
+
/**
* A Servlet filter that forwards service requests to the Servlets registered with
@@ -41,10 +43,11 @@ public class TuscanyServletFilter implements Filter {
private static final long serialVersionUID = 1L;
private transient ServletContext context;
+ private transient ServletHost servletHost;
public void init(final FilterConfig config) throws ServletException {
context = config.getServletContext();
- ServletHostHelper.init(context);
+ servletHost = ServletHostHelper.init(context);
}
public void destroy() {
@@ -65,7 +68,7 @@ public class TuscanyServletFilter implements Filter {
}
// Get a request dispatcher for the Servlet mapped to that path
- RequestDispatcher dispatcher = ServletHostHelper.getServletHost().getRequestDispatcher(path);
+ RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path);
if (dispatcher != null) {
// Let the dispatcher forward the request to the Servlet
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
index 7e8933e6aa..d07b19bca9 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
@@ -39,15 +39,9 @@ public class WebAppModuleActivator implements ModuleActivator {
extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
List<ServletHost> hosts = servletHosts.getServletHosts();
- ServletHost host = null;
- try {
- host = ServletHostHelper.getServletHost();
- } catch (NoClassDefFoundError e) {
- // ignore
- }
- if (host != null) {
- hosts.clear();
- hosts.add(host);
+ // Only add webapp host if no other host already registered (eg jetty in standalone)
+ if (hosts != null && hosts.size() < 1) {
+ hosts.add(new WebAppServletHost());
}
}
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
index feb35c2bce..f05203f5e8 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
@@ -51,7 +51,7 @@ public class WebAppServletHost implements ServletHost {
public static final String SCA_NODE_ATTRIBUTE = Node.class.getName();
- private static final WebAppServletHost instance = new WebAppServletHost();
+// private static final WebAppServletHost instance = new WebAppServletHost();
private Map<String, Servlet> servlets;
private String contextPath = "/";
@@ -61,7 +61,7 @@ public class WebAppServletHost implements ServletHost {
private ServletContext servletContext;
private Map<String, Object> tempAttributes = new HashMap<String, Object>();
- WebAppServletHost() {
+ public WebAppServletHost() {
servlets = new HashMap<String, Servlet>();
}
@@ -199,9 +199,9 @@ public class WebAppServletHost implements ServletHost {
return null;
}
- public static WebAppServletHost getInstance() {
- return instance;
- }
+// public static WebAppServletHost getInstance() {
+// return instance;
+// }
public void init(ServletConfig config) throws ServletException {
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index 786bf6840e..a32180959f 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -712,4 +712,8 @@ public class NodeImpl implements Node, Client {
}
throw new ServiceRuntimeException("no deployable composite found");
}
+
+ public ExtensionPointRegistry getExtensionPoints() {
+ return extensionPoints;
+ }
}