Author: jboynes
Date: Thu Sep 28 00:09:18 2006
New Revision: 450722
URL: http://svn.apache.org/viewvc?view=rev&rev=450722
Log:
clean up webapp bootstrap code
move extension deployment into a service component
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
(with props)
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
(with props)
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/services/
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
(with props)
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
(with props)
Modified:
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java?view=auto&rev=450722
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
Thu Sep 28 00:09:18 2006
@@ -0,0 +1,115 @@
+/*
+ * 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.core.runtime;
+
+import java.net.URL;
+
+import
org.apache.tuscany.core.implementation.system.component.SystemCompositeComponent;
+import
org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractRuntime implements TuscanyRuntime {
+ private URL systemScdl;
+ private String applicationName;
+ private URL applicationScdl;
+ private ClassLoader hostClassLoader;
+ private RuntimeInfo runtimeInfo;
+
+ public URL getSystemScdl() {
+ return systemScdl;
+ }
+
+ public void setSystemScdl(URL systemScdl) {
+ this.systemScdl = systemScdl;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public URL getApplicationScdl() {
+ return applicationScdl;
+ }
+
+ public void setApplicationScdl(URL applicationScdl) {
+ this.applicationScdl = applicationScdl;
+ }
+
+ public ClassLoader getHostClassLoader() {
+ return hostClassLoader;
+ }
+
+ public void setHostClassLoader(ClassLoader hostClassLoader) {
+ this.hostClassLoader = hostClassLoader;
+ }
+
+ public RuntimeInfo getRuntimeInfo() {
+ return runtimeInfo;
+ }
+
+ public void setRuntimeInfo(RuntimeInfo runtimeInfo) {
+ this.runtimeInfo = runtimeInfo;
+ }
+
+ protected SystemCompositeComponent deploySystemScdl(Deployer deployer,
+
SystemCompositeComponent parent,
+ String name,
+ URL systemScdl,
+ ClassLoader
systemClassLoader)
+ throws LoaderException {
+
+ SystemCompositeImplementation impl = new
SystemCompositeImplementation();
+ impl.setScdlLocation(systemScdl);
+ impl.setClassLoader(systemClassLoader);
+ ComponentDefinition<SystemCompositeImplementation> definition =
+ new ComponentDefinition<SystemCompositeImplementation>(name, impl);
+
+ return (SystemCompositeComponent) deployer.deploy(parent, definition);
+ }
+
+ protected CompositeComponent deployApplicationScdl(Deployer deployer,
+ CompositeComponent
parent,
+ String name,
+ URL applicationScdl,
+ ClassLoader
applicationClassLoader)
+ throws LoaderException {
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(applicationScdl);
+ impl.setClassLoader(applicationClassLoader);
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(name, impl);
+
+ return (CompositeComponent) deployer.deploy(parent, definition);
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java?view=diff&rev=450722&r1=450721&r2=450722
==============================================================================
---
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java
(original)
+++
incubator/tuscany/java/sca/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java
Thu Sep 28 00:09:18 2006
@@ -41,6 +41,18 @@
void setSystemScdl(URL systemScdl);
/**
+ * Returns the name of the component associated with the application SCDL.
+ * @return the name of the component associated with the application SCDL
+ */
+ String getApplicationName();
+
+ /**
+ * Sets the name of the component associated with the application SCDL.
+ * @param applicationName the name of the component associated with the
application SCDL
+ */
+ void setApplicationName(String applicationName);
+
+ /**
* Returns the location of the default application's SCDL.
*
* @return the location of the default application's SCDL
@@ -78,7 +90,7 @@
/**
* Sets the info this runtime should make available to service components.
* The instance supplied here should be registered in the system composite
with the name
- * [EMAIL PROTECTED] RuntimeInfo#COMPONENT_NAME "RuntimeInfo"}.
+ * [EMAIL PROTECTED] RuntimeInfo#COMPONENT_NAME "RuntimeInfo"}.
*
* @param runtimeInfo the information this runtime should make available
to service components
*/
Added:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java?view=auto&rev=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
(added)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
Thu Sep 28 00:09:18 2006
@@ -0,0 +1,86 @@
+/*
+ * 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.util.Set;
+
+import javax.servlet.ServletContext;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.core.services.extension.AbstractExtensionDeployer;
+import org.apache.tuscany.runtime.webapp.WebappRuntimeInfo;
+import org.apache.tuscany.spi.annotation.Autowire;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebResourceScanExtender extends AbstractExtensionDeployer {
+ private final WebappRuntimeInfo runtimeInfo;
+ private final String path;
+
+ public WebResourceScanExtender(@Autowire WebappRuntimeInfo runtimeInfo,
+ @Property(name = "path") String path) {
+ this.runtimeInfo = runtimeInfo;
+ this.path = path;
+ }
+
+ @Init
+ public void init() {
+ System.out.println("Looking for extensions");
+
+ ServletContext servletContext = runtimeInfo.getServletContext();
+ Set extensions = servletContext.getResourcePaths(path);
+ if (extensions == null || extensions.isEmpty()) {
+ // no extensions in this webapp
+ return;
+ }
+
+ for (Object e : extensions) {
+ String extensionPath = (String) e;
+ URL extension;
+ try {
+ extension = servletContext.getResource(extensionPath);
+ } catch (MalformedURLException e1) {
+ // web container should return an invalid URL for a path it
gave us
+ throw new AssertionError();
+ }
+
+ String name = extensionPath.substring(path.length());
+ if (name.charAt(name.length() - 1) == '/') {
+ // TODO support exploded extensions
+ continue;
+ }
+ if (name.charAt(0) == '.') {
+ // hidden file
+ continue;
+ }
+
+ int lastDot = name.lastIndexOf('.');
+ if (lastDot != -1) {
+ name = name.substring(0, lastDot);
+ }
+ System.out.println("extension = " + extension);
+ deployExtension(name, extension);
+ }
+ }
+}
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.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=450722&r1=450721&r2=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
Thu Sep 28 00:09:18 2006
@@ -18,41 +18,33 @@
*/
package org.apache.tuscany.runtime.webapp;
-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.http.HttpSessionEvent;
+import javax.xml.stream.XMLInputFactory;
import org.osoa.sca.SCA;
+import org.apache.tuscany.core.bootstrap.Bootstrapper;
+import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
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.implementation.system.component.SystemCompositeComponent;
import org.apache.tuscany.core.launcher.CompositeContextImpl;
-import org.apache.tuscany.core.launcher.LauncherImpl;
import org.apache.tuscany.core.monitor.MonitorFactoryUtil;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
import org.apache.tuscany.host.MonitorFactory;
import org.apache.tuscany.host.RuntimeInfo;
import org.apache.tuscany.host.servlet.ServletRequestInjector;
-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 org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.bootstrap.ComponentNames;
+import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
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
@@ -71,19 +63,18 @@
* @version $$Rev$$ $$Date$$
*/
-public class WebappRuntimeImpl implements WebappRuntime {
+public class WebappRuntimeImpl extends AbstractRuntime implements
WebappRuntime {
private ServletContext servletContext;
- private URL systemScdl;
- private URL applicationScdl;
- private ClassLoader webappClassLoader;
- private RuntimeInfo runtimeInfo;
- private CompositeComponent component;
private ServletLauncherMonitor monitor;
- private LauncherImpl launcher;
private CompositeContextImpl context;
private ServletRequestInjector requestInjector;
+ private RuntimeComponent runtime;
+ private SystemCompositeComponent systemComponent;
+ private SystemCompositeComponent tuscanySystem;
+ private CompositeComponent application;
+
public ServletContext getServletContext() {
return servletContext;
}
@@ -92,99 +83,76 @@
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 getHostClassLoader() {
- return webappClassLoader;
- }
-
- public void setHostClassLoader(ClassLoader webappClassLoader) {
- this.webappClassLoader = webappClassLoader;
- }
-
- public RuntimeInfo getRuntimeInfo() {
- return runtimeInfo;
- }
-
- public void setRuntimeInfo(RuntimeInfo runtimeInfo) {
- this.runtimeInfo = runtimeInfo;
- }
-
public void initialize() {
+ ClassLoader bootClassLoader = getClass().getClassLoader();
+
// 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();
- launcher.setApplicationLoader(webappClassLoader);
+ XMLInputFactory xmlFactory =
XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory",
bootClassLoader);
- try {
- CompositeComponent rt = launcher.bootRuntime(systemScdl, mf);
+ Bootstrapper bootstrapper = new DefaultBootstrapper(mf, xmlFactory);
+ runtime = bootstrapper.createRuntime();
+ runtime.start();
+ systemComponent = (SystemCompositeComponent)
runtime.getSystemComponent();
+
+ // register the runtime info provided by the host
+ systemComponent.registerJavaObject(RuntimeInfo.COMPONENT_NAME,
+ WebappRuntimeInfo.class,
+ (WebappRuntimeInfo)
getRuntimeInfo());
- // 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;
- }
+ // register the monitor factory provided by the host
+ systemComponent.registerJavaObject("MonitorFactory",
MonitorFactory.class, mf);
- // load extensions
- Set<String> paths =
servletContext.getResourcePaths(extensionScdlPath);
- if (paths != null) {
- for (String path : paths) {
- if (path != null && path.endsWith(".scdl")) {
//getResourePaths even includes sub-directory names. Only look at scdl files.
- 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();
-
- String name = servletContext.getServletContextName();
- if (name == null) {
- name = "application";
- }
-
- CompositeComponent root = launcher.bootApplication(name,
applicationScdl);
- 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);
+ systemComponent.start();
+
+ try {
+ // deploy the system scdl
+ Deployer deployer = bootstrapper.createDeployer();
+ tuscanySystem = deploySystemScdl(deployer,
+ systemComponent,
+ ComponentNames.TUSCANY_SYSTEM,
+ getSystemScdl(),
+ bootClassLoader);
+ tuscanySystem.start();
+
+ requestInjector = (ServletRequestInjector)
tuscanySystem.getChild("servletHost").getServiceInstance();
+
+ // switch to the system deployer
+ deployer = (Deployer)
tuscanySystem.getChild("deployer").getServiceInstance();
+
+ application = deployApplicationScdl(deployer,
+ runtime.getRootComponent(),
+ getApplicationName(),
+ getApplicationScdl(),
+ getHostClassLoader());
+ application.start();
+ context = new CompositeContextImpl(application);
} catch (Exception e) {
throw new ServletLauncherInitException(e);
}
}
public void destroy() {
- if (launcher != null) {
- launcher.shutdownRuntime();
+ context = null;
+ if (application != null) {
+ application.stop();
+ application = null;
+ }
+ if (tuscanySystem != null) {
+ tuscanySystem.stop();
+ tuscanySystem = null;
+ }
+ if (systemComponent != null) {
+ systemComponent.stop();
+ systemComponent = null;
+ }
+ if (runtime != null) {
+ runtime.stop();
+ runtime = null;
}
}
@@ -197,45 +165,19 @@
}
public void sessionCreated(HttpSessionEvent event) {
- component.publish(new HttpSessionStart(this,
event.getSession().getId()));
+ application.publish(new HttpSessionStart(this,
event.getSession().getId()));
}
public void sessionDestroyed(HttpSessionEvent event) {
- component.publish(new HttpSessionEnd(this,
event.getSession().getId()));
+ application.publish(new HttpSessionEnd(this,
event.getSession().getId()));
}
public void startRequest() {
- component.publish(new RequestStart(this));
+ application.publish(new RequestStart(this));
}
public void stopRequest() {
- component.publish(new RequestEnd(this));
- }
-
-
- /**
- * 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();
+ application.publish(new RequestEnd(this));
}
/**
@@ -260,34 +202,5 @@
}
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;
- }
}
}
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl?view=diff&rev=450722&r1=450721&r2=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
Thu Sep 28 00:09:18 2006
@@ -81,7 +81,7 @@
<component name="scope.httpsession">
<system:implementation.system
class="org.apache.tuscany.core.component.scope.HttpSessionScopeObjectFactory"/>
</component>
-
+
<!-- include loader configuration -->
<include name="org.apache.tuscany.launcher.Loader"
scdlResource="org/apache/tuscany/core/loader.scdl"/>
@@ -113,14 +113,14 @@
<component name="workScheduler">
<system:implementation.system
class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
</component>
-
+
<!-- Web app ServletHost -->
<component name="servletHost">
<system:implementation.system
class="org.apache.tuscany.runtime.webapp.ServletHostImpl"/>
</component>
<component name="policyBuilderRegistry">
- <system:implementation.system
class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ <system:implementation.system
class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
</component>
<component name="propertyFactory">
@@ -128,16 +128,13 @@
</component>
<component name="artifactRepository">
- <system:implementation.system
class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
- <!-- this value needs to change to a correct one -->
- <property name = "repository">.</property>
+ <system:implementation.system
class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <!-- this value needs to change to a correct one -->
+ <property name="repository">.</property>
</component>
-
- <!-- TODO: Hack the Axis extension in -->
- <!--<include name="binding.axis2" scdlLocation="binding.axis2.scdl"/> -->
-
- <!-- TODO: Hack the SDO DataBinding extension in -->
- <!-- <include name="databinding.sdo" scdlLocation="databinding.sdo.scdl"/>
-->
-
+ <component name="extender" initLevel="90">
+ <system:implementation.system
class="org.apache.tuscany.runtime.webapp.WebResourceScanExtender"/>
+ <property name="path">/WEB-INF/tuscany/extensions/</property>
+ </component>
</composite>
Modified:
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.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=450722&r1=450721&r2=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
Thu Sep 28 00:09:18 2006
@@ -43,11 +43,7 @@
*/
public void testBootWithDefaults() throws Exception {
expect(context.getInitParameter(Constants.SYSTEM_MONITORING_PARAM)).andReturn(null);
-
expect(context.getInitParameter(Constants.EXTENSION_SCDL_PATH_PARAM)).andReturn(null);
-
expect(context.getResourcePaths("/WEB-INF/tuscany/extensions")).andReturn(null);
- expect(context.getServletContextName()).andReturn("foo");
-
expect(context.getInitParameter(Constants.CURRENT_COMPOSITE_PATH_PARAM)).andReturn(null);
- context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE),
isA(WebappRuntime.class));
+
expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null);
replay(context);
runtime.initialize();
verify(context);
@@ -60,9 +56,11 @@
context = createMock(ServletContext.class);
runtime = new WebappRuntimeImpl();
+ runtime.setRuntimeInfo(new WebappRuntimeInfoImpl(context, null));
runtime.setHostClassLoader(getClass().getClassLoader());
runtime.setServletContext(context);
runtime.setSystemScdl(systemScdl);
+ runtime.setApplicationName("foo");
runtime.setApplicationScdl(applicationScdl);
}
}
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=450722&r1=450721&r2=450722
==============================================================================
---
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
Thu Sep 28 00:09:18 2006
@@ -31,6 +31,7 @@
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_ATTRIBUTE;
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;
@@ -57,32 +58,45 @@
*/
public class TuscanyContextListener implements ServletContextListener {
- private WebappRuntime runtime;
-
public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
try {
ClassLoader webappClassLoader =
Thread.currentThread().getContextClassLoader();
ClassLoader bootClassLoader = getBootClassLoader(servletContext,
webappClassLoader);
- runtime = getRuntime(servletContext, bootClassLoader);
+ WebappRuntime runtime = getRuntime(servletContext,
bootClassLoader);
+ WebappRuntimeInfo info = new WebappRuntimeInfoImpl(servletContext,
+
servletContext.getResource("/WEB-INF/tuscany/"));
URL systemScdl = getSystemScdl(servletContext, bootClassLoader);
URL applicationScdl = getApplicationScdl(servletContext,
webappClassLoader);
+ String name = getApplicationName(servletContext);
runtime.setServletContext(servletContext);
+ runtime.setRuntimeInfo(info);
runtime.setHostClassLoader(webappClassLoader);
runtime.setSystemScdl(systemScdl);
+ runtime.setApplicationName(name);
runtime.setApplicationScdl(applicationScdl);
runtime.initialize();
+
+ servletContext.setAttribute(RUNTIME_ATTRIBUTE, runtime);
} catch (TuscanyRuntimeException e) {
servletContext.log(e.getMessage(), e);
throw e;
+ } catch (MalformedURLException e) {
+ servletContext.log(e.getMessage(), e);
+ throw new RuntimeException(e);
}
}
public void contextDestroyed(ServletContextEvent event) {
- if (runtime != null) {
- runtime.destroy();
+ ServletContext servletContext = event.getServletContext();
+ WebappRuntime runtime = (WebappRuntime)
servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ return;
}
+
+ servletContext.removeAttribute(RUNTIME_ATTRIBUTE);
+ runtime.destroy();
}
/**
@@ -133,6 +147,14 @@
} catch (MalformedURLException e) {
throw new TuscanyInitException("Invalid resource path for " +
SYSTEM_SCDL_PATH_PARAM + " : " + path, e);
}
+ }
+
+ protected String getApplicationName(ServletContext servletContext) {
+ String name = servletContext.getServletContextName();
+ if (name == null) {
+ name = "application";
+ }
+ return name;
}
protected URL getApplicationScdl(ServletContext servletContext,
ClassLoader bootClassLoader) {
Added:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java?view=auto&rev=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
(added)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
Thu Sep 28 00:09:18 2006
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface WebappRuntimeInfo extends RuntimeInfo {
+ /**
+ * Returns the ServletContext associated with this webapp runtime.
+ *
+ * @return the ServletContext associated with this webapp runtime.
+ */
+ ServletContext getServletContext();
+}
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java?view=auto&rev=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
(added)
+++
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
Thu Sep 28 00:09:18 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 java.io.File;
+import java.net.URL;
+import javax.servlet.ServletContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappRuntimeInfoImpl implements WebappRuntimeInfo {
+ private final ServletContext servletContext;
+ private final URL baseURL;
+
+ public WebappRuntimeInfoImpl(ServletContext servletContext, URL baseURL) {
+ this.servletContext = servletContext;
+ this.baseURL = baseURL;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public URL getBaseURL() {
+ return baseURL;
+ }
+
+ public File getInstallDirectory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public File getApplicationRootDirectory() {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
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=diff&rev=450722&r1=450721&r2=450722
==============================================================================
---
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
(original)
+++
incubator/tuscany/java/sca/runtime/webapp/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
Thu Sep 28 00:09:18 2006
@@ -49,17 +49,22 @@
replay(event);
expect(context.getInitParameter("tuscany.bootDir")).andReturn(null);
expect(context.getResourcePaths("/WEB-INF/tuscany/boot")).andReturn(null);
+ expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null);
expect(context.getInitParameter("tuscany.systemScdlPath")).andReturn(null);
+ expect(context.getServletContextName()).andReturn(null);
expect(context.getInitParameter("tuscany.applicationScdlPath")).andReturn(null);
expect(context.getResource("/WEB-INF/default.scdl")).andReturn(applicationUrl);
+ context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE),
isA(WebappRuntime.class));
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.setRuntimeInfo(isA(WebappRuntimeInfo.class));
runtime.setHostClassLoader(cl);
runtime.setSystemScdl(systemUrl);
+ runtime.setApplicationName("application");
runtime.setApplicationScdl(applicationUrl);
runtime.initialize();
replay(runtime);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]