tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r713566 - in /tuscany/branches/sca-equinox/modules/host-webapp: ./ META-INF/ src/main/java/org/apache/tuscany/sca/host/webapp/ src/main/java/org/apache/tuscany/sca/host/webapp/jsp/
Date Wed, 12 Nov 2008 23:45:11 GMT
Author: rfeng
Date: Wed Nov 12 15:45:10 2008
New Revision: 713566

URL: http://svn.apache.org/viewvc?rev=713566&view=rev
Log:
Update the host-webapp to use Node API

Removed:
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebSCADomain.java
Modified:
    tuscany/branches/sca-equinox/modules/host-webapp/META-INF/MANIFEST.MF
    tuscany/branches/sca-equinox/modules/host-webapp/pom.xml
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
    tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java

Modified: tuscany/branches/sca-equinox/modules/host-webapp/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/META-INF/MANIFEST.MF?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/META-INF/MANIFEST.MF (original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/META-INF/MANIFEST.MF Wed Nov 12 15:45:10
2008
@@ -15,13 +15,17 @@
 Bundle-ManifestVersion: 2
 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
 Bundle-Description: Apache Tuscany SCA Webapp Host
-Import-Package: javax.naming,javax.servlet,javax.servlet.http,javax.se
- rvlet.jsp,javax.servlet.jsp.tagext,org.apache.tuscany.sca.core;versio
- n="1.4",org.apache.tuscany.sca.host.embedded;version="1.4",org.apache
- .tuscany.sca.host.embedded.impl;version="1.4",org.apache.tuscany.sca.
- host.http;version="1.4",org.apache.tuscany.sca.host.webapp;version="1
- .4",org.apache.tuscany.sca.host.webapp.jsp;version="1.4",org.osoa.sca
- ;version="1.4"
+Import-Package: javax.naming,
+ javax.servlet,
+ javax.servlet.http,
+ javax.servlet.jsp,
+ javax.servlet.jsp.tagext,
+ org.apache.tuscany.sca.core;version="1.4",
+ org.apache.tuscany.sca.host.http;version="1.4",
+ org.apache.tuscany.sca.host.webapp;version="1.4",
+ org.apache.tuscany.sca.host.webapp.jsp;version="1.4",
+ org.apache.tuscany.sca.node;version="1.4.0",
+ org.osoa.sca;version="1.4"
 Bundle-SymbolicName: org.apache.tuscany.sca.host.webapp
 Bundle-DocURL: http://www.apache.org/
 

Modified: tuscany/branches/sca-equinox/modules/host-webapp/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/pom.xml?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/pom.xml (original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/pom.xml Wed Nov 12 15:45:10 2008
@@ -41,7 +41,14 @@
             <artifactId>tuscany-host-http</artifactId>
 	        <version>1.4-SNAPSHOT</version>
         </dependency>
-        
+       
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-node-api</artifactId>
+            <version>1.4-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+                
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node-impl</artifactId>

Modified: tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
(original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java
Wed Nov 12 15:45:10 2008
@@ -20,7 +20,10 @@
 package org.apache.tuscany.sca.host.webapp;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Enumeration;
+import java.util.Map;
+import java.util.WeakHashMap;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterConfig;
@@ -32,6 +35,8 @@
 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
  * the Tuscany ServletHost.
@@ -42,11 +47,21 @@
     private static final long serialVersionUID = 1L;
     //private static final Logger logger = Logger.getLogger(WebAppServletHost.class.getName());
 
-    private WebAppServletHost servletHost;
+    private static Map<ClassLoader, ServletHost> servletHosts =
+        Collections.synchronizedMap(new WeakHashMap<ClassLoader, ServletHost>());
+
+    // [REVIEW] Assume the filter class is per webapp
+    private static WebAppServletHost servletHost;
+
+    // Test if the servletHost == null to know if the filter is called (webapp)
+    static ServletHost getServletHost() {
+        return servletHosts.get(Thread.currentThread().getContextClassLoader());
+    }
 
     public void init(final FilterConfig config) throws ServletException {
         // TODO: must be a better way to get this than using a static
-        servletHost = WebAppServletHost.getInstance();
+        servletHost = new WebAppServletHost();
+        servletHosts.put(Thread.currentThread().getContextClassLoader(), servletHost);
 
         // Initialize the Servlet host
         servletHost.init(new ServletConfig() {
@@ -69,7 +84,11 @@
     }
 
     public void destroy() {
-        WebAppServletHost.getInstance().destroy();
+        if (servletHost != null) {
+            servletHost.destroy();
+            servletHost = null;
+            servletHosts.remove(Thread.currentThread().getContextClassLoader());
+        }
     }
 
     public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain
chain)

Modified: tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
(original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
Wed Nov 12 15:45:10 2008
@@ -37,30 +37,16 @@
 
         ServletHostExtensionPoint servletHosts =
             extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
-        
+
         List<ServletHost> hosts = servletHosts.getServletHosts();
-        if (isRunningInWebapp()) {
-            if (hosts.size() > 0) {
-                hosts.removeAll(hosts);
-            }
-            servletHosts.addServletHost(WebAppServletHost.getInstance());
+        ServletHost host = TuscanyServletFilter.getServletHost();
+        if (host != null) {
+            hosts.clear();
+            hosts.add(host);
         }
     }
 
     public void stop(ExtensionPointRegistry registry) {
     }
 
-    /**
-     * TODO: this seems a bit of a hacky way to find if its running in a webapp
-     *       is there a better way?
-     */
-    private boolean isRunningInWebapp() {
-        for (StackTraceElement ste : new Exception().getStackTrace()) {
-            if (ste.getClassName().equals(WebSCADomain.class.getName())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
 }

Modified: tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
(original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Wed Nov 12 15:45:10 2008
@@ -39,9 +39,11 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
-import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.apache.tuscany.sca.host.http.ServletHost;
 import org.apache.tuscany.sca.host.http.ServletMappingException;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
 
 /**
  * ServletHost implementation for use in a webapp environment.
@@ -54,19 +56,19 @@
 public class WebAppServletHost implements ServletHost {
     private static final Logger logger = Logger.getLogger(WebAppServletHost.class.getName());
 
-    public static final String SCA_DOMAIN_ATTRIBUTE = "org.apache.tuscany.sca.SCADomain";
+    public static final String SCA_NODE_ATTRIBUTE = Node.class.getName();
 
     private static final WebAppServletHost instance = new WebAppServletHost();
 
     private Map<String, Servlet> servlets;
-    private SCADomain scaDomain;
+    private Node node;
     private String contextPath = "/";
     private int defaultPortNumber = 8080;
     private String contributionRoot;
 
     private ServletContext servletContext;
 
-    private WebAppServletHost() {
+    WebAppServletHost() {
         servlets = new HashMap<String, Servlet>();
     }
 
@@ -211,14 +213,13 @@
     public void init(ServletConfig config) throws ServletException {
 
         servletContext = config.getServletContext();
-        if (servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE) == null) {
+        if (servletContext.getAttribute(SCA_NODE_ATTRIBUTE) == null) {
             initContextPath(config);
-            String domainURI = "http://localhost/" + contextPath;
             contributionRoot = getContributionRoot(servletContext);
-            // logger.info("Contribution: " + contributionRoot);
-            System.setProperty(SCADomain.class.getName(), WebSCADomain.class.getName());
-            this.scaDomain = SCADomain.newInstance(domainURI, contributionRoot);
-            servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
+            NodeFactory factory = NodeFactory.newInstance();
+            node = factory.createNode(null, new Contribution(contributionRoot, contributionRoot));
+            node.start();
+            servletContext.setAttribute(SCA_NODE_ATTRIBUTE, node);
         }
 
         // Initialize the registered Servlets
@@ -251,7 +252,7 @@
                 if (rootURL.getProtocol().equals("jndi")) {
                     //this is Tomcat case, we should use getRealPath
                     File warRootFile = new File(servletContext.getRealPath(root));
-                    contributionRoot = warRootFile.toURL().toString();
+                    contributionRoot = warRootFile.toURI().toString();
                 } else {
                     //this is Jetty case
                     contributionRoot = rootURL.toString();
@@ -299,11 +300,8 @@
         }
 
         // Close the SCA domain
-        if (scaDomain != null) {
-            scaDomain.close();
-            if (scaDomain instanceof WebSCADomain) {
-                ((WebSCADomain)scaDomain).destroy();
-            }
+        if (node != null) {
+            node.stop();
         }
     }
 

Modified: tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java?rev=713566&r1=713565&r2=713566&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
(original)
+++ tuscany/branches/sca-equinox/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
Wed Nov 12 15:45:10 2008
@@ -21,12 +21,9 @@
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.TagSupport;
 
-import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.apache.tuscany.sca.host.webapp.WebAppServletHost;
+import org.apache.tuscany.sca.node.Node;
 import org.osoa.sca.ComponentContext;
 
 /**
@@ -58,9 +55,9 @@
  
         ServletContext servletContext = pageContext.getServletContext();
         ComponentContext componentContext = (ComponentContext)servletContext.getAttribute("org.osoa.sca.ComponentContext");
-        SCADomain scaDomain = null;
+        Node scaDomain = null;
         if (componentContext == null) {
-            scaDomain = (SCADomain)servletContext.getAttribute(WebAppServletHost.SCA_DOMAIN_ATTRIBUTE);
+            scaDomain = (Node)servletContext.getAttribute(WebAppServletHost.SCA_NODE_ATTRIBUTE);
             if (scaDomain == null) {
                 throw new JspException("SCADomain is null. Check Tuscany configuration in
web.xml");
             }



Mime
View raw message