summaryrefslogtreecommitdiffstats
path: root/tags/java-stable-20060304/sca/tomcat/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-stable-20060304/sca/tomcat/src/main/java/org')
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/ContainerLoader.java100
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java144
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java162
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java118
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java41
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java113
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatServerLifecycleListener.java40
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatWebAppLifecycleListener.java249
-rw-r--r--tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java152
9 files changed, 0 insertions, 1119 deletions
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/ContainerLoader.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/ContainerLoader.java
deleted file mode 100644
index 60c9a7961f..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/ContainerLoader.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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.tomcat;
-
-import java.beans.PropertyChangeListener;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Loader;
-
-/**
- * Implementation of a TomcatLoader that allows privileged servlets from the container
- * classloader to be loaded into an unprivileged application. This allows the Tuscany
- * integration code to add servlets to the application, for example, to handle web
- * services requests.
- *
- * @version $Rev$ $Date$
- */
-public class ContainerLoader implements Loader {
- private static final String INFO = ContainerLoader.class.getName() + "/SNAPSHOT";
- private final ClassLoader cl;
- private Container container;
-
- /**
- * Constructor specifying the classloader to be used.
- *
- * @param cl the classloader this Loader wraps, typically the container classloader
- */
- public ContainerLoader(ClassLoader cl) {
- this.cl = cl;
- }
-
- public void backgroundProcess() {
- }
-
- public ClassLoader getClassLoader() {
- return cl;
- }
-
- public Container getContainer() {
- return container;
- }
-
- public void setContainer(Container container) {
- this.container = container;
- }
-
- public boolean getDelegate() {
- return false;
- }
-
- public void setDelegate(boolean delegate) {
- throw new UnsupportedOperationException();
- }
-
- public String getInfo() {
- return INFO;
- }
-
- public boolean getReloadable() {
- return false;
- }
-
- public void setReloadable(boolean reloadable) {
- throw new UnsupportedOperationException();
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public void addRepository(String repository) {
- throw new UnsupportedOperationException();
- }
-
- public String[] findRepositories() {
- throw new UnsupportedOperationException();
- }
-
- public boolean modified() {
- throw new UnsupportedOperationException();
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
deleted file mode 100644
index 04977dbc27..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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.tomcat;
-
-import java.io.IOException;
-
-import javax.servlet.ServletContext;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.Valve;
-import org.apache.catalina.core.StandardWrapper;
-
-import org.apache.tuscany.binding.axis2.handler.WebServiceEntryPointServlet;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
-import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyModelContext;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
-import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader;
-
-/**
- * @version $Rev$ $Date$
- */
-public class TuscanyContextListener implements LifecycleListener {
- private static final String TUSCANY_RUNTIME_NAME = RuntimeContext.class.getName();
- public static final String MODULE_COMPONENT_NAME = "org.apache.tuscany.core.webapp.ModuleComponentContext";
-
- private final AssemblyFactory modelFactory;
- private final AssemblyModelLoader modelLoader;
- private final RuntimeContext runtime;
- private final ResourceLoader systemLoader;
- private AggregateContext moduleContext;
-
- public TuscanyContextListener(RuntimeContext runtimeContext, AssemblyFactory modelFactory, AssemblyModelLoader modelLoader, ResourceLoader systemLoader) {
- this.runtime = runtimeContext;
- this.modelFactory = modelFactory;
- this.modelLoader = modelLoader;
- this.systemLoader = systemLoader;
- }
-
- public void lifecycleEvent(LifecycleEvent event) {
- String type = event.getType();
- if (Lifecycle.START_EVENT.equals(type)) {
- startContext((Context) event.getLifecycle());
- } else if (Lifecycle.STOP_EVENT.equals(type)) {
- stopContext((Context) event.getLifecycle());
- }
- }
-
- private void startContext(Context ctx) {
- ResourceLoader resourceLoader = new ResourceLoaderImpl(ctx.getLoader().getClassLoader());
- try {
- if (resourceLoader.getResource("sca.module") == null) {
- return;
- }
- } catch (IOException e) {
- return;
- }
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- try {
- AssemblyModelContext modelContext = new AssemblyModelContextImpl(modelFactory, modelLoader, systemLoader, resourceLoader);
- ModuleComponentConfigurationLoader loader = new ModuleComponentConfigurationLoaderImpl(modelContext);
-
- try {
- // Load the SCDL configuration of the application module
- ModuleComponent moduleComponent = loader.loadModuleComponent(ctx.getName(), ctx.getPath());
-
- // Register it under the root application context
- AggregateContext rootContext = runtime.getRootContext();
- rootContext.registerModelObject(moduleComponent);
- moduleContext = (AggregateContext)rootContext.getContext(moduleComponent.getName());
- moduleContext.registerModelObject(moduleComponent.getComponentImplementation());
- } catch (ConfigurationLoadException e) {
- throw new UnsupportedOperationException();
- } catch (ConfigurationException e) {
- throw new UnsupportedOperationException();
- }
- } finally {
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- moduleContext.fireEvent(EventContext.MODULE_START, null);
-
- // add a valve to this context's pipeline that will associate the request with the runtime
- Valve valve = new TuscanyValve(moduleContext);
- ctx.getPipeline().addValve(valve);
-
- // add the web service servlet wrapper
- addWebServiceWrapper(ctx);
-
- // add the RuntimeContext in as a servlet context parameter
- ServletContext servletContext = ctx.getServletContext();
- servletContext.setAttribute(TUSCANY_RUNTIME_NAME, runtime);
- servletContext.setAttribute(MODULE_COMPONENT_NAME, moduleContext);
- }
-
- private void stopContext(Context ctx) {
- if (moduleContext!=null) {
- moduleContext.fireEvent(EventContext.MODULE_START, null);
- }
- // todo unload module component from runtime
- }
-
- private static void addWebServiceWrapper(Context ctx) {
- // todo this should not depend on axis2, we need an API in the model for embedders
- // todo should only add this servlet if we need it
- // todo servlet implementation should be determined by the binding implementation
- // todo should get path from entry point definition and not hard code to /services
-
- Class<WebServiceEntryPointServlet> servletClass = WebServiceEntryPointServlet.class;
- StandardWrapper wrapper = new StandardWrapper();
- wrapper.setName("TuscanyAxis2EntryPointServlet");
- wrapper.setLoader(new ContainerLoader(servletClass.getClassLoader()));
- wrapper.setServletClass(servletClass.getName());
- ctx.addChild(wrapper);
- ctx.addServletMapping("/services/*", wrapper.getName());
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
deleted file mode 100644
index b6e6db6da7..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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.tomcat;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.core.StandardContext;
-import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.util.StringManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
-import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.SystemAggregateContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
-import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
-import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
-import org.apache.tuscany.core.system.loader.SystemSCDLModelLoader;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyModelContext;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
-import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader;
-import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
-import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl;
-
-/**
- * A Tomcat listener to be attached to a Host container to add SCA runtime functionality.
- * The listener wraps a Tuscany runtime and listens for container events to detect the
- * addition and removal of Context children.
- *
- * @version $Rev$ $Date$
- */
-public class TuscanyHost extends StandardHost {
- private static final String SYSTEM_MODULE_COMPONENT = "org.apache.tuscany.core.system";
- private static final Log log = LogFactory.getLog(TuscanyHost.class);
- private static final StringManager sm = StringManager.getManager("org.apache.tuscany.tomcat");
-
- private RuntimeContext runtime;
- private AssemblyModelLoader modelLoader;
- private AssemblyFactory modelFactory;
- private ResourceLoader systemLoader;
-
- public synchronized void start() throws LifecycleException {
- startRuntime();
- super.start();
- }
-
- public synchronized void stop() throws LifecycleException {
- super.stop();
- stopRuntime();
- }
-
- private void startRuntime() {
- systemLoader = new ResourceLoaderImpl(getClass().getClassLoader());
-
- // Create an assembly model factory
- modelFactory = new AssemblyFactoryImpl();
-
- // Create an assembly model loader
- List<SCDLModelLoader> scdlLoaders=new ArrayList<SCDLModelLoader>();
- scdlLoaders.add(new SystemSCDLModelLoader());
- modelLoader = new SCDLAssemblyModelLoaderImpl(scdlLoaders);
-
- // Create an assembly model context
- AssemblyModelContext modelContext = new AssemblyModelContextImpl(modelFactory, modelLoader, systemLoader);
-
- // Load the system module component
- ModuleComponentConfigurationLoader loader = new ModuleComponentConfigurationLoaderImpl(modelContext);
- ModuleComponent systemModuleComponent;
- try {
- systemModuleComponent = loader.loadSystemModuleComponent(SYSTEM_MODULE_COMPONENT, SYSTEM_MODULE_COMPONENT);
- } catch (ConfigurationLoadException e) {
- log.warn(sm.getString("runtime.loadSystemFailed"), e);
- return;
- }
-
- List<RuntimeConfigurationBuilder> configBuilders = new ArrayList();
- configBuilders.add((new SystemComponentContextBuilder()));
- configBuilders.add(new SystemEntryPointBuilder());
- configBuilders.add(new SystemExternalServiceBuilder());
-
- runtime = new RuntimeContextImpl(new NullMonitorFactory(), scdlLoaders, configBuilders, new DefaultWireBuilder());
- runtime.start();
-
- try {
- SystemAggregateContext systemContext = runtime.getSystemContext();
- systemContext.registerModelObject(systemModuleComponent);
-
- // Get the aggregate context representing the system module component
- AggregateContext systemModuleComponentContext = (AggregateContext) systemContext.getContext(SYSTEM_MODULE_COMPONENT);
- systemModuleComponentContext.registerModelObject(systemModuleComponent.getComponentImplementation());
- systemModuleComponentContext.fireEvent(EventContext.MODULE_START, null);
- } catch (Exception e) {
- log.warn(sm.getString("runtime.registerSystemFailed"), e);
- runtime.stop();
- runtime = null;
- return;
- }
-
- log.info(sm.getString("runtime.started"));
- }
-
- private void stopRuntime() {
- if (runtime == null) {
- return;
- }
-
- runtime.stop();
- runtime = null;
- log.info(sm.getString("runtime.stopped"));
- }
-
- public synchronized void addChild(Container child) {
- if (!(child instanceof StandardContext)) {
- throw new IllegalArgumentException(sm.getString("tuscanyHost.notContext"));
- }
- StandardContext ctx = (StandardContext) child;
- ctx.addLifecycleListener(new TuscanyContextListener(runtime, modelFactory, modelLoader, systemLoader));
- super.addChild(child);
- }
-
- public String toString() {
-
- StringBuffer sb = new StringBuffer(132);
- if (getParent() != null) {
- sb.append(getParent().toString()).append('.');
- }
- sb.append("TuscanyHost[").append(getName()).append(']');
- return (sb.toString());
-
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java
deleted file mode 100644
index d5383b64ea..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyValve.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed 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.tomcat;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.catalina.connector.Request;
-import org.apache.catalina.connector.Response;
-import org.apache.catalina.valves.ValveBase;
-import org.osoa.sca.CurrentModuleContext;
-import org.osoa.sca.ModuleContext;
-import org.osoa.sca.SCA;
-
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.EventException;
-import org.apache.tuscany.core.context.webapp.LazyHTTPSessionId;
-
-/**
- * Valve that can be added to a pipeline to automatically set the SCA environment as each request is processed.
- *
- * @version $Rev$ $Date$
- */
-public class TuscanyValve extends ValveBase {
- /**
- * Name of the note that contains the request id
- */
- private static final String REQUEST_ID = "org.apache.tuscany.tomcat.REQUEST_ID";
-
- private static final ContextBinder BINDER = new ContextBinder();
-
- private final AggregateContext moduleComponentContext;
-
- public TuscanyValve(AggregateContext moduleComponentContext) {
- this.moduleComponentContext = moduleComponentContext;
- }
-
- public void invoke(Request request, Response response) throws IOException, ServletException {
- Object oldRequestId = request.getNote(REQUEST_ID);
- ModuleContext oldContext = CurrentModuleContext.getContext();
-
- // bind the current module context to the thread for use by CurrentModuleContext
- BINDER.setContext((ModuleContext) moduleComponentContext);
- try {
- if (oldRequestId != null) {
- // the request has already been started, just invoke the next valve
- next.invoke(request, response);
- } else {
- // tell the runtime a new request is starting
- Object requestId = new Object();
- // jfm
- if (request.getSession(false) != null) {
- // A session is already active
- moduleComponentContext
- .fireEvent(EventContext.SESSION_NOTIFY, ((HttpServletRequest) request).getSession(true));
- } else {
- // Create a lazy wrapper since a session is not yet active
- moduleComponentContext.fireEvent(EventContext.SESSION_NOTIFY, new LazyHTTPSessionId(
- (HttpServletRequest) request));
- }
- // jfm
- try {
- moduleComponentContext.fireEvent(EventContext.REQUEST_START, requestId);
- } catch (Exception e) {
- throw new ServletException(e.getMessage(), e);
- }
- request.setNote(REQUEST_ID, requestId);
-
- try {
- // invoke the next valve in the pipeline
- next.invoke(request, response);
- } finally {
- // notify the runtime the request is ending
- request.removeNote(REQUEST_ID);
- try {
- moduleComponentContext.fireEvent(EventContext.REQUEST_END, requestId);
- } catch (Exception e) {
- // the application already did its work, log and ignore
- // todo log this exception
- }
- }
- }
- } finally {
- // restore the previous module context onto the thread
- BINDER.setContext(oldContext);
- }
- }
-
- private static class ContextBinder extends SCA {
- public void setContext(ModuleContext context) {
- setModuleContext(context);
- }
-
- public void start() {
- throw new AssertionError();
- }
-
- public void stop() {
- throw new AssertionError();
- }
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
deleted file mode 100644
index 39f24cba8f..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.tomcat.lifecycle.listener;
-
-import org.apache.tuscany.common.TuscanyException;
-
-/**
- * Signals an exception booting the Tuscany runtime hosted in a Tomcat instance
- *
- * @version $Rev$ $Date$
- */
-public class BootstrapConfigurationException extends TuscanyException {
-
- public BootstrapConfigurationException() {
- super();
- }
-
- public BootstrapConfigurationException(String message) {
- super(message);
- }
-
- public BootstrapConfigurationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public BootstrapConfigurationException(Throwable cause) {
- super(cause);
- }
-
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
deleted file mode 100644
index 16cad1cb1b..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.tomcat.lifecycle.listener;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.spi.ObjectFactory;
-
-import org.apache.tuscany.common.monitor.MonitorFactory;
-import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.config.JavaIntrospectionHelper;
-import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
-import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
-import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-
-/**
- * Bootstraps an SCA runtime hosted by a Tomcat instance. The runtime will be bound to JNDI and accessed by
- * {@link org.apache.tuscany.tomcat.lifecycle.listener.WebAppLifecycleListener}s that deploy web archives as module
- * components.
- * <p>
- * Tomcat is configured by adding the following to <code>server.xml</code> under the
- * <code>GlobalNamingResources</code> element:
- *
- * <pre>
- * &lt;Resource name=&quot;TuscanyRuntime&quot; auth=&quot;Container&quot; type=&quot;org.apache.tuscany.core.runtime.RuntimeContext&quot;
- * description=&quot;Tuscany Runtime&quot;
- * factory=&quot; org.apache.tuscany.tomcat.lifecycle.listener.RuntimeBootstrap&quot;
- * monitor=&quot;[monitor factory]&quot; loader=&quot;[configuration loader]&quot;/&gt;
- * </pre>
- *
- * @version $Rev$ $Date$
- */
-public class RuntimeBootstrap implements ObjectFactory {
-
- public static final String RUNTIME_NAME = "TuscanyRuntime";
-
- public RuntimeBootstrap() {
- }
-
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
- throws BootstrapConfigurationException {
- if (!RUNTIME_NAME.equals(name)) {
- throw new BootstrapConfigurationException("Tuscany Runtime must be configured with JNDI address of " + RUNTIME_NAME);
- }
- MonitorFactory monitorFactory = null;
- ModuleComponentConfigurationLoader configurationLoader = null;
-
- Reference ref = (Reference) obj;
- if (!RuntimeContext.class.getName().equals(ref.getClassName())) {
- throw new BootstrapConfigurationException("Invalid runtime configuration");
- }
- RefAddr monitorAddr = ref.get("monitor");
- RefAddr loaderAddr = ref.get("loader");
- if (loaderAddr == null) {
- throw new BootstrapConfigurationException("No configuration laoder specified in Tomcat configuration");
- }
- if (monitorAddr != null) {
- try {
- Class monitorFactoryClass = JavaIntrospectionHelper.loadClass(monitorAddr.getContent().toString());
- monitorFactory = (MonitorFactory) monitorFactoryClass.newInstance();
- } catch (ClassNotFoundException e) {
- throw new BootstrapConfigurationException("Unable to find monitor factory class specified in Tomcat configuration", e);
- } catch (InstantiationException e) {
- throw new BootstrapConfigurationException("Error initializing monitor factory in Tomcat configuration", e);
- } catch (IllegalAccessException e) {
- throw new BootstrapConfigurationException("Error initializing monitor factory in Tomcat configuration", e);
- }
- }
-// try {
-// Class configurationLoaderClass = JavaIntrospectionHelper.loadClass(loaderAddr.getContent().toString());
-// configurationLoader = (ConfigurationLoader) configurationLoaderClass.newInstance();
-// } catch (ClassNotFoundException e) {
-// throw new BootstrapConfigurationException("Unable to find configuration loader class specified in Tomcat configuration", e);
-// } catch (InstantiationException e) {
-// throw new BootstrapConfigurationException("Error initializing configuration loader in Tomcat configuration", e);
-// } catch (IllegalAccessException e) {
-// throw new BootstrapConfigurationException("Error initializing configuration loader in Tomcat configuration", e);
-// }
- // create the SCA Runtime and have it bound in the global JNDI context
- return new RuntimeContextImpl(monitorFactory, null, createBuilders(),null);
- }
-
- /**
- * Creates a collection of bootstrap builders
- */
- private List<RuntimeConfigurationBuilder> createBuilders() {
- List<RuntimeConfigurationBuilder> builders = new ArrayList();
- builders.add((new SystemComponentContextBuilder()));
- builders.add(new SystemEntryPointBuilder());
- builders.add(new SystemExternalServiceBuilder());
- return builders;
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatServerLifecycleListener.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatServerLifecycleListener.java
deleted file mode 100644
index 0da95bde17..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatServerLifecycleListener.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.tomcat.lifecycle.listener;
-
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-
-/**
- * This class manages the lifecycle of the SCA container in Tomcat.
- * @deprecated
- */
-public class TomcatServerLifecycleListener implements LifecycleListener {
- //private CoreModuleContext containerModuleContext;
-
- /**
- * Constructor
- */
- public TomcatServerLifecycleListener() {
- }
-
- /**
- * @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
- */
- public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
- }
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatWebAppLifecycleListener.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatWebAppLifecycleListener.java
deleted file mode 100644
index d1e7d8de39..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatWebAppLifecycleListener.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.tomcat.lifecycle.listener;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.deploy.FilterDef;
-import org.apache.catalina.deploy.FilterMap;
-import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
-import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.CoreRuntimeException;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.webapp.HTTPSessionExpirationListener;
-import org.apache.tuscany.core.context.webapp.TuscanyRequestFilter;
-import org.apache.tuscany.core.context.webapp.TuscanyWebAppRuntime;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
-import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
-import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
-import org.apache.tuscany.core.system.loader.SystemSCDLModelLoader;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyModelContext;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
-import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader;
-import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
-import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl;
-import org.osoa.sca.ServiceRuntimeException;
-
-//FIXME This is a temporary hack to bootstrap the runtime in a Tomcat environment and do some bringup testing, the real bootstrap code is
-// still under construction
-
-/**
- * Responsible for initializing web applications as module components in a
- * Tomcat instance. When a web app is being loaded in Tomcat, this listener
- * receives a callback to register a corresponding module component and set up
- * the appropriate Servlet filters in the web context.
- * <p/>
- * Note that Tomcat loads this class in the standard (common/lib) classloader
- * even though the context classloader is that of the web app being loaded.
- * Consequently, the transitive closure of class references must not include
- * <tt>ModuleContext</tt> or <tt>ModuleManager</tt>
- * <p/>
- * TODO decide if we want to set this up as a Tomcat listener or as a web app
- * listener Setting this up as a web app listener allows users to set the
- * context path, avoiding a performance hit for SCA event processing in contexts
- * where it is not used. The downside is the potential for user error. For
- * example, SCA event filters must be manually configured. We probably should
- * provide both options
- * FIXME fix the exception handling
- */
-public class TomcatWebAppLifecycleListener implements LifecycleListener {
-
- private final static String SYSTEM_MODULE_COMPONENT = "org.apache.tuscany.core.system";
-
- /**
- * Constructor
- */
- public TomcatWebAppLifecycleListener() {
- }
-
- /**
- * Callback for receiving web application events. When a web app containing
- * an SCA configuration is initialized, a module component is created and
- * appropriate SCA filters are set for in the web context. If a web app stop
- * event is received, the corresponding module component is deregistered from
- * the system.
- */
- public void lifecycleEvent(LifecycleEvent event) {
- String lifecycleEventType = event.getType();
- Object lifecycleEventSource = event.getSource();
-
- if (Lifecycle.START_EVENT.equals(lifecycleEventType) && lifecycleEventSource instanceof Context) {
-
- // The web app is starting
- Context context = (Context) lifecycleEventSource;
- try {
-
- // Get the application classloader
- ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader();
- ResourceLoader resourceLoader = new ResourceLoaderImpl(applicationClassLoader);
-
- // Check if the web app contains an sca.module file
- URL url;
- try {
- url = resourceLoader.getResource("sca.module");
- } catch (IOException e) {
- url = null;
- }
- if (url != null) {
- // The Web app has an sca.module file
- // Get the module component name from the context
- String moduleComponentName = context.getPath().substring(1);
- try {
-
- // Create an assembly model factory
- AssemblyFactory modelFactory=new AssemblyFactoryImpl();
-
- // Create an assembly model loader
- List<SCDLModelLoader> scdlLoaders=new ArrayList<SCDLModelLoader>();
- scdlLoaders.add(new SystemSCDLModelLoader());
- AssemblyModelLoader modelLoader=new SCDLAssemblyModelLoaderImpl(scdlLoaders);
-
- // Create an assembly model context
- AssemblyModelContext modelContext = new AssemblyModelContextImpl(modelFactory, modelLoader, resourceLoader);
-
- // Create system configuration builders
- List<RuntimeConfigurationBuilder> configBuilders = new ArrayList();
- configBuilders.add((new SystemComponentContextBuilder()));
- configBuilders.add(new SystemEntryPointBuilder());
- configBuilders.add(new SystemExternalServiceBuilder());
-
- // Create a runtime context and start it
- RuntimeContext runtimeContext = new RuntimeContextImpl(new NullMonitorFactory(), scdlLoaders, configBuilders,new DefaultWireBuilder());
- runtimeContext.start();
-
- // Get the system context
- AggregateContext systemContext = runtimeContext.getSystemContext();
-
- // Load the system module component
- ModuleComponentConfigurationLoader loader = new ModuleComponentConfigurationLoaderImpl(modelContext);
- ModuleComponent systemModuleComponent = loader.loadSystemModuleComponent(SYSTEM_MODULE_COMPONENT, SYSTEM_MODULE_COMPONENT);
-
- // Register it with the system context
- systemContext.registerModelObject(systemModuleComponent);
-
- // Get the aggregate context representing the system module component
- AggregateContext systemModuleComponentContext = (AggregateContext) systemContext.getContext(SYSTEM_MODULE_COMPONENT);
- systemModuleComponentContext.registerModelObject(systemModuleComponent.getComponentImplementation());
- systemModuleComponentContext.fireEvent(EventContext.MODULE_START, null);
-
- // Load the SCDL configuration of the application module
- String uri = context.getPath().substring(1);
- ModuleComponent moduleComponent = loader.loadModuleComponent(moduleComponentName, uri);
-
- // Register it under the root application context
- runtimeContext.getRootContext().registerModelObject(moduleComponent);
- AggregateContext moduleContext=(AggregateContext)runtimeContext.getContext(moduleComponent.getName());
- moduleContext.registerModelObject(moduleComponent.getComponentImplementation());
-
- // Create a Tuscany runtime and store it in the servlet
- // context
- TuscanyWebAppRuntime tuscanyRuntime = new TuscanyWebAppRuntime(moduleContext);
- context.getServletContext().setAttribute(TuscanyWebAppRuntime.class.getName(), tuscanyRuntime);
-
- // Start the runtime and the module component context
- tuscanyRuntime.start();
- try {
- //moduleContext.start();
-
- moduleContext.fireEvent(EventContext.MODULE_START, null);
-
- } finally {
- tuscanyRuntime.stop();
- }
-
- // Set up the SCA web app filter and listener
- FilterDef def = new FilterDef();
- def.setDescription("SCA Filter");
- def.setFilterClass(TuscanyRequestFilter.class.getName());
- def.setFilterName("__modContext");
- def.setDisplayName("SCA Filter");
- FilterMap map = new FilterMap();
- map.setFilterName("__modContext");
- map.setURLPattern("/*");
- context.addFilterDef(def);
- context.addFilterMap(map);
- context.addApplicationListener(HTTPSessionExpirationListener.class.getName());
-
- } catch (CoreRuntimeException e) {
- throw new ServiceRuntimeException(e);
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else if (Lifecycle.STOP_EVENT.equals(lifecycleEventType) && lifecycleEventSource instanceof Context) {
-
- // The web app is stopping
- Context context = (Context) lifecycleEventSource;
- try {
-
- // Get the tuscany runtime from the servlet context
- // If the servlet context contains a tuscany runtime then this is a
- // Tuscany app
- TuscanyWebAppRuntime tuscanyRuntime = (TuscanyWebAppRuntime) context.getServletContext().getAttribute(
- TuscanyWebAppRuntime.class.getName());
- if (tuscanyRuntime != null) {
-
- // Get the module component name from the servlet context
- try {
- // Start the runtime
- tuscanyRuntime.start();
- try {
- // Stop the module context
- AggregateContext aggregateContext = tuscanyRuntime.getModuleComponentContext();
- aggregateContext.fireEvent(EventContext.MODULE_STOP, null);
- aggregateContext.stop();
- } finally {
-
- // Stop the runtime
- tuscanyRuntime.stop();
-
- // Cleanup the servlet context
- context.getServletContext().removeAttribute(TuscanyWebAppRuntime.class.getName());
- }
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
-}
diff --git a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java b/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java
deleted file mode 100644
index 0e9a80f13d..0000000000
--- a/tags/java-stable-20060304/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed 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.tomcat.lifecycle.listener;
-
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.deploy.FilterDef;
-import org.apache.catalina.deploy.FilterMap;
-import org.apache.tuscany.common.TuscanyRuntimeException;
-import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.webapp.HTTPSessionExpirationListener;
-import org.apache.tuscany.core.context.webapp.TuscanyRequestFilter;
-import org.apache.tuscany.core.context.webapp.TuscanyWebAppRuntime;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeMonitor;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-
-/**
- * Responsible for initializing web applications as module components in a Tomcat instance. When a web app is being
- * loaded in Tomcat, this listener receives a callback to register a corresponding module component and set up the
- * appropriate Servlet filters in the web context.
- * <p>
- * Note that Tomcat loads this class in the standard (common/lib) classloader even though the context classloader is
- * that of the web app being loaded.
- */
-public class WebAppLifecycleListener implements LifecycleListener {
-
- private RuntimeContext runtime;
-
- private RuntimeMonitor monitor;
-
- // ----------------------------------
- // Constructors
- // ----------------------------------
-
- public WebAppLifecycleListener() {
- // locate runtime in the global naming context
- javax.naming.Context context = null;
- try {
- context = (javax.naming.Context) (new InitialContext()).lookup("java:/");
- runtime = (RuntimeContext) context.lookup(RuntimeBootstrap.RUNTIME_NAME);
- monitor = runtime.getMonitorFactory().getMonitor(RuntimeMonitor.class);
- } catch (NamingException e) {
- // FIXME need bootstrap logging;
- return;
- }
- }
-
- /**
- * Callback for receiving web application events. When a web app containing an SCA configuration is initialized, a
- * module component is created and appropriate SCA filters are set for in the web context. If a web app stop event
- * is received, the corresponding module component is deregistered from the system.
- */
- public void lifecycleEvent(LifecycleEvent event) {
- String lifecycleEventType = event.getType();
- Object lifecycleEventSource = event.getSource();
-
- if (Lifecycle.START_EVENT.equals(lifecycleEventType) && lifecycleEventSource instanceof Context) {
- // The web app is starting
- Context context = (Context) lifecycleEventSource;
- String name = context.getPath().substring(1);
- try {
- ModuleComponent moduleComponent = null;// FIXME runtime.loadModuleComponent(name, "sca.module");
- if (moduleComponent == null) {
- return; // not an SCA module component
- }
- // create the module component
- runtime.registerModelObject(moduleComponent);
- AggregateContext aggregateContext = (AggregateContext) runtime.getContext(moduleComponent.getName());
- TuscanyWebAppRuntime tuscanyRuntime = new TuscanyWebAppRuntime(aggregateContext);
- context.getServletContext().setAttribute(TuscanyWebAppRuntime.class.getName(), tuscanyRuntime);
- // Start the runtime and the module component context
- tuscanyRuntime.start();
- try {
- aggregateContext.start();
- aggregateContext.fireEvent(EventContext.MODULE_START, null);
- } finally {
- tuscanyRuntime.stop();
- }
- // Set up the SCA web app filter and listener
- FilterDef def = new FilterDef();
- def.setDescription("SCA Filter");
- def.setFilterClass(TuscanyRequestFilter.class.getName());
- def.setFilterName("__modContext");
- def.setDisplayName("SCA Filter");
- FilterMap map = new FilterMap();
- map.setFilterName("__modContext");
- map.setURLPattern("/*");
- context.addFilterDef(def);
- context.addFilterMap(map);
- context.addApplicationListener(HTTPSessionExpirationListener.class.getName());
- } catch (ConfigurationException e) {
- e.addContextName(name);
- monitor.log(e);
- return;
- } catch (TuscanyRuntimeException e) {
- e.addContextName(name);
- monitor.log(e);
- return;
- }
- } else if (Lifecycle.STOP_EVENT.equals(lifecycleEventType) && lifecycleEventSource instanceof Context) {
- // The web app is stopping
- Context context = (Context) lifecycleEventSource;
- // Get the tuscany runtime from the servlet context
- TuscanyWebAppRuntime tuscanyRuntime = (TuscanyWebAppRuntime) context.getServletContext().getAttribute(
- TuscanyWebAppRuntime.class.getName());
- if (tuscanyRuntime == null) {
- return; // not an SCA module
- }
- try {
- // Stop the module context
- tuscanyRuntime.start();
- AggregateContext aggregateContext = tuscanyRuntime.getModuleComponentContext();
- aggregateContext.fireEvent(EventContext.MODULE_STOP, null);
- aggregateContext.stop();
- } catch (TuscanyRuntimeException e) {
- monitor.log(e);
- } finally {
- try {
- tuscanyRuntime.stop();
- } catch (TuscanyRuntimeException e) {
- monitor.log(e);
- } finally {
- // Cleanup the servlet context
- context.getServletContext().removeAttribute(TuscanyWebAppRuntime.class.getName());
- }
- }
-
- }
- }
-}