You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/03/17 08:48:16 UTC

svn commit: r637772 - in /incubator/tuscany/java/sca/modules/implementation-node-runtime: ./ src/main/java/org/apache/tuscany/sca/implementation/node/launcher/ src/main/java/org/apache/tuscany/sca/implementation/node/webapp/

Author: jsdelfino
Date: Mon Mar 17 00:48:14 2008
New Revision: 637772

URL: http://svn.apache.org/viewvc?rev=637772&view=rev
Log:
Bootstrapping SCANode2 from a webapp.

Added:
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java   (with props)
Modified:
    incubator/tuscany/java/sca/modules/implementation-node-runtime/pom.xml
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemon.java
    incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncher.java

Modified: incubator/tuscany/java/sca/modules/implementation-node-runtime/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/pom.xml?rev=637772&r1=637771&r2=637772&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/pom.xml Mon Mar 17 00:48:14 2008
@@ -62,6 +62,19 @@
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-host-http</artifactId>
+	        <version>1.2-incubating-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version> <!-- to keep compatible with older servlet containers --> 
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node2-impl</artifactId>
             <version>1.2-incubating-SNAPSHOT</version>
             <scope>runtime</scope>

Modified: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemon.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemon.java?rev=637772&r1=637771&r2=637772&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemon.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemon.java Mon Mar 17 00:48:14 2008
@@ -46,7 +46,7 @@
             
             // We use Java reflection here as only the runtime class
             // loader knows the runtime classes required by the daemon
-            daemonClass = runtimeClassLoader.loadClass("org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap"); 
+            daemonClass = Class.forName("org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap", true, runtimeClassLoader); 
             daemon = daemonClass.getConstructor().newInstance();
             
             // Start the daemon

Modified: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncher.java?rev=637772&r1=637771&r2=637772&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncher.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncher.java Mon Mar 17 00:48:14 2008
@@ -49,7 +49,7 @@
             
             // We use Java reflection here as only the runtime class
             // loader knows the runtime classes required by the node
-            nodeClass = runtimeClassLoader.loadClass("org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap"); 
+            nodeClass = Class.forName("org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap", true, runtimeClassLoader); 
             node = nodeClass.getConstructor(String.class).newInstance(configurationURI);
             
             // Start the node

Added: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java?rev=637772&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java Mon Mar 17 00:48:14 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.node.launcher;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A servlet filter that forwards service requests to the servlets registered with
+ * the Tuscany ServletHost.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeServletFilter implements Filter {
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger logger = Logger.getLogger(NodeServletFilter.class.getName());
+
+    private ClassLoader runtimeClassLoader;
+    private Class<?> servletHostClass;
+    private Object servletHost;
+    private Filter filter;
+
+    public void init(final FilterConfig config) throws ServletException {
+        logger.info("Apache Tuscany SCA WebApp Node starting...");
+
+        try {
+            // Get the Tuscany runtime classloader
+            runtimeClassLoader = NodeLauncherUtil.runtimeClassLoader();
+    
+            // Load the Tuscany WebApp servlet host and get the host instance
+            // for the current webapp
+            servletHostClass = Class.forName("org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost", true, runtimeClassLoader);
+            servletHost = servletHostClass.getMethod("servletHost").invoke(null);
+    
+            // Initialize the servlet host
+            servletHostClass.getMethod("init", FilterConfig.class).invoke(config);
+
+            // The servlet host also implements the filter interface 
+            filter = (Filter)servletHost;
+            
+        } catch (Exception e) {
+            logger.log(Level.SEVERE, "Error Starting SCA WebApp Node", e);
+            throw new ServletException(e);
+        }
+
+        logger.info("SCA WebApp Node started.");
+    }
+
+    public void destroy() {
+        logger.info("Apache Tuscany WebApp Node stopping...");
+        if (servletHost != null) {
+            try {
+                servletHostClass.getMethod("destroy").invoke(servletHost);
+            } catch (Exception e) {
+                logger.log(Level.SEVERE, "Error Stopping SCA WebApp Node", e);
+            }
+        }
+        logger.info("SCA WebApp Node stopped.");
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
+        throws IOException, ServletException {
+
+        // Delegate to the servlet host filter
+        filter.doFilter(request, response, chain);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java?rev=637772&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java Mon Mar 17 00:48:14 2008
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.node.webapp;
+
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * A servlet request dispatcher that can be used to delegate requests to a
+ * serlvet registered with the Webapp servlet host.
+ * 
+ * @version $Rev$ $Date$
+ */
+class NodeWebAppRequestDispatcher implements RequestDispatcher {
+    private String servletPath;
+    private Servlet servlet;
+    
+    /**
+     * Constructs a new request dispatcher.
+     * 
+     * @param mapping
+     * @param servlet
+     */
+    public NodeWebAppRequestDispatcher(String mapping, Servlet servlet) {
+        if (mapping.endsWith("*")) {
+            mapping = mapping.substring(0, mapping.length()-1);
+        }
+        if (mapping.endsWith("/")) {
+            mapping = mapping.substring(0, mapping.length()-1);
+        }
+        this.servletPath = mapping;
+        this.servlet = servlet;
+    }
+
+    /**
+     * Returns a request wrapper which will return the correct servlet path
+     * and path info.
+     * 
+     * @param request
+     * @return
+     */
+    private HttpServletRequest createRequestWrapper(ServletRequest request) {
+        HttpServletRequest requestWrapper = new HttpServletRequestWrapper((HttpServletRequest)request) {
+            
+            @Override
+            public String getServletPath() {
+                return servletPath;
+            }
+            
+            @Override
+            public String getPathInfo() {
+                String path = super.getServletPath();
+                if (path.length() == 0) {
+                    path = super.getPathInfo();
+                }
+
+                // TODO: another context path hack, revisit when context path is sorted out
+                path = fiddlePath(path, servletPath);
+
+                return path;
+            }
+        };
+        return requestWrapper;
+    }
+
+    /**
+     * Remove any path suffix thats part of the servlet context path.
+     * 
+     * @param path
+     * @param servletPath
+     */
+    private static String fiddlePath(String path, String servletPath) {
+        StringTokenizer st = new StringTokenizer(path, "/");
+        String root = "";
+        while (st.hasMoreTokens()){
+                String s = st.nextToken();
+                if (servletPath.endsWith((root + "/" + s))) {
+                        root += "/" + s;
+                } else {
+                        break;
+                }
+        }
+        String fiddlePath = path.substring(root.length());
+        return fiddlePath;
+    }
+
+    public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+        servlet.service(createRequestWrapper(request), response);
+    }
+    
+    public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+        servlet.service(createRequestWrapper(request), response);
+    }
+}
+

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java?rev=637772&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java Mon Mar 17 00:48:14 2008
@@ -0,0 +1,371 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.node.webapp;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.FilterConfig;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+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.NodeException;
+import org.apache.tuscany.sca.node.SCANode2;
+import org.apache.tuscany.sca.node.SCANode2Factory;
+
+/**
+ * ServletHost implementation for use in a Webapp Node environment.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeWebAppServletHost implements ServletHost {
+    private static final Logger logger = Logger.getLogger(NodeWebAppServletHost.class.getName());
+
+    public static final String SCA_NODE_ATTRIBUTE = "org.apache.tuscany.sca.SCANode";
+
+    private static final NodeWebAppServletHost servletHost = new NodeWebAppServletHost();
+
+    private Map<String, Servlet> servlets = new HashMap<String, Servlet>();
+    private SCANode2 node;
+    
+    private String contextPath = "/";
+    private int defaultPort = 8080;
+    private String contributionRoot;
+
+    /**
+     * Constructs a new NodeWebAppServletHost.
+     */
+    private NodeWebAppServletHost() {
+    }
+
+    /**
+     * Returns the servlet host for the current Web app.
+     * 
+     * @return
+     */
+    static public NodeWebAppServletHost servletHost() {
+        return servletHost;
+    }
+
+    /**
+     * Initialize the servlet host.
+     * 
+     * @param filterConfig
+     * @throws ServletException
+     */
+    public void init(final FilterConfig filterConfig) throws ServletException {
+        
+        // Create a servlet config wrappering the given filter config
+        ServletConfig servletConfig = new ServletConfig() {
+            public String getInitParameter(String name) {
+                return filterConfig.getInitParameter(name);
+            }
+
+            public Enumeration getInitParameterNames() {
+                return filterConfig.getInitParameterNames();
+            }
+
+            public ServletContext getServletContext() {
+                return filterConfig.getServletContext();
+            }
+
+            public String getServletName() {
+                return filterConfig.getFilterName();
+            }
+        };
+
+        // Get the servlet context
+        ServletContext servletContext = servletConfig.getServletContext();
+
+        // Initialize the context path
+        initContextPath(servletContext);
+
+        // Derive the node name and node image from the Webapp
+        // context path
+        String nodeName = contextPath;
+        if (nodeName.startsWith("/")) {
+            nodeName = nodeName.substring(1); 
+        }
+        if (nodeName.endsWith("/")) {
+            nodeName = nodeName.substring(0, nodeName.length() - 1); 
+        }
+        String nodeImage = "http://localhost:9990/node-image/" + nodeName;
+        
+        // Create the SCA node
+        SCANode2Factory nodeFactory = SCANode2Factory.newInstance();
+        try {
+            node = nodeFactory.createSCANode(nodeImage);
+        } catch (NodeException e) {
+            throw new ServletException(e);
+        }
+
+        // Save the node in the servlet context 
+        servletContext.setAttribute(SCA_NODE_ATTRIBUTE, node);
+        
+        // Start the node
+        try {
+            node.start();
+        } catch (NodeException e) {
+            throw new ServletException(e);
+        }
+
+        // Initialize the registered servlets
+        for (Servlet servlet : servlets.values()) {
+            servlet.init(servletConfig);
+        }
+    }
+
+    public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException {
+        URI pathURI = URI.create(suri);
+
+        // Make sure that the path starts with a /
+        suri = pathURI.getPath();
+        if (!suri.startsWith("/")) {
+            suri = '/' + suri;
+        }
+
+        if (!suri.startsWith(contextPath)) {
+            suri = contextPath + suri;
+        }
+
+        // In a webapp just use the given path and ignore the host and port
+        // as they are fixed by the Web container
+        servlets.put(suri, servlet);
+
+        logger.info("Added Servlet mapping: " + suri);
+    }
+
+    public Servlet removeServletMapping(String suri) throws ServletMappingException {
+        URI pathURI = URI.create(suri);
+
+        // Make sure that the path starts with a /
+        suri = pathURI.getPath();
+        if (!suri.startsWith("/")) {
+            suri = '/' + suri;
+        }
+
+        if (!suri.startsWith(contextPath)) {
+            suri = contextPath + suri;
+        }
+
+        // In a webapp just use the given path and ignore the host and port
+        // as they are fixed by the Web container
+        return servlets.remove(suri);
+    }
+
+    public Servlet getServletMapping(String suri) throws ServletMappingException {
+        if (!suri.startsWith("/")) {
+            suri = '/' + suri;
+        }
+
+        if (!suri.startsWith(contextPath)) {
+            suri = contextPath + suri;
+        }
+
+        // Get the servlet mapped to the given path
+        Servlet servlet = servlets.get(suri);
+        return servlet;
+    }
+
+    public URL getURLMapping(String suri) throws ServletMappingException {
+        URI uri = URI.create(suri);
+
+        // Get the URI scheme and port
+        String scheme = uri.getScheme();
+        if (scheme == null) {
+            scheme = "http";
+        }
+        int portNumber = uri.getPort();
+        if (portNumber == -1) {
+            portNumber = defaultPort;
+        }
+
+        // Get the host
+        String host;
+        try {
+            host = InetAddress.getLocalHost().getHostName();
+        } catch (UnknownHostException e) {
+            host = "localhost";
+        }
+
+        // Construct the URL
+        String path = uri.getPath();
+        if (!path.startsWith("/")) {
+            path = '/' + path;
+        }
+
+        if (contextPath != null && !path.startsWith(contextPath)) {
+            path = contextPath + path;
+        }
+
+        URL url;
+        try {
+            url = new URL(scheme, host, portNumber, path);
+        } catch (MalformedURLException e) {
+            throw new ServletMappingException(e);
+        }
+        return url;
+    }
+
+    public RequestDispatcher getRequestDispatcher(String suri) throws ServletMappingException {
+
+        // Make sure that the path starts with a /
+        if (!suri.startsWith("/")) {
+            suri = '/' + suri;
+        }
+
+        suri = contextPath + suri;
+
+        // Get the servlet mapped to the given path
+        Servlet servlet = servlets.get(suri);
+        if (servlet != null) {
+            return new NodeWebAppRequestDispatcher(suri, servlet);
+        }
+
+        for (Map.Entry<String, Servlet> entry : servlets.entrySet()) {
+            String servletPath = entry.getKey();
+            if (servletPath.endsWith("*")) {
+                servletPath = servletPath.substring(0, servletPath.length() - 1);
+                if (suri.startsWith(servletPath)) {
+                    return new NodeWebAppRequestDispatcher(entry.getKey(), entry.getValue());
+                } else {
+                    if ((suri + "/").startsWith(servletPath)) {
+                        return new NodeWebAppRequestDispatcher(entry.getKey(), entry.getValue());
+                    }
+                }
+            }
+        }
+
+        // No servlet found
+        return null;
+    }
+
+    /**
+     * Destroy the servlet host.
+     * 
+     * @throws ServletException
+     */
+    public void destroy() throws ServletException {
+
+        // Destroy the registered servlets
+        for (Servlet servlet : servlets.values()) {
+            servlet.destroy();
+        }
+
+        // Close the SCA domain
+        if (node != null) {
+            try {
+                node.stop();
+            } catch (NodeException e) {
+                throw new ServletException(e);
+            }
+        }
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
+        throws IOException, ServletException {
+
+        // Get the servlet path
+        HttpServletRequest httpRequest = (HttpServletRequest)request;
+        String path = httpRequest.getPathInfo();
+        if (path == null) {
+            path = httpRequest.getServletPath();
+        }
+        if (path == null) {
+            path = "/";
+        }
+
+        // Get a request dispatcher for the servlet mapped to that path
+        RequestDispatcher dispatcher = getRequestDispatcher(path);
+        if (dispatcher != null) {
+
+            // Let the dispatcher forward the request to the servlet
+            dispatcher.forward(request, response);
+
+        } else {
+
+            // Proceed down the filter chain
+            chain.doFilter(request, response);
+        }
+    }
+
+    public void setDefaultPort(int port) {
+        defaultPort = port;
+    }
+
+    public int getDefaultPort() {
+        return defaultPort;
+    }
+
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    public void setContextPath(String path) {
+        //this.contextPath = path;
+    }
+
+    /**
+     * Initializes the contextPath
+     * The 2.5 Servlet API has a getter for this, for pre 2.5 servlet
+     * containers use an init parameter.
+     */
+    private void initContextPath(ServletContext context) {
+
+        // The getContextPath() is introduced since Servlet 2.5
+        Method m;
+        try {
+            // Try to get the method anyway since some ServletContext impl has this method even before 2.5
+            m = context.getClass().getMethod("getContextPath", new Class[] {});
+            contextPath = (String)m.invoke(context, new Object[] {});
+        } catch (Exception e) {
+            contextPath = context.getInitParameter("contextPath");
+            if (contextPath == null) {
+                logger.warning("Servlet level is: " + context.getMajorVersion() + "." + context.getMinorVersion());
+                throw new IllegalStateException(
+                                                "'contextPath' init parameter must be set for pre-2.5 servlet container");
+            }
+        }
+
+        logger.info("ContextPath: " + contextPath);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org