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/18 02:52:19 UTC
svn commit: r638174 - in /incubator/tuscany/java/sca/modules/node2-launcher:
pom.xml
src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
Author: jsdelfino
Date: Mon Mar 17 18:52:16 2008
New Revision: 638174
URL: http://svn.apache.org/viewvc?rev=638174&view=rev
Log:
Moved NodeServletFilter here from module node2-launcher-webapp.
Added:
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
Modified:
incubator/tuscany/java/sca/modules/node2-launcher/pom.xml
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
Modified: incubator/tuscany/java/sca/modules/node2-launcher/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-launcher/pom.xml?rev=638174&r1=638173&r2=638174&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/node2-launcher/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/node2-launcher/pom.xml Mon Mar 17 18:52:16 2008
@@ -35,6 +35,14 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca-api</artifactId>
<version>1.2-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </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>
</dependencies>
Modified: incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java?rev=638174&r1=638173&r2=638174&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java (original)
+++ incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java Mon Mar 17 18:52:16 2008
@@ -143,7 +143,8 @@
}
// Filter out the Jetty and Webapp hosts
- if (name.startsWith("tuscany-host-jetty") || name.startsWith("tuscany-host-webapp")) {
+ if (name.startsWith("tuscany-host-jetty") ||
+ name.startsWith("tuscany-host-webapp")) {
//FIXME This is temporary
return false;
}
Added: incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java?rev=638174&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java (added)
+++ incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java Mon Mar 17 18:52:16 2008
@@ -0,0 +1,126 @@
+/*
+ * 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.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(FilterConfig filterConfig) throws ServletException {
+ logger.info("Apache Tuscany SCA WebApp Node starting...");
+
+ try {
+ // Get the Tuscany runtime classloader
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ runtimeClassLoader = NodeLauncherUtil.runtimeClassLoader(getClass().getClassLoader());
+
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Load the Tuscany WebApp servlet host and get the host instance
+ // for the current webapp
+ String className = "org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost";
+ if (runtimeClassLoader != null) {
+ servletHostClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ servletHostClass = Class.forName(className);
+ }
+ servletHost = servletHostClass.getMethod("servletHost").invoke(null);
+
+ // Initialize the servlet host
+ servletHostClass.getMethod("init", FilterConfig.class).invoke(servletHost, filterConfig);
+
+ // The servlet host also implements the filter interface
+ filter = (Filter)servletHost;
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+
+ } 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) {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ servletHostClass.getMethod("destroy").invoke(servletHost);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error Stopping SCA WebApp Node", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+ 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
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ filter.doFilter(request, response, chain);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org