You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/09/03 08:02:46 UTC
svn commit: r439728 [1/2] - in /incubator/tuscany/java/sca:
containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/
containers/container.spring/src/main/java/org/springframework/sca/
containers/container.spring/src/main/java...
Author: jmarino
Date: Sat Sep 2 23:02:44 2006
New Revision: 439728
URL: http://svn.apache.org/viewvc?rev=439728&view=rev
Log:
cleanup web app launcher to properly bootstrap the runtime (multiparent classloading still needs to be done) including request binding and session events; add configuration of current composite from a nested hierarchy; add test cases; cleanup Spring composite so it may now be booted in a web app; removal of webappp project dependencies on SDO and Axis as they break all other web app projects (they will need to be manually added in to when needed
Added:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java (with props)
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java (with props)
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java (contents, props changed)
- copied, changed from r439524, incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java (with props)
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java (with props)
Removed:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Modified:
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringScaAdapter.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaPostProcessor.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaServiceProxyFactoryBean.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/config/ScaNamespaceHandler.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/intercept/OneWayAdvisor.java
incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/metadata/AnnotationServiceMetadata.java
incubator/tuscany/java/sca/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LaunchException.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LauncherImpl.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/annotation/Autowire.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/sca/webapp.system.scdl
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponent.java Sat Sep 2 23:02:44 2006
@@ -69,8 +69,7 @@
public SpringCompositeComponent(String name,
AbstractApplicationContext springContext,
CompositeComponent parent,
- Map<String, Document> propertyValues
- ) {
+ Map<String, Document> propertyValues) {
super(name, parent, propertyValues);
SCAApplicationContext scaApplicationContext = new SCAApplicationContext();
springContext.setParent(scaApplicationContext);
@@ -108,6 +107,10 @@
springContext.stop();
}
+ public <T> T locateService(Class<T> serviceInterface, String name) {
+ return serviceInterface.cast(springContext.getBean(name));
+ }
+
/**
* An inner class is required to act as the Spring application context parent as opposed to implementing the
* interface since the return types for {@link org.springframework.context.ApplicationContext#getParent()} and
@@ -123,7 +126,7 @@
public Object getBean(String name, Class requiredType) throws BeansException {
SCAObject object = (SCAObject) children.get(name); // keep cast due to compiler error
if (object == null) {
- throw new NoSuchBeanDefinitionException("SCA service not found [" + name + "]");
+ return null;
}
Class<?> type;
if (object instanceof Reference) {
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringScaAdapter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringScaAdapter.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringScaAdapter.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/apache/tuscany/container/spring/impl/SpringScaAdapter.java Sat Sep 2 23:02:44 2006
@@ -25,10 +25,10 @@
* @since 2.1
*/
public class SpringScaAdapter implements ScaAdapter {
- private final CompositeComponentType componentType;
+ //private final CompositeComponentType componentType;
public SpringScaAdapter(CompositeComponentType componentType) {
- this.componentType = componentType;
+ //this.componentType = componentType;
}
public Object getServiceReference(String referenceName, Class referenceType, String moduleName,
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaPostProcessor.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaPostProcessor.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaPostProcessor.java Sat Sep 2 23:02:44 2006
@@ -47,7 +47,7 @@
private TaskExecutor taskExecutor;
- private ScaAdapter scaAdapter;
+ //private ScaAdapter scaAdapter;
/**
@@ -67,7 +67,7 @@
* @param scaAdapter the ScaAdapter for use to export services if necessary
*/
public void setScaAdapter(ScaAdapter scaAdapter) {
- this.scaAdapter = scaAdapter;
+ //this.scaAdapter = scaAdapter;
}
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaServiceProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaServiceProxyFactoryBean.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaServiceProxyFactoryBean.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/ScaServiceProxyFactoryBean.java Sat Sep 2 23:02:44 2006
@@ -50,7 +50,7 @@
private Object resolvedServiceReference;
private ApplicationContext applicationContext;
- private ScaAdapter scaAdapter;
+ //private ScaAdapter scaAdapter;
public void setServiceType(Class serviceType) {
this.serviceType = serviceType;
@@ -138,6 +138,6 @@
}
public void setScaAdapter(ScaAdapter adapter) {
- this.scaAdapter = adapter;
+ // this.scaAdapter = adapter;
}
}
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/config/ScaNamespaceHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/config/ScaNamespaceHandler.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/config/ScaNamespaceHandler.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/config/ScaNamespaceHandler.java Sat Sep 2 23:02:44 2006
@@ -34,7 +34,7 @@
init();
}
- public void init() {
+ public final void init() {
registerBeanDefinitionParser("composite", new ScaCompositeBeanDefinitionParser());
registerBeanDefinitionParser("reference", new ScaReferenceBeanDefinitionParser());
registerBeanDefinitionParser("property", new ScaPropertyBeanDefinitionParser());
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/intercept/OneWayAdvisor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/intercept/OneWayAdvisor.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/intercept/OneWayAdvisor.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/intercept/OneWayAdvisor.java Sat Sep 2 23:02:44 2006
@@ -74,9 +74,8 @@
});
} catch (Throwable t) {
t.printStackTrace();
- } finally {
- return null;
}
+ return null;
}
}
Modified: incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/metadata/AnnotationServiceMetadata.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/metadata/AnnotationServiceMetadata.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/metadata/AnnotationServiceMetadata.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/main/java/org/springframework/sca/metadata/AnnotationServiceMetadata.java Sat Sep 2 23:02:44 2006
@@ -51,8 +51,7 @@
}
public Class<?>[] getServiceInterfaces() {
- Service service = serviceClass.getAnnotation(Service.class);
- return service.interfaces();
+ return serviceClass.getAnnotation(Service.class).interfaces();
}
public List<Method> getOneWayMethods() {
@@ -79,7 +78,7 @@
// TODO fields propertly
ReflectionUtils.doWithFields(serviceClass, new ReflectionUtils.FieldCallback() {
- public void doWith(Field f) throws IllegalArgumentException, IllegalAccessException {
+ public void doWith(Field f) throws IllegalArgumentException {
if (f.isAnnotationPresent(ComponentName.class)) {
Injection componentNameInjection = new FieldInjection(f);
componentNameInjection.setLiteralValue(name);
Modified: incubator/tuscany/java/sca/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java Sat Sep 2 23:02:44 2006
@@ -27,7 +27,6 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import org.springframework.beans.PropertyValue;
-import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.AbstractApplicationContext;
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java Sat Sep 2 23:02:44 2006
@@ -19,9 +19,9 @@
package org.apache.tuscany.core.launcher;
import org.osoa.sca.CompositeContext;
-import org.osoa.sca.ServiceReference;
import org.osoa.sca.RequestContext;
import org.osoa.sca.SCA;
+import org.osoa.sca.ServiceReference;
import org.apache.tuscany.spi.component.CompositeComponent;
@@ -62,7 +62,7 @@
}
public <T> T locateService(Class<T> serviceInterface, String serviceName) {
- return serviceInterface.cast(composite.getChild(serviceName).getServiceInstance());
+ return composite.locateService(serviceInterface, serviceName);
}
public ServiceReference newSession(String arg0) {
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LaunchException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LaunchException.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LaunchException.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LaunchException.java Sat Sep 2 23:02:44 2006
@@ -18,12 +18,14 @@
*/
package org.apache.tuscany.core.launcher;
+import org.apache.tuscany.api.TuscanyException;
+
/**
* Exception indicating that there was a problem launching an application.
*
* @version $Rev$ $Date$
*/
-public abstract class LaunchException extends Exception {
+public abstract class LaunchException extends TuscanyException {
public LaunchException() {
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LauncherImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LauncherImpl.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LauncherImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/LauncherImpl.java Sat Sep 2 23:02:44 2006
@@ -92,12 +92,12 @@
SystemCompositeImplementation moduleImplementation = new SystemCompositeImplementation();
moduleImplementation.setScdlLocation(systemScdl);
moduleImplementation.setClassLoader(systemClassLoader);
- ComponentDefinition<SystemCompositeImplementation> moduleDefinition =
+ ComponentDefinition<SystemCompositeImplementation> definition =
new ComponentDefinition<SystemCompositeImplementation>(
ComponentNames.TUSCANY_SYSTEM, moduleImplementation);
// deploy the component into the runtime under the system parent
- composite = (CompositeComponent<?>) bootDeployer.deploy(parent, moduleDefinition);
+ composite = (CompositeComponent<?>) bootDeployer.deploy(parent, definition);
// start the system
composite.start();
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/annotation/Autowire.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/annotation/Autowire.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/annotation/Autowire.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/annotation/Autowire.java Sat Sep 2 23:02:44 2006
@@ -41,6 +41,6 @@
/**
* Indicates if a reference must be specified.
*/
- public boolean required() default true;
+ boolean required() default true;
}
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java Sat Sep 2 23:02:44 2006
@@ -67,6 +67,11 @@
Service getService(String name) throws ComponentNotFoundException;
/**
+ * Returns the service instance for associated with the child registered for the given name
+ */
+ <T> T locateService(Class<T> serviceInterface, String serviceName);
+
+ /**
* Returns the references contained by the composite
*/
List<Reference> getReferences();
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java Sat Sep 2 23:02:44 2006
@@ -136,6 +136,10 @@
return (Service) ctx;
}
+ public <T> T locateService(Class<T> serviceInterface, String name) {
+ return serviceInterface.cast(children.get(name).getServiceInstance());
+ }
+
public List<Reference> getReferences() {
return Collections.unmodifiableList(references);
}
Added: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,25 @@
+package org.apache.tuscany.runtime.webapp;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Denotes an invalid path representing a composite in application hierarchy
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidCompositePath extends TuscanyException {
+ public InvalidCompositePath() {
+ }
+
+ public InvalidCompositePath(String message) {
+ super(message);
+ }
+
+ public InvalidCompositePath(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidCompositePath(Throwable cause) {
+ super(cause);
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/InvalidCompositePath.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java Sat Sep 2 23:02:44 2006
@@ -35,8 +35,7 @@
import org.apache.tuscany.host.servlet.ServletRequestInjector;
/**
- * ServletHost impl that forwards requests to registered servlets TODO: TUSCANY-649, move this and
- * ServletLauncherListener to a new webapp-host module
+ * A <code>ServletHost</code> implementation that forwards requests to registered servlets
*/
@Service(ServletHost.class)
public class ServletHostImpl implements ServletHost, ServletRequestInjector {
@@ -62,7 +61,6 @@
}
public void registerMapping(String path, Servlet servlet) {
-
if (servlets.containsKey(path)) {
throw new IllegalStateException("Servlet already registered at path: " + path);
}
Added: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.runtime.webapp;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Thrown when an error is encountered booting the runtme in a web app environment
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServletLauncherInitException extends TuscanyRuntimeException {
+
+ public ServletLauncherInitException() {
+ }
+
+ public ServletLauncherInitException(String message) {
+ super(message);
+ }
+
+ public ServletLauncherInitException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ServletLauncherInitException(Throwable cause) {
+ super(cause);
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java Sat Sep 2 23:02:44 2006
@@ -20,154 +20,176 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
import java.util.logging.Level;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionEvent;
+import org.osoa.sca.SCA;
+
+import org.apache.tuscany.spi.component.Component;
import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.deployer.Deployer;
import org.apache.tuscany.spi.loader.LoaderException;
import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.component.event.RequestStart;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
import org.apache.tuscany.core.launcher.CompositeContextImpl;
import org.apache.tuscany.core.launcher.LauncherImpl;
+import static org.apache.tuscany.core.launcher.LauncherImpl.METAINF_SYSTEM_SCDL_PATH;
import org.apache.tuscany.core.monitor.MonitorFactoryUtil;
import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.CURRENT_COMPOSITE_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.DEFAULT_EXTENSION_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.EXTENSION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_MONITORING_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
/**
- * LauncherImpl for runtime environment that loads info from servlet context params. This listener manages one top-level
- * LauncherImpl (and hence one Tuscany runtime context) per servlet context; the lifecycle of that runtime corresponds
- * to the the lifecycle of the associated servlet context.
+ * Bootstrapper for the Tuscany runtime in a web application host. This listener manages one runtime per servlet
+ * context; the lifecycle of that runtime corresponds to the the lifecycle of the associated servlet context.
+ * <p/>
+ * The bootstrapper launches the runtime, booting system extensions and applications, according to the servlet
+ * parameters defined in {@link Constants}. When the runtime is instantiated, it is placed in the servlet context with
+ * the attribute {@link Constants.RUNTIME_ATTRIBUTE}. The runtime implements {@link TuscanyWebappRuntime} so that
+ * filters and servlets loaded in the parent web app classloader may pass events and requests to it.
* <p/>
- * Web application code may obtain the top-level CompositeContext via
- * {@link org.osoa.sca.CurrentCompositeContext#getContext()}.
- * If that returns null, it is likely the runtime failed to boot: the context param {@link LAUNCHER_THROWABLE_ATTRIBUTE}
- * will contain a {@link Throwable} with diagnostic information.
+ * By default, the top-most application composite component will be returned when "non-managed" web application code
+ * such as JSPs call {@link org.osoa.sca.CurrentCompositeContext}. If a composite deeper in the hierarchy should be
+ * returned instead, the <code>web.xml</code> must contain an entry for {@link Constants.CURRENT_COMPOSITE_PATH_PARAM}
+ * whose value is a component path expression using '/' as a delimeter such as foo/bar/baz.
*
* @version $$Rev$$ $$Date$$
*/
-public class ServletLauncherListener implements ServletContextListener {
- /**
- * Servlet context-param name for user-specified system SCDL path.
- */
- public static final String SYSTEM_SCDL_PATH_PARAM = "systemScdlPath";
- /**
- * Servlet context-param name for user-specified application SCDL path.
- */
- public static final String APPLICATION_SCDL_PATH_PARAM = "applicationScdlPath";
- /**
- * Servlet context-param name for system monitoring level. Supported values are the names of statics defined in
- * java.util.logging.Level. If absent, no monitoring will take place.
- */
- public static final String SYSTEM_MONITORING_PARAM = "tuscanyMonitoringLevel";
+public class ServletLauncherListener implements TuscanyWebappRuntime {
- /**
- * Default application SCDL path used if no "applicationScdlPath" param is specified
- */
- public static final String DEFAULT_APPLICATION_SCDL_PATH = "/WEB-INF/default.scdl";
-
- /**
- * Context attribute to which an Exception or Error object will be bound to if the launcher fails to initialize.
- */
- public static final String LAUNCHER_THROWABLE_ATTRIBUTE = "Tuscany.LauncherImpl.Throwable";
+ private URL testSystemScdl;
+ private CompositeComponent<?> component;
+ private ServletLauncherMonitor monitor;
+ private LauncherImpl launcher;
+ private CompositeContextImpl context;
+ private ServletRequestInjector requestInjector;
- /**
- * Context attribute to which the active {@link LauncherImpl} managing the runtime for this servlet context is
- * stored.
- */
- private static final String LAUNCHER_ATTRIBUTE = "Tuscany.LauncherImpl";
+ public SCA getContext() {
+ return context;
+ }
- private URL testSystemScdl;
+ public ServletRequestInjector getRequestInjector() {
+ return requestInjector;
+ }
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- ServletContext servletContext = servletContextEvent.getServletContext();
+ public void contextInitialized(ServletContextEvent event) {
+ ServletContext servletContext = event.getServletContext();
// Read optional path to system SCDL from context-param
String systemScdlPath = servletContext.getInitParameter(SYSTEM_SCDL_PATH_PARAM);
if (systemScdlPath == null) {
- systemScdlPath = "/" + LauncherImpl.METAINF_SYSTEM_SCDL_PATH;
+ systemScdlPath = "/" + METAINF_SYSTEM_SCDL_PATH;
}
// Read optional path to application SCDL from context-param
String applicationScdlPath = servletContext.getInitParameter(APPLICATION_SCDL_PATH_PARAM);
if (applicationScdlPath == null) {
- applicationScdlPath = DEFAULT_APPLICATION_SCDL_PATH;
+ applicationScdlPath = Constants.DEFAULT_APPLICATION_SCDL_PATH_PARAM;
}
// Read optional system monitor factory classname
String systemLogging = servletContext.getInitParameter(SYSTEM_MONITORING_PARAM);
MonitorFactory mf = getMonitorFactory(systemLogging);
+ monitor = mf.getMonitor(ServletLauncherMonitor.class);
- LauncherImpl launcher = new LauncherImpl();
+ launcher = new LauncherImpl();
// Current thread context classloader should be the webapp classloader
ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
launcher.setApplicationLoader(webappClassLoader);
- CompositeComponent<?> component;
- CompositeContextImpl context;
-
try {
- URL systemScdl;
- if (testSystemScdl != null) {
- systemScdl = testSystemScdl;
- } else {
- systemScdl = getClass().getResource(systemScdlPath);
- if (systemScdl == null) {
- MissingResourceException e = new MissingResourceException("System SCDL not found");
- e.setIdentifier(systemScdlPath);
- throw e;
- }
- }
+ URL systemScdl = getSystemSCDL(systemScdlPath);
CompositeComponent<?> rt = launcher.bootRuntime(systemScdl, mf);
- servletContext.setAttribute(LAUNCHER_ATTRIBUTE, launcher);
- servletContext
- .setAttribute("Tuscany.ServletRequestInjector", rt.getChild("servletHost").getServiceInstance());
-
- URL appScdl;
- if (applicationScdlPath.startsWith("/")) {
- // Paths begining w/ "/" are treated as webapp resources
- try {
- appScdl = servletContext.getResource(applicationScdlPath);
- } catch (MalformedURLException mue) {
- throw new LoaderException("Unable to find application SCDL: " + applicationScdlPath);
- }
- } else {
- // Other paths are searched using the application classloader
- appScdl = launcher.getApplicationLoader().getResource(applicationScdlPath);
- if (appScdl == null) {
- throw new LoaderException("Unable to find application SCDL: " + applicationScdlPath);
- }
+
+ // Read optional path to extension SCDLs from context-param
+ String extensionScdlPath = servletContext.getInitParameter(EXTENSION_SCDL_PATH_PARAM);
+ if (extensionScdlPath == null) {
+ extensionScdlPath = DEFAULT_EXTENSION_PATH_PARAM;
}
+ // load extensions
+ Set<String> paths = servletContext.getResourcePaths(extensionScdlPath);
+ for (String path : paths) {
+ monitor.deployExtension(path);
+ deployExtension(rt, path, servletContext.getResource(path));
+ }
+
+ // FIXME this is too coupled to the configuration
+ SCAObject host = rt.getChild("servletHost");
+ if (host == null) {
+ MissingResourceException e = new MissingResourceException("ServletHost service not found");
+ e.setIdentifier("servletHost");
+ throw e;
+ }
+ // fixme this case is problematic
+ requestInjector = (ServletRequestInjector) host.getServiceInstance();
+
+ URL appScdl = getApplicationSCDL(applicationScdlPath, servletContext);
+
String name = servletContext.getServletContextName();
if (name == null) {
name = "application";
}
- component = launcher.bootApplication(name, appScdl);
- component.start();
+
+ CompositeComponent<?> root = launcher.bootApplication(name, appScdl);
+ String compositePath = servletContext.getInitParameter(CURRENT_COMPOSITE_PATH_PARAM);
+ root.start();
+ // set the current composite
+ setCurrentComposite(compositePath, root);
context = new CompositeContextImpl(component);
context.start();
+ servletContext.setAttribute(RUNTIME_ATTRIBUTE, this);
- } catch (Throwable t) {
- servletContext.setAttribute(LAUNCHER_THROWABLE_ATTRIBUTE, t);
- servletContext.log("Error launching Tuscany Runtime", t);
+ } catch (Exception e) {
+ throw new ServletLauncherInitException(e);
}
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
- ServletContext servletContext = servletContextEvent.getServletContext();
-
- LauncherImpl launcher = (LauncherImpl) servletContext.getAttribute(LAUNCHER_ATTRIBUTE);
-
if (launcher != null) {
launcher.shutdownRuntime();
}
}
+ public void sessionCreated(HttpSessionEvent event) {
+ component.publish(new HttpSessionStart(this, event.getSession().getId()));
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event) {
+ component.publish(new HttpSessionEnd(this, event.getSession().getId()));
+ }
+
+ public void startRequest() {
+ component.publish(new RequestStart(this));
+ }
+
+ public void stopRequest() {
+ component.publish(new RequestEnd(this));
+ }
+
+
/**
* Sets the system SCDL url for testing
*/
@@ -175,6 +197,36 @@
this.testSystemScdl = testSystemScdl;
}
+ /**
+ * Deploys an system extension
+ *
+ * @param composite the composite to deploy to
+ * @param extensionName the extensionname
+ * @param scdlURL the location of the system SCDL
+ * @throws LoaderException
+ */
+ private void deployExtension(CompositeComponent<?> composite, String extensionName, URL scdlURL)
+ throws LoaderException {
+ SystemCompositeImplementation implementation = new SystemCompositeImplementation();
+ implementation.setScdlLocation(scdlURL);
+ URLClassLoader classLoader = new URLClassLoader(new URL[]{scdlURL}, getClass().getClassLoader());
+ implementation.setClassLoader(classLoader);
+
+ ComponentDefinition<SystemCompositeImplementation> definition =
+ new ComponentDefinition<SystemCompositeImplementation>(extensionName,
+ implementation);
+
+ Deployer deployer = (Deployer) composite.getChild("deployer").getServiceInstance();
+ Component<?> component = deployer.deploy(composite, definition);
+
+ component.start();
+ }
+
+ /**
+ * Returns a monitor factory for the funtime
+ *
+ * @param loggingLevel
+ */
private MonitorFactory getMonitorFactory(String loggingLevel) {
String factoryName = "org.apache.tuscany.core.monitor.NullMonitorFactory";
Map<String, Object> props = null;
@@ -193,4 +245,83 @@
return MonitorFactoryUtil.createMonitorFactory(factoryName, props);
}
+
+ /**
+ * Sets the root to point to a composite in the hierarchy specified by the given path
+ *
+ * @throws InvalidCompositePath
+ */
+ private void setCurrentComposite(String compositePath, CompositeComponent<?> root) throws InvalidCompositePath {
+ if (compositePath != null) {
+ StringTokenizer tokens = new StringTokenizer(compositePath, "/");
+ CompositeComponent<?> current = root;
+ while (tokens.hasMoreTokens()) {
+ String token = tokens.nextToken();
+ SCAObject<?> child = current.getChild(token);
+ if (child == null) {
+ InvalidCompositePath e = new InvalidCompositePath("Composite not found");
+ e.setIdentifier(token);
+ throw e;
+ } else if (!(child instanceof CompositeComponent)) {
+ InvalidCompositePath e = new InvalidCompositePath("Child not a composite");
+ e.setIdentifier(child.getName());
+ throw e;
+ }
+ current = (CompositeComponent<?>) child;
+ }
+ component = current;
+ } else {
+ component = root;
+ }
+ }
+
+ /**
+ * Returns a url to the application SCDL based on the given path
+ *
+ * @throws MissingResourceException
+ */
+ private URL getApplicationSCDL(String path, ServletContext context) throws MissingResourceException {
+ URL appScdl;
+ if (path.startsWith("/")) {
+ // Paths begining w/ "/" are treated as webapp resources
+ try {
+ appScdl = context.getResource(path);
+ } catch (MalformedURLException mue) {
+ MissingResourceException e = new MissingResourceException("Unable to find application SCDL");
+ e.setIdentifier(path);
+ throw e;
+ }
+ } else {
+ // Other paths are searched using the application classloader
+ appScdl = launcher.getApplicationLoader().getResource(path);
+ if (appScdl == null) {
+ MissingResourceException e = new MissingResourceException("Unable to find application SCDL");
+ e.setIdentifier(path);
+ throw e;
+ }
+ }
+ return appScdl;
+ }
+
+ /**
+ * Returns the system SCDL based on the given path
+ *
+ * @throws MissingResourceException
+ */
+ private URL getSystemSCDL(String path) throws MissingResourceException {
+ URL systemScdl;
+ if (testSystemScdl != null) {
+ systemScdl = testSystemScdl;
+ } else {
+ systemScdl = getClass().getResource(path);
+ if (systemScdl == null) {
+ MissingResourceException e = new MissingResourceException("System SCDL not found");
+ e.setIdentifier(path);
+ throw e;
+ }
+ }
+ return systemScdl;
+ }
+
+
}
Modified: incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/sca/webapp.system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/sca/webapp.system.scdl?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/sca/webapp.system.scdl (original)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/sca/webapp.system.scdl Sat Sep 2 23:02:44 2006
@@ -130,9 +130,9 @@
<!-- TODO: Hack the Axis extension in -->
- <include name="binding.axis2" scdlLocation="binding.axis2.scdl"/>
+ <!--<include name="binding.axis2" scdlLocation="binding.axis2.scdl"/> -->
<!-- TODO: Hack the SDO DataBinding extension in -->
- <include name="databinding.sdo" scdlLocation="databinding.sdo.scdl"/>
+ <!-- <include name="databinding.sdo" scdlLocation="databinding.sdo.scdl"/> -->
</composite>
Modified: incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java Sat Sep 2 23:02:44 2006
@@ -18,16 +18,18 @@
*/
package org.apache.tuscany.runtime.webapp;
+import java.net.URL;
+import java.util.Collections;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import org.apache.tuscany.spi.loader.MissingResourceException;
-
import junit.framework.TestCase;
-import static org.apache.tuscany.runtime.webapp.ServletLauncherListener.APPLICATION_SCDL_PATH_PARAM;
-import static org.apache.tuscany.runtime.webapp.ServletLauncherListener.SYSTEM_MONITORING_PARAM;
-import static org.apache.tuscany.runtime.webapp.ServletLauncherListener.SYSTEM_SCDL_PATH_PARAM;
+import org.apache.tuscany.api.TuscanyException;
+import static org.apache.tuscany.runtime.webapp.Constants.DEFAULT_EXTENSION_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
import static org.easymock.EasyMock.expect;
+import org.easymock.IAnswer;
import org.easymock.classextension.EasyMock;
/**
@@ -37,85 +39,76 @@
/**
* Verifies the web app host is configured properly to perform a basic boot
- * <p/>
- * FIXME Uncomment this test case when the webapp project is fixed by removing the dependency on web services
*/
public void testBoot() throws Exception {
-// final Launcher[] launcher = new Launcher[1];
-// ServletLauncherListener listener = new ServletLauncherListener();
-// listener.setTestSystemScdl(getClass().getClassLoader().getResource("META-INF/sca/webapp.system.scdl"));
-// ServletContext context = EasyMock.createMock(ServletContext.class);
-// expect(context.getServletContextName()).andReturn("foo").anyTimes();
-// expect(context.getInitParameter(SYSTEM_SCDL_PATH_PARAM)).andReturn(null);
-// expect(context.getInitParameter(APPLICATION_SCDL_PATH_PARAM)).andReturn(null);
-// expect(context.getInitParameter(SYSTEM_MONITORING_PARAM)).andReturn(null);
-// context.setAttribute(EasyMock.eq("Tuscany.LauncherImpl"), EasyMock.isA(Launcher.class));
-// EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
-// public Object answer() throws Throwable {
-// Object o = EasyMock.getCurrentArguments()[1];
-// launcher[0] = (Launcher) o;
-// return null;
-// }
-// });
-// context.setAttribute(EasyMock.eq("Tuscany.ServletRequestInjector"), EasyMock.isA(ServletHost.class));
-// expect(context.getResource("/WEB-INF/default.scdl"))
-// .andReturn(getClass().getClassLoader().getResource("testapp.scdl"));
-// expect(context.getAttribute(EasyMock.eq("Tuscany.LauncherImpl"))).andReturn(launcher[0]);
-// EasyMock.replay(context);
-// ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
-// EasyMock.expect(event.getServletContext()).andReturn(context).anyTimes();
-// EasyMock.replay(event);
-// listener.contextInitialized(event);
-// listener.contextDestroyed(event);
-// EasyMock.verify(context);
+ final TuscanyWebappRuntime[] runtime = new TuscanyWebappRuntime[1];
+ ServletLauncherListener listener = new ServletLauncherListener();
+ listener.setTestSystemScdl(getClass().getClassLoader().getResource("META-INF/sca/webapp.system.scdl"));
+ ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+ expect(context.getServletContextName()).andReturn("foo").anyTimes();
+ expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
+ context.setAttribute(EasyMock.eq(RUNTIME_ATTRIBUTE), EasyMock.isA(TuscanyWebappRuntime.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ Object o = EasyMock.getCurrentArguments()[1];
+ runtime[0] = (TuscanyWebappRuntime) o;
+ return null;
+ }
+ });
+ URL resource = getClass().getClassLoader().getResource("testapp.scdl");
+ expect(context.getResource("/WEB-INF/default.scdl")).andReturn(resource);
+ context.setAttribute(EasyMock.eq(RUNTIME_ATTRIBUTE), EasyMock.isA(TuscanyWebappRuntime.class));
+ EasyMock.replay(context);
+ ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
+ EasyMock.expect(event.getServletContext()).andReturn(context).anyTimes();
+ EasyMock.replay(event);
+ listener.contextInitialized(event);
+ listener.contextDestroyed(event);
+ EasyMock.verify(context);
}
/**
- * Verifies a {@link org.apache.tuscany.spi.loader.LoaderException} is thrown when the application SCDL is not
- * found
- * <p/>
- * FIXME Uncomment this test case when the webapp project is fixed by removing the dependency on web services
+ * Verifies a an is thrown when the application SCDL is not found
*/
public void testApplicationSCDLNotFound() throws Exception {
-// ServletLauncherListener listener = new ServletLauncherListener();
-// listener.setTestSystemScdl(getClass().getClassLoader().getResource("META-INF/sca/webapp.system.scdl"));
-// ServletContext context = EasyMock.createMock(ServletContext.class);
-// expect(context.getInitParameter(SYSTEM_SCDL_PATH_PARAM)).andReturn(null);
-// expect(context.getServletContextName()).andReturn("foo").anyTimes();
-// context.setAttribute(EasyMock.eq("Tuscany.LauncherImpl"), EasyMock.isA(Launcher.class));
-// context.setAttribute(EasyMock.eq("Tuscany.ServletRequestInjector"), EasyMock.isA(ServletHost.class));
-// expect(context.getInitParameter(APPLICATION_SCDL_PATH_PARAM)).andReturn(null);
-// expect(context.getInitParameter(SYSTEM_MONITORING_PARAM)).andReturn(null);
-// expect(context.getResource("/WEB-INF/default.scdl")).andReturn(null);
-// context.setAttribute(EasyMock.eq("Tuscany.LauncherImpl.Throwable"), EasyMock.isA(LoaderException.class));
-// context.log(EasyMock.isA(String.class), EasyMock.isA(Throwable.class));
-// EasyMock.replay(context);
-// ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
-// expect(event.getServletContext()).andReturn(context);
-// EasyMock.replay(event);
-// listener.contextInitialized(event);
-// EasyMock.verify(context);
+ ServletLauncherListener listener = new ServletLauncherListener();
+ listener.setTestSystemScdl(getClass().getClassLoader().getResource("META-INF/sca/webapp.system.scdl"));
+ ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+ expect(context.getServletContextName()).andReturn("foo").anyTimes();
+ expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
+ EasyMock.replay(context);
+ ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
+ expect(event.getServletContext()).andReturn(context);
+ EasyMock.replay(event);
+ try {
+ listener.contextInitialized(event);
+ fail();
+ } catch (ServletLauncherInitException e) {
+ assertTrue(e.getCause() instanceof TuscanyException);
+ }
+ EasyMock.verify(context);
}
/**
- * Verifies a {@link MissingResourceException} is thrown if the system SCDL is not found
- *
- * @throws Exception
+ * Verifies an exception is thrown if the system SCDL is not found
*/
public void testSystemSCDLNotFound() throws Exception {
ServletLauncherListener listener = new ServletLauncherListener();
- ServletContext context = EasyMock.createMock(ServletContext.class);
+ listener.setTestSystemScdl(getClass().getClassLoader().getResource("META-INF/sca/webapp.system.scdl"));
+ ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+ expect(context.getServletContextName()).andReturn("foo").anyTimes();
expect(context.getInitParameter(SYSTEM_SCDL_PATH_PARAM)).andReturn("notthere");
- context
- .setAttribute(EasyMock.eq("Tuscany.LauncherImpl.Throwable"), EasyMock.isA(MissingResourceException.class));
- expect(context.getInitParameter(APPLICATION_SCDL_PATH_PARAM)).andReturn(null);
- expect(context.getInitParameter(SYSTEM_MONITORING_PARAM)).andReturn(null);
- context.log(EasyMock.isA(String.class), EasyMock.isA(Throwable.class));
+ expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
EasyMock.replay(context);
ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
- EasyMock.expect(event.getServletContext()).andReturn(context);
+ expect(event.getServletContext()).andReturn(context);
EasyMock.replay(event);
- listener.contextInitialized(event);
+ try {
+ listener.contextInitialized(event);
+ fail();
+ } catch (ServletLauncherInitException e) {
+ assertTrue(e.getCause() instanceof TuscanyException);
+ }
EasyMock.verify(context);
}
Copied: incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java (from r439524, incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java?p2=incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java&p1=incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java&r1=439524&r2=439728&rev=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java Sat Sep 2 23:02:44 2006
@@ -20,14 +20,18 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.osoa.sca.SCA;
import junit.framework.TestCase;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
import static org.easymock.EasyMock.expect;
import org.easymock.classextension.EasyMock;
/**
- * Verifies a context listener is properly instantiated and lifecycle events are sent to it
+ * Verifies a context listener is properly instantiated and lifecycle events are sent to it. this must be tested in
+ * webapp-host as the listener isntantiates {@link ServletLauncherListener} reflectively
*
* @version $Rev$ $Date$
*/
@@ -35,26 +39,25 @@
public void testLifecycle() {
ServletContext context = EasyMock.createMock(ServletContext.class);
- expect(context.getInitParameter(TuscanyContextListener.BOOTDIR_PARAM)).andReturn("foo");
+ expect(context.getInitParameter(Constants.BOOTDIR_PARAM)).andReturn("foo");
expect(context.getResourcePaths("foo")).andReturn(null);
- expect(context.getInitParameter(TuscanyContextListener.LAUNCHER_PARAM)).andReturn(TestLauncher.class.getName());
+ expect(context.getInitParameter(Constants.LAUNCHER_PARAM)).andReturn(TestRuntime.class.getName());
EasyMock.replay(context);
ServletContextEvent event = EasyMock.createMock(ServletContextEvent.class);
- EasyMock.expect(event.getServletContext()).andReturn(context);
+ expect(event.getServletContext()).andReturn(context);
EasyMock.replay(event);
TuscanyContextListener listener = new TuscanyContextListener();
listener.contextInitialized(event);
- assertEquals(1, TestLauncher.getInitialized());
listener.contextDestroyed(event);
- assertEquals(1, TestLauncher.getDestroyed());
+ EasyMock.verify(context);
}
- public static class TestLauncher implements ServletContextListener {
+ public static class TestRuntime implements TuscanyWebappRuntime {
private static int initialized;
private static int destroyed;
- public TestLauncher() {
+ public TestRuntime() {
}
public static int getInitialized() {
@@ -71,6 +74,30 @@
public void contextDestroyed(ServletContextEvent servletContextEvent) {
++destroyed;
+ }
+
+ public void sessionCreated(HttpSessionEvent httpSessionEvent) {
+
+ }
+
+ public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
+
+ }
+
+ public SCA getContext() {
+ return null;
+ }
+
+ public ServletRequestInjector getRequestInjector() {
+ return null;
+ }
+
+ public void startRequest() {
+
+ }
+
+ public void stopRequest() {
+
}
}
}
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,63 @@
+package org.apache.tuscany.runtime.webapp;
+
+/**
+ * Constants used by the web application booter
+ *
+ * @version $Rev$ $Date$
+ */
+public final class Constants {
+
+ /**
+ * Context attribute to which the Tuscany runtime for this servlet context is stored.
+ */
+ static final String RUNTIME_ATTRIBUTE = "Tuscany.Runtime";
+
+ /**
+ * Servlet context-param name for the path to the composite to set as the webb app composite
+ */
+ static final String CURRENT_COMPOSITE_PATH_PARAM = "currentCompositePath";
+
+ /**
+ * Servlet context-param name for user-specified system SCDL path.
+ */
+ static final String SYSTEM_SCDL_PATH_PARAM = "systemScdlPath";
+
+ /**
+ * Servlet context-param name for user-specified system SCDL path.
+ */
+ static final String EXTENSION_SCDL_PATH_PARAM = "extensionScdlPath";
+
+ /**
+ * Servlet context-param name for user-specified application SCDL path.
+ */
+ static final String APPLICATION_SCDL_PATH_PARAM = "applicationScdlPath";
+
+ /**
+ * Default application SCDL path used if no "applicationScdlPath" param is specified
+ */
+ static final String DEFAULT_APPLICATION_SCDL_PATH_PARAM = "/WEB-INF/default.scdl";
+
+ /**
+ * Default path for extensions if no "extensionScdlPath param is specified
+ */
+ static final String DEFAULT_EXTENSION_PATH_PARAM = "/META-INF/tuscany.extensions";
+
+ /**
+ * Servlet context-param name for system monitoring level. Supported values are the names of statics defined in
+ * java.util.logging.Level. If absent, no monitoring will take place.
+ */
+ static final String SYSTEM_MONITORING_PARAM = "tuscanyMonitoringLevel";
+
+ /**
+ * Name of the context parameter that defines the directory containing bootstrap jars.
+ */
+ static final String BOOTDIR_PARAM = "tuscany.bootDir";
+
+ /**
+ * Name of the class to load to launch the runtime.
+ */
+ static final String LAUNCHER_PARAM = "tuscany.launcherClass";
+
+ private Constants() {
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,33 @@
+/*
+ * 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.runtime.webapp;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * A monitor interface used during runtime bootstrap
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServletLauncherMonitor {
+
+ @LogLevel("DEBUG")
+ void deployExtension(String path);
+
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java Sat Sep 2 23:02:44 2006
@@ -28,44 +28,56 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import static org.apache.tuscany.runtime.webapp.Constants.LAUNCHER_PARAM;
+
/**
- * Launcher for runtime environment that loads info from servlet context params. This listener manages one top-level
- * Launcher (and hence one Tuscany runtime context) per servlet context; the lifecycle of that runtime corresponds to
- * the the lifecycle of the associated servlet context.
+ * Launches a Tuscany runtime in a web application, loading information from servlet context parameters. This listener
+ * manages one runtime per servlet context; the lifecycle of that runtime corresponds to the the lifecycle of the
+ * associated servlet context.
+ * <p/>
+ * The runtime is launched in a child classloader of the web application, thereby providing isolation between
+ * application and system artifacts. Application code only has access to the SCA API and may not reference Tuscany
+ * system artifacts directly.
+ * <p/>
+ * The <code>web.xml</code> of a web application embedding Tuscany must have entries for this listener and {@link
+ * TuscanySessionListener}. The latter notifies the runtime of session creation and expiration events through a
+ * "bridging" contract, {@link TuscanyWebappRuntime}. The <code>web.xml</code> may also optionally be configured with
+ * entries for {@link TuscanyFilter} and {@link TuscanyServlet}. The former must be mapped to all urls that execute
+ * "unmanaged" code which accesses the Tuscany runtime though the SCA API, for example, JSPs and Servlets. The latter
+ * forwards service requests into the runtime, by default requests sent to URLs relative to the context path beginning
+ * with <code>/services</code>.
*
* @version $Rev$ $Date$
*/
public class TuscanyContextListener implements ServletContextListener {
- /**
- * Name of the context parameter that defines the directory containing bootstrap jars.
- */
- public static final String BOOTDIR_PARAM = "tuscany.bootDir";
-
- /**
- * Name of the class to load to launch the runtime.
- */
- public static final String LAUNCHER_PARAM = "tuscany.launcherClass";
-
- private ServletContextListener runtime;
-
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- ServletContext servletContext = servletContextEvent.getServletContext();
- ClassLoader bootClassLoader = getBootClassLoader(servletContext);
- runtime = getLauncher(servletContext, bootClassLoader);
+ private TuscanyWebappRuntime runtime;
- runtime.contextInitialized(servletContextEvent);
+ public void contextInitialized(ServletContextEvent event) {
+ ServletContext servletContext = event.getServletContext();
+ try {
+ ClassLoader bootClassLoader = getBootClassLoader(servletContext);
+ runtime = getRuntime(servletContext, bootClassLoader);
+ runtime.contextInitialized(event);
+ } catch (IOException e) {
+ servletContext.log("Error instantiating Tuscany bootstrap", e);
+ } catch (ClassNotFoundException e) {
+ servletContext.log("Tuscany bootstrap class not found ", e);
+ } catch (TuscanyRuntimeException e) {
+ servletContext.log("Error instantiating Tuscany bootstrap", e);
+ }
}
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ public void contextDestroyed(ServletContextEvent event) {
if (runtime != null) {
- runtime.contextDestroyed(servletContextEvent);
+ runtime.contextDestroyed(event);
}
}
protected ClassLoader getBootClassLoader(ServletContext servletContext) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- String bootDirName = servletContext.getInitParameter(BOOTDIR_PARAM);
+ String bootDirName = servletContext.getInitParameter(Constants.BOOTDIR_PARAM);
if (bootDirName == null) {
bootDirName = "/WEB-INF/tuscany/boot/";
}
@@ -86,18 +98,13 @@
return new URLClassLoader(urls, contextClassLoader);
}
- protected ServletContextListener getLauncher(ServletContext servletContext, ClassLoader bootClassLoader) {
+ protected TuscanyWebappRuntime getRuntime(ServletContext servletContext, ClassLoader bootClassLoader)
+ throws IOException, ClassNotFoundException {
String launcherClass = servletContext.getInitParameter(LAUNCHER_PARAM);
if (launcherClass == null) {
launcherClass = "org.apache.tuscany.runtime.webapp.ServletLauncherListener";
}
-
- try {
- return (ServletContextListener) Beans.instantiate(bootClassLoader, launcherClass);
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
+ // launch the runtime in a separate classloader to preserve isolation of system artifacts
+ return (TuscanyWebappRuntime) Beans.instantiate(bootClassLoader, launcherClass);
}
}
Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.runtime.webapp;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.osoa.sca.SCA;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * Maps an incoming request and the current composite context to the composite component for the web application. This
+ * filter must be applied to all web application urls that execute unmanaged code (e.g. JSPs and Servlets) which
+ * accesses the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyFilter implements Filter {
+
+ private SCA context;
+ private TuscanyWebappRuntime runtime;
+
+ public void init(FilterConfig config) throws ServletException {
+ runtime = (TuscanyWebappRuntime) config.getServletContext().getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ throw new ServletException("Tuscany is not configured for the web application");
+ }
+ context = runtime.getContext();
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain)
+ throws IOException, ServletException {
+ try {
+ runtime.startRequest();
+ context.start();
+ filterChain.doFilter(req, resp);
+ } finally {
+ context.stop();
+ runtime.stopRequest();
+ }
+ }
+
+ public void destroy() {
+
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java?rev=439728&r1=439727&r2=439728&view=diff
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java Sat Sep 2 23:02:44 2006
@@ -27,28 +27,33 @@
import javax.servlet.http.HttpServlet;
import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
/**
- * A servlet that locates the ServletRequestInjector and forwards requests into the Tuscany runtime. Needs to be added
- * to the webapp web.xml
+ * A servlet that forwards requests intended for SCA services into the Tuscany runtime via a ServletRequestInjector.
+ * This servlet is typically mapped to relative paths beginning with <code>/services</code> in the <code>web.xml</code>
+ * <p/>
+ * TODO a better URL mapping scheme out to be implemented that corresponds to the SCA specification
*/
public class TuscanyServlet extends HttpServlet {
- public static final String TUSCANY_SERVLET_REQUEST_INJECTOR = "Tuscany.ServletRequestInjector";
private static final long serialVersionUID = 1L;
- private ServletRequestInjector servletRequestInjector;
+ private ServletRequestInjector requestInjector;
@Override
- public void init(ServletConfig config) {
+ public void init(ServletConfig config) throws ServletException {
ServletContext servletContext = config.getServletContext();
- this.servletRequestInjector =
- (ServletRequestInjector) servletContext.getAttribute(TUSCANY_SERVLET_REQUEST_INJECTOR);
+ TuscanyWebappRuntime runtime = (TuscanyWebappRuntime) servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ throw new ServletException("Tuscany runtime not configured for web application");
+ }
+ requestInjector = runtime.getRequestInjector();
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
- servletRequestInjector.service(req, res);
+ requestInjector.service(req, res);
}
}
Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,52 @@
+/*
+ * 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.runtime.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * Notifies the Tuscany runtime of session creation and expiration events.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanySessionListener implements HttpSessionListener {
+ private TuscanyWebappRuntime runtime;
+
+ public void sessionCreated(HttpSessionEvent event) {
+ if (runtime == null) {
+ ServletContext context = event.getSession().getServletContext();
+ runtime = (TuscanyWebappRuntime) context.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ context.log("Error on session creation", new ServletException("Tuscany runtime not configured"));
+ return;
+ }
+ }
+ runtime.sessionCreated(event);
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event) {
+ runtime.sessionDestroyed(event);
+
+ }
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java?rev=439728&view=auto
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java Sat Sep 2 23:02:44 2006
@@ -0,0 +1,58 @@
+/*
+ * 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.runtime.webapp;
+
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionListener;
+
+import org.osoa.sca.SCA;
+
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+
+/**
+ * The contract for artifacts loaded in the web application classloader to comminicate with the Tuscany runtime loaded
+ * in a child classloader. For example, filters and listeners may use this interface to notify the runtime of the web
+ * container events.
+ *
+ * @version $Rev$ $Date$
+ * @see TuscanyFilter
+ * @see TuscanySessionListener
+ */
+public interface TuscanyWebappRuntime extends ServletContextListener, HttpSessionListener {
+
+ /**
+ * Returns the current SCA context
+ */
+ SCA getContext();
+
+ /**
+ * Returns the request injector for the runtime
+ */
+ ServletRequestInjector getRequestInjector();
+
+ /**
+ * Notification that the web application has begun servicing a request
+ */
+ void startRequest();
+
+ /**
+ * Notification that the web application has stopped servicing a request
+ */
+ void stopRequest();
+}
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.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