Author: jboynes
Date: Sun Sep 10 08:48:29 2006
New Revision: 441961
URL: http://svn.apache.org/viewvc?view=rev&rev=441961
Log:
rename ServletLauncherListener to WebappRuntimeImpl
convert runtime properties to bean properties on WebappRuntime
make context parameter names consistent (_PARAM and _DEFAULT)
Added:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
(contents, props changed)
- copied, changed from r441838,
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/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
(contents, props changed)
- copied, changed from r441838,
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/TuscanyInitException.java
(with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
(contents, props changed)
- copied, changed from r441838,
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
(with props)
Removed:
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/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.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/TuscanyFilter.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
Copied:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
(from r441838,
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/WebappRuntimeImpl.java?view=diff&rev=441961&p1=incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherListener.java&r1=441838&p2=incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java&r2=441961
==============================================================================
---
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/WebappRuntimeImpl.java
Sun Sep 10 08:48:29 2006
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.runtime.webapp;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
@@ -31,14 +30,6 @@
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;
@@ -49,13 +40,18 @@
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;
+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;
/**
* Bootstrapper for the Tuscany runtime in a web application host. This
listener manages one runtime per servlet
@@ -63,7 +59,7 @@
* <p/>
* The bootstrapper launches the runtime, booting system extensions and
applications, according to the servlet
* parameters defined in [EMAIL PROTECTED] Constants}. When the runtime is
instantiated, it is placed in the servlet context with
- * the attribute [EMAIL PROTECTED] Constants.RUNTIME_ATTRIBUTE}. The runtime
implements [EMAIL PROTECTED] TuscanyWebappRuntime} so that
+ * the attribute [EMAIL PROTECTED] Constants.RUNTIME_ATTRIBUTE}. The runtime
implements [EMAIL PROTECTED] WebappRuntime} so that
* filters and servlets loaded in the parent web app classloader may pass
events and requests to it.
* <p/>
* By default, the top-most application composite component will be returned
when "non-managed" web application code
@@ -74,42 +70,61 @@
* @version $$Rev$$ $$Date$$
*/
-public class ServletLauncherListener implements TuscanyWebappRuntime {
+public class WebappRuntimeImpl implements WebappRuntime {
+ private ServletContext servletContext;
+ private URL systemScdl;
+ private URL applicationScdl;
+ private ClassLoader webappClassLoader;
- private URL testSystemScdl;
- private CompositeComponent<?> component;
+ private CompositeComponent component;
private ServletLauncherMonitor monitor;
private LauncherImpl launcher;
private CompositeContextImpl context;
private ServletRequestInjector requestInjector;
- public void initialize(ServletContext servletContext) {
- // Read optional path to system SCDL from context-param
- String systemScdlPath =
servletContext.getInitParameter(SYSTEM_SCDL_PATH_PARAM);
- if (systemScdlPath == null) {
- systemScdlPath = Constants.WEBAPP_SYSTEM_SCDL_PATH;
- }
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
- // Read optional path to application SCDL from context-param
- String applicationScdlPath =
servletContext.getInitParameter(APPLICATION_SCDL_PATH_PARAM);
- if (applicationScdlPath == null) {
- applicationScdlPath =
Constants.DEFAULT_APPLICATION_SCDL_PATH_PARAM;
- }
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public URL getSystemScdl() {
+ return systemScdl;
+ }
+
+ public void setSystemScdl(URL systemScdl) {
+ this.systemScdl = systemScdl;
+ }
+
+ public URL getApplicationScdl() {
+ return applicationScdl;
+ }
+
+ public void setApplicationScdl(URL applicationScdl) {
+ this.applicationScdl = applicationScdl;
+ }
+
+ public ClassLoader getWebappClassLoader() {
+ return webappClassLoader;
+ }
+
+ public void setWebappClassLoader(ClassLoader webappClassLoader) {
+ this.webappClassLoader = webappClassLoader;
+ }
+ public void initialize() {
// Read optional system monitor factory classname
String systemLogging =
servletContext.getInitParameter(SYSTEM_MONITORING_PARAM);
MonitorFactory mf = getMonitorFactory(systemLogging);
monitor = mf.getMonitor(ServletLauncherMonitor.class);
launcher = new LauncherImpl();
-
- // Current thread context classloader should be the webapp classloader
- ClassLoader webappClassLoader =
Thread.currentThread().getContextClassLoader();
launcher.setApplicationLoader(webappClassLoader);
try {
- URL systemScdl = getSystemSCDL(systemScdlPath);
- CompositeComponent<?> rt = launcher.bootRuntime(systemScdl, mf);
+ CompositeComponent rt = launcher.bootRuntime(systemScdl, mf);
// Read optional path to extension SCDLs from context-param
String extensionScdlPath =
servletContext.getInitParameter(EXTENSION_SCDL_PATH_PARAM);
@@ -136,14 +151,12 @@
// fixme this case is problematic
requestInjector = (ServletRequestInjector)
host.getServiceInstance();
- URL appScdl = getApplicationSCDL(applicationScdlPath,
servletContext);
-
String name = servletContext.getServletContextName();
if (name == null) {
name = "application";
}
- CompositeComponent<?> root = launcher.bootApplication(name,
appScdl);
+ CompositeComponent root = launcher.bootApplication(name,
applicationScdl);
String compositePath =
servletContext.getInitParameter(CURRENT_COMPOSITE_PATH_PARAM);
root.start();
// set the current composite
@@ -189,13 +202,6 @@
/**
- * Sets the system SCDL url for testing
- */
- void setTestSystemScdl(URL testSystemScdl) {
- this.testSystemScdl = testSystemScdl;
- }
-
- /**
* Deploys an system extension
*
* @param composite the composite to deploy to
@@ -203,7 +209,7 @@
* @param scdlURL the location of the system SCDL
* @throws LoaderException
*/
- private void deployExtension(CompositeComponent<?> composite, String
extensionName, URL scdlURL)
+ private void deployExtension(CompositeComponent composite, String
extensionName, URL scdlURL)
throws LoaderException {
SystemCompositeImplementation implementation = new
SystemCompositeImplementation();
implementation.setScdlLocation(scdlURL);
@@ -212,10 +218,10 @@
ComponentDefinition<SystemCompositeImplementation> definition =
new
ComponentDefinition<SystemCompositeImplementation>(extensionName,
- implementation);
+
implementation);
Deployer deployer = (Deployer)
composite.getChild("deployer").getServiceInstance();
- Component<?> component = deployer.deploy(composite, definition);
+ Component component = deployer.deploy(composite, definition);
component.start();
}
@@ -249,13 +255,13 @@
*
* @throws InvalidCompositePath
*/
- private void setCurrentComposite(String compositePath,
CompositeComponent<?> root) throws InvalidCompositePath {
+ private void setCurrentComposite(String compositePath, CompositeComponent
root) throws InvalidCompositePath {
if (compositePath != null) {
StringTokenizer tokens = new StringTokenizer(compositePath, "/");
- CompositeComponent<?> current = root;
+ CompositeComponent current = root;
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
- SCAObject<?> child = current.getChild(token);
+ SCAObject child = current.getChild(token);
if (child == null) {
InvalidCompositePath e = new
InvalidCompositePath("Composite not found");
e.setIdentifier(token);
@@ -265,61 +271,11 @@
e.setIdentifier(child.getName());
throw e;
}
- current = (CompositeComponent<?>) child;
+ 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().getClassLoader().getResource(path);
- if (systemScdl == null) {
- MissingResourceException e = new
MissingResourceException("System SCDL not found");
- e.setIdentifier(path);
- throw e;
- }
- }
- return systemScdl;
- }
-
-
}
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
(from r441838,
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/WebappRuntimeImplTestCase.java?view=diff&rev=441961&p1=incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletLauncherListenerTestCase.java&r1=441838&p2=incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java&r2=441961
==============================================================================
---
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/WebappRuntimeImplTestCase.java
Sun Sep 10 08:48:29 2006
@@ -19,95 +19,50 @@
package org.apache.tuscany.runtime.webapp;
import java.net.URL;
-import java.util.Collections;
import javax.servlet.ServletContext;
import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
-import org.easymock.IAnswer;
-import org.easymock.classextension.EasyMock;
-
-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.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
/**
* @version $Rev$ $Date$
*/
-public class ServletLauncherListenerTestCase extends TestCase {
+public class WebappRuntimeImplTestCase extends TestCase {
+ private URL applicationScdl;
private URL systemScdl;
- private ServletLauncherListener listener;
+ private WebappRuntimeImpl runtime;
+ private ServletContext context;
/**
* Verifies the web app host is configured properly to perform a basic boot
*/
- public void testBoot() throws Exception {
- final TuscanyWebappRuntime[] runtime = new TuscanyWebappRuntime[1];
- listener.setTestSystemScdl(systemScdl);
- 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);
-
- listener.initialize(context);
- listener.destroy();
- EasyMock.verify(context);
- }
-
- /**
- * Verifies a an is thrown when the application SCDL is not found
- */
- public void testApplicationSCDLNotFound() throws Exception {
- listener.setTestSystemScdl(systemScdl);
- 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);
-
- try {
- listener.initialize(context);
- fail();
- } catch (ServletLauncherInitException e) {
- assertTrue(e.getCause() instanceof TuscanyException);
- }
- EasyMock.verify(context);
- }
-
- /**
- * Verifies an exception is thrown if the system SCDL is not found
- */
- public void testSystemSCDLNotFound() throws Exception {
- listener.setTestSystemScdl(systemScdl);
- ServletContext context = EasyMock.createNiceMock(ServletContext.class);
- expect(context.getServletContextName()).andReturn("foo").anyTimes();
-
expect(context.getInitParameter(SYSTEM_SCDL_PATH_PARAM)).andReturn("notthere");
-
expect(context.getResourcePaths(DEFAULT_EXTENSION_PATH_PARAM)).andReturn(Collections.emptySet());
- EasyMock.replay(context);
-
- try {
- listener.initialize(context);
- fail();
- } catch (ServletLauncherInitException e) {
- assertTrue(e.getCause() instanceof TuscanyException);
- }
- EasyMock.verify(context);
+ public void testBootWithDefaults() throws Exception {
+
expect(context.getInitParameter("tuscanyMonitoringLevel")).andReturn(null);
+ expect(context.getInitParameter("extensionScdlPath")).andReturn(null);
+
expect(context.getResourcePaths("/META-INF/tuscany.extensions")).andReturn(null);
+ expect(context.getServletContextName()).andReturn("foo");
+
expect(context.getInitParameter("currentCompositePath")).andReturn(null);
+ context.setAttribute(eq("Tuscany.Runtime"), isA(WebappRuntime.class));
+ replay(context);
+ runtime.initialize();
+ verify(context);
}
protected void setUp() throws Exception {
super.setUp();
- listener = new ServletLauncherListener();
systemScdl = getClass().getResource("/META-INF/tuscany/webapp.scdl");
+ applicationScdl = getClass().getResource("/testapp.scdl");
+ context = createMock(ServletContext.class);
+
+ runtime = new WebappRuntimeImpl();
+ runtime.setWebappClassLoader(getClass().getClassLoader());
+ runtime.setServletContext(context);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setApplicationScdl(applicationScdl);
}
}
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
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?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
Sun Sep 10 08:48:29 2006
@@ -8,60 +8,74 @@
public final class Constants {
/**
- * Context attribute to which the Tuscany runtime for this servlet context
is stored.
+ * Name of the parameter that defines the name of webapp resource
containing bootstrap jars.
*/
- static final String RUNTIME_ATTRIBUTE = "Tuscany.Runtime";
+ static final String BOOTDIR_PARAM = "tuscany.bootDir";
/**
- * Servlet context-param name for the path to the composite to set as the
webb app composite
+ * Default value for BOOTDIR_PARAM.
*/
- static final String CURRENT_COMPOSITE_PATH_PARAM = "currentCompositePath";
+ static final String BOOTDIR_DEFAULT = "/WEB-INF/tuscany/boot";
/**
- * Servlet context-param name for user-specified system SCDL path.
+ * Name of the parameter that defines the class to load to launch the
runtime.
*/
- static final String SYSTEM_SCDL_PATH_PARAM = "systemScdlPath";
+ static final String RUNTIME_PARAM = "tuscany.runtimeImpl";
/**
- * Default webapp system SCDL path.
+ * Name of the default webapp runtime implementation.
*/
- static final String WEBAPP_SYSTEM_SCDL_PATH =
"META-INF/tuscany/webapp.scdl";
+ static final String RUNTIME_DEFAULT =
"org.apache.tuscany.runtime.webapp.WebappRuntimeImpl";
/**
* Servlet context-param name for user-specified system SCDL path.
*/
- static final String EXTENSION_SCDL_PATH_PARAM = "extensionScdlPath";
+ static final String SYSTEM_SCDL_PATH_PARAM = "tuscany.systemScdlPath";
+
+ /**
+ * Default webapp system SCDL path.
+ */
+ static final String SYSTEM_SCDL_PATH_DEFAULT =
"META-INF/tuscany/webapp.scdl";
/**
* Servlet context-param name for user-specified application SCDL path.
*/
- static final String APPLICATION_SCDL_PATH_PARAM = "applicationScdlPath";
+ static final String APPLICATION_SCDL_PATH_PARAM =
"tuscany.applicationScdlPath";
/**
- * Default application SCDL path used if no "applicationScdlPath" param is
specified
+ * Default application SCDL path.
*/
- static final String DEFAULT_APPLICATION_SCDL_PATH_PARAM =
"/WEB-INF/default.scdl";
+ static final String APPLICATION_SCDL_PATH_DEFAULT =
"/WEB-INF/default.scdl";
+
+
+
+
/**
- * Default path for extensions if no "extensionScdlPath param is specified
+ * Context attribute to which the Tuscany runtime for this servlet context
is stored.
*/
- static final String DEFAULT_EXTENSION_PATH_PARAM =
"/META-INF/tuscany.extensions";
+ static final String RUNTIME_ATTRIBUTE = "Tuscany.Runtime";
/**
- * 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.
+ * Servlet context-param name for the path to the composite to set as the
webb app composite
*/
- static final String SYSTEM_MONITORING_PARAM = "tuscanyMonitoringLevel";
+ static final String CURRENT_COMPOSITE_PATH_PARAM = "currentCompositePath";
/**
- * Name of the context parameter that defines the directory containing
bootstrap jars.
+ * Servlet context-param name for user-specified system SCDL path.
*/
- static final String BOOTDIR_PARAM = "tuscany.bootDir";
+ static final String EXTENSION_SCDL_PATH_PARAM = "extensionScdlPath";
/**
- * Name of the class to load to launch the runtime.
+ * Default path for extensions if no "extensionScdlPath param is specified
*/
- static final String LAUNCHER_PARAM = "tuscany.launcherClass";
+ 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";
private Constants() {
}
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?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
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
Sun Sep 10 08:48:29 2006
@@ -18,8 +18,6 @@
*/
package org.apache.tuscany.runtime.webapp;
-import java.beans.Beans;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -29,7 +27,14 @@
import javax.servlet.ServletContextListener;
import org.apache.tuscany.api.TuscanyRuntimeException;
-import static org.apache.tuscany.runtime.webapp.Constants.LAUNCHER_PARAM;
+import static
org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+import static
org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_PARAM;
+import static
org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_DEFAULT;
+import static
org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
/**
* Launches a Tuscany runtime in a web application, loading information from
servlet context parameters. This listener
@@ -42,7 +47,7 @@
* <p/>
* The <code>web.xml</code> of a web application embedding Tuscany must have
entries for this listener and [EMAIL PROTECTED]
* TuscanySessionListener}. The latter notifies the runtime of session
creation and expiration events through a
- * "bridging" contract, [EMAIL PROTECTED] TuscanyWebappRuntime}. The
<code>web.xml</code> may also optionally be configured with
+ * "bridging" contract, [EMAIL PROTECTED] WebappRuntime}. The
<code>web.xml</code> may also optionally be configured with
* entries for [EMAIL PROTECTED] TuscanyFilter} and [EMAIL PROTECTED]
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
@@ -52,20 +57,25 @@
*/
public class TuscanyContextListener implements ServletContextListener {
- private TuscanyWebappRuntime runtime;
+ private WebappRuntime runtime;
public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
try {
- ClassLoader bootClassLoader = getBootClassLoader(servletContext);
+ ClassLoader webappClassLoader =
Thread.currentThread().getContextClassLoader();
+ ClassLoader bootClassLoader = getBootClassLoader(servletContext,
webappClassLoader);
runtime = getRuntime(servletContext, bootClassLoader);
- runtime.initialize(servletContext);
- } catch (IOException e) {
- servletContext.log("Error instantiating Tuscany bootstrap", e);
- } catch (ClassNotFoundException e) {
- servletContext.log("Tuscany bootstrap class not found ", e);
+ URL systemScdl = getSystemScdl(servletContext, bootClassLoader);
+ URL applicationScdl = getApplicationScdl(servletContext,
webappClassLoader);
+
+ runtime.setServletContext(servletContext);
+ runtime.setWebappClassLoader(webappClassLoader);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setApplicationScdl(applicationScdl);
+ runtime.initialize();
} catch (TuscanyRuntimeException e) {
- servletContext.log("Error instantiating Tuscany bootstrap", e);
+ servletContext.log(e.getMessage(), e);
+ throw e;
}
}
@@ -75,16 +85,20 @@
}
}
- protected ClassLoader getBootClassLoader(ServletContext servletContext) {
- ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
- String bootDirName =
servletContext.getInitParameter(Constants.BOOTDIR_PARAM);
- if (bootDirName == null) {
- bootDirName = "/WEB-INF/tuscany/boot/";
- }
+ /**
+ * Return the classloader that should be used to boot the Tuscany runtime.
+ * This will be a child of the web application's ClassLoader.
+ *
+ * @param servletContext the servlet context for the webapp containing
the bootstrap classes
+ * @param webappClassLoader the web application's classloader
+ * @return a classloader that can be used to load the Tuscany runtime
classes
+ */
+ protected ClassLoader getBootClassLoader(ServletContext servletContext,
ClassLoader webappClassLoader) {
+ String bootDirName = getInitParameter(servletContext, BOOTDIR_PARAM,
BOOTDIR_DEFAULT);
Set paths = servletContext.getResourcePaths(bootDirName);
if (paths == null) {
// nothing in boot directory, assume everything is in the webapp
classloader
- return contextClassLoader;
+ return webappClassLoader;
}
URL[] urls = new URL[paths.size()];
int i = 0;
@@ -92,19 +106,69 @@
try {
urls[i++] = servletContext.getResource((String) path);
} catch (MalformedURLException e) {
- throw new AssertionError("getResourcePaths returned an invalid
path");
+ throw new AssertionError("getResourcePaths returned an invalid
path: " + path);
}
}
- return new URLClassLoader(urls, contextClassLoader);
+ return new URLClassLoader(urls, webappClassLoader);
+ }
+
+ protected WebappRuntime getRuntime(ServletContext servletContext,
ClassLoader bootClassLoader) {
+ try {
+ String className = getInitParameter(servletContext, RUNTIME_PARAM,
RUNTIME_DEFAULT);
+ Class<?> runtimeClass = bootClassLoader.loadClass(className);
+ return (WebappRuntime) runtimeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new TuscanyInitException("Invalid runtime class", e);
+ } catch (IllegalAccessException e) {
+ throw new TuscanyInitException("Invalid runtime class", e);
+ } catch (ClassNotFoundException e) {
+ throw new TuscanyInitException("Runtime Implementation not found",
e);
+ }
+ }
+
+ protected URL getSystemScdl(ServletContext servletContext, ClassLoader
bootClassLoader) {
+ String path = getInitParameter(servletContext, SYSTEM_SCDL_PATH_PARAM,
SYSTEM_SCDL_PATH_DEFAULT);
+ try {
+ return getScdlURL(path, servletContext, bootClassLoader);
+ } catch (MalformedURLException e) {
+ throw new TuscanyInitException("Invalid resource path for " +
SYSTEM_SCDL_PATH_PARAM + " : " + path, e);
+ }
+ }
+
+ protected URL getApplicationScdl(ServletContext servletContext,
ClassLoader bootClassLoader) {
+ String path = getInitParameter(servletContext,
APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
+ try {
+ return getScdlURL(path, servletContext, bootClassLoader);
+ } catch (MalformedURLException e) {
+ throw new TuscanyInitException("Invalid resource path for " +
APPLICATION_SCDL_PATH_PARAM + " : " + path,
+ e);
+ }
+ }
+
+ protected URL getScdlURL(String path, ServletContext servletContext,
ClassLoader classLoader)
+ throws MalformedURLException {
+ if (path.charAt(0) == '/') {
+ // user supplied an absolute path - look up as a webapp resource
+ return servletContext.getResource(path);
+ } else {
+ // user supplied a relative path - look up as a boot classpath
resource
+ return classLoader.getResource(path);
+ }
}
- 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";
+ /**
+ * Return a init parameter from the servlet context or provide a default.
+ *
+ * @param servletContext the servlet context for the application
+ * @param name the name of the parameter
+ * @param value the default value
+ * @return the value of the specified parameter, or the default if not
defined
+ */
+ protected String getInitParameter(ServletContext servletContext, String
name, String value) {
+ String result = servletContext.getInitParameter(name);
+ if (result != null && result.length() != 0) {
+ return result;
}
- // launch the runtime in a separate classloader to preserve isolation
of system artifacts
- return (TuscanyWebappRuntime) Beans.instantiate(bootClassLoader,
launcherClass);
+ return value;
}
}
Modified:
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?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
Sun Sep 10 08:48:29 2006
@@ -40,10 +40,10 @@
public class TuscanyFilter implements Filter {
private SCA context;
- private TuscanyWebappRuntime runtime;
+ private WebappRuntime runtime;
public void init(FilterConfig config) throws ServletException {
- runtime = (TuscanyWebappRuntime)
config.getServletContext().getAttribute(RUNTIME_ATTRIBUTE);
+ runtime = (WebappRuntime)
config.getServletContext().getAttribute(RUNTIME_ATTRIBUTE);
if (runtime == null) {
throw new ServletException("Tuscany is not configured for the web
application");
}
Added:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java?view=auto&rev=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java
(added)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java
Sun Sep 10 08:48:29 2006
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * Exception indicating that there was a problem starting the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyInitException extends TuscanyRuntimeException {
+ public TuscanyInitException(String string) {
+ super(string);
+ }
+
+ public TuscanyInitException(String string, Throwable throwable) {
+ super(string, throwable);
+ }
+
+ public TuscanyInitException(Throwable throwable) {
+ super(throwable);
+ }
+}
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.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?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
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
Sun Sep 10 08:48:29 2006
@@ -44,7 +44,7 @@
@Override
public void init(ServletConfig config) throws ServletException {
ServletContext servletContext = config.getServletContext();
- TuscanyWebappRuntime runtime = (TuscanyWebappRuntime)
servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ WebappRuntime runtime = (WebappRuntime)
servletContext.getAttribute(RUNTIME_ATTRIBUTE);
if (runtime == null) {
throw new ServletException("Tuscany runtime not configured for web
application");
}
Modified:
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?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
Sun Sep 10 08:48:29 2006
@@ -31,12 +31,12 @@
* @version $Rev$ $Date$
*/
public class TuscanySessionListener implements HttpSessionListener {
- private TuscanyWebappRuntime runtime;
+ private WebappRuntime runtime;
public void sessionCreated(HttpSessionEvent event) {
if (runtime == null) {
ServletContext context = event.getSession().getServletContext();
- runtime = (TuscanyWebappRuntime)
context.getAttribute(RUNTIME_ATTRIBUTE);
+ runtime = (WebappRuntime) context.getAttribute(RUNTIME_ATTRIBUTE);
if (runtime == null) {
context.log("Error on session creation", new
ServletException("Tuscany runtime not configured"));
return;
Copied:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
(from r441838,
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/WebappRuntime.java?view=diff&rev=441961&p1=incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java&r1=441838&p2=incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyWebappRuntime.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
Sun Sep 10 08:48:29 2006
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.runtime.webapp;
+import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionListener;
@@ -34,13 +35,68 @@
* @see TuscanyFilter
* @see TuscanySessionListener
*/
-public interface TuscanyWebappRuntime extends HttpSessionListener {
+public interface WebappRuntime extends HttpSessionListener {
+ /**
+ * Returns the ServletContext associated with this runtime.
+ *
+ * @return the ServletContext associated with this runtime
+ */
+ ServletContext getServletContext();
+
+ /**
+ * Sets the ServletContext associated with this runtime.
+ *
+ * @param servletContext the ServletContext associated with this runtime
+ */
+ void setServletContext(ServletContext servletContext);
+
+ /**
+ * Returns the location of the SCDL used to boot this runtime.
+ *
+ * @return the location of the SCDL used to boot this runtime
+ */
+ URL getSystemScdl();
+
+ /**
+ * Sets the location of the SCDL used to boot this runtime.
+ *
+ * @param systemScdl the location of the SCDL used to boot this runtime
+ */
+ void setSystemScdl(URL systemScdl);
+
+ /**
+ * Returns the location of the default application's SCDL.
+ *
+ * @return the location of the default application's SCDL
+ */
+ URL getApplicationScdl();
+
+ /**
+ * Sets the location of the default application's SCDL
+ *
+ * @param applicationScdl the location of the default application's SCDL
+ */
+ void setApplicationScdl(URL applicationScdl);
+
+ /**
+ * Returns the web application's ClassLoader.
+ *
+ * @return the web application's ClassLoader
+ */
+ ClassLoader getWebappClassLoader();
+
+ /**
+ * Sets the web application's ClassLoader.
+ *
+ * @param webappClassLoader the web application's ClassLoader
+ */
+ void setWebappClassLoader(ClassLoader webappClassLoader);
+
/**
* Initialize a runtime for the supplied servlet context.
*
- * @param context the servlet context the runtime should run in
*/
- void initialize(ServletContext context);
+ void initialize();
/**
* Destroy the runtime.
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
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/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java?view=auto&rev=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
(added)
+++
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Sun Sep 10 08:48:29 2006
@@ -0,0 +1,173 @@
+/*
+ * 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.net.URL;
+import java.net.MalformedURLException;
+import java.lang.reflect.Method;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.*;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyContextListenerTestCase extends TestCase {
+ private ServletContext context;
+ private TuscanyContextListener listener;
+ private ClassLoader cl;
+ private URL systemUrl;
+ private URL applicationUrl;
+ private Method getRuntimeMethod;
+
+ public void testInitializationUsingDefaults() throws Exception {
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ listener = createMock(TuscanyContextListener.class, new
Method[]{getRuntimeMethod});
+ try {
+ Thread.currentThread().setContextClassLoader(cl);
+ ServletContextEvent event = createMock(ServletContextEvent.class);
+ WebappRuntime runtime = createMock(WebappRuntime.class);
+ expect(event.getServletContext()).andReturn(context);
+ replay(event);
+
expect(context.getInitParameter("tuscany.bootDir")).andReturn(null);
+
expect(context.getResourcePaths("/WEB-INF/tuscany/boot")).andReturn(null);
+
expect(context.getInitParameter("tuscany.systemScdlPath")).andReturn(null);
+
expect(context.getInitParameter("tuscany.applicationScdlPath")).andReturn(null);
+
expect(context.getResource("/WEB-INF/default.scdl")).andReturn(applicationUrl);
+ replay(context);
+
expect(cl.getResource("META-INF/tuscany/webapp.scdl")).andReturn(systemUrl);
+ replay(cl);
+ expect(listener.getRuntime(context, cl)).andReturn(runtime);
+ replay(listener);
+ runtime.setServletContext(context);
+ runtime.setWebappClassLoader(cl);
+ runtime.setSystemScdl(systemUrl);
+ runtime.setApplicationScdl(applicationUrl);
+ runtime.initialize();
+ replay(runtime);
+ listener.contextInitialized(event);
+ verify(event);
+ verify(context);
+ verify(listener);
+ verify(cl);
+ verify(runtime);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+ }
+
+ public void testGetInitParameterWhenSpecified() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn(value);
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(context, name,
"default"));
+ verify(context);
+ }
+
+ public void testGetInitParameterUsingDefault() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn(null);
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(context, name, value));
+ verify(context);
+ }
+
+ public void testGetInitParameterWithZeroLength() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn("");
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(context, name, value));
+ verify(context);
+ }
+
+ public void testGetScdlFromWebapp() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andReturn(systemUrl);
+ replay(context);
+ replay(cl);
+ assertSame(systemUrl, listener.getScdlURL(path, context, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromWebappMissing() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andReturn(null);
+ replay(context);
+ replay(cl);
+ assertNull(listener.getScdlURL(path, context, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromWebappMalformed() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andThrow(new
MalformedURLException());
+ replay(context);
+ replay(cl);
+ try {
+ listener.getScdlURL(path, context, cl);
+ fail();
+ } catch (MalformedURLException e) {
+ // OK
+ }
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromClasspath() throws MalformedURLException {
+ String path = "META-INF/test";
+ replay(context);
+ expect(cl.getResource(path)).andReturn(systemUrl);
+ replay(cl);
+ assertSame(systemUrl, listener.getScdlURL(path, context, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromClasspathMissing() throws MalformedURLException
{
+ String path = "META-INF/test";
+ replay(context);
+ expect(cl.getResource(path)).andReturn(null);
+ replay(cl);
+ assertNull(listener.getScdlURL(path, context, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ getRuntimeMethod =
TuscanyContextListener.class.getDeclaredMethod("getRuntime",
+
ServletContext.class,
+
ClassLoader.class);
+ listener = new TuscanyContextListener();
+ context = createMock(ServletContext.class);
+ cl = createMock(ClassLoader.class);
+ systemUrl = new URL("file:/system.scdl");
+ applicationUrl = new URL("file:/application.scdl");
+ }
+}
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
Sun Sep 10 08:48:29 2006
@@ -47,7 +47,7 @@
sca.start();
sca.stop();
EasyMock.replay(sca);
- TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+ WebappRuntime runtime = createMock(WebappRuntime.class);
expect(runtime.getContext()).andReturn(sca);
runtime.startRequest();
runtime.stopRequest();
@@ -73,7 +73,7 @@
sca.start();
sca.stop();
EasyMock.replay(sca);
- TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+ WebappRuntime runtime = createMock(WebappRuntime.class);
runtime.startRequest();
runtime.stopRequest();
expect(runtime.getContext()).andReturn(sca);
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
Sun Sep 10 08:48:29 2006
@@ -48,7 +48,7 @@
ServletRequestInjector injector =
createMock(ServletRequestInjector.class);
injector.service(eq(req), eq(resp));
EasyMock.replay(injector);
- TuscanyWebappRuntime runtime = createMock(TuscanyWebappRuntime.class);
+ WebappRuntime runtime = createMock(WebappRuntime.class);
expect(runtime.getRequestInjector()).andReturn(injector);
replay(runtime);
ServletContext context = createNiceMock(ServletContext.class);
Modified:
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java?view=diff&rev=441961&r1=441960&r2=441961
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
Sun Sep 10 08:48:29 2006
@@ -17,7 +17,7 @@
public class TuscanySessionListenerTestCase extends TestCase {
public void testSessionPropagated() throws Exception {
- TuscanyWebappRuntime runtime =
EasyMock.createNiceMock(TuscanyWebappRuntime.class);
+ WebappRuntime runtime = EasyMock.createNiceMock(WebappRuntime.class);
runtime.sessionCreated(EasyMock.isA(HttpSessionEvent.class));
runtime.sessionDestroyed(EasyMock.isA(HttpSessionEvent.class));
EasyMock.replay(runtime);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]