You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/02/16 18:42:17 UTC
svn commit: r508518 - in /incubator/tuscany/java/sca/runtime/webapp:
webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/
webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/
webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ we...
Author: jboynes
Date: Fri Feb 16 09:42:15 2007
New Revision: 508518
URL: http://svn.apache.org/viewvc?view=rev&rev=508518
Log:
partial webapp runtime impl
Modified:
incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java Fri Feb 16 09:42:15 2007
@@ -10,17 +10,32 @@
/**
* Name of the servlet context-param that should contain the component id for the webapp.
*/
- static final String COMPONENT_PARAM = "tuscany.component";
+ public static final String COMPOSITE_PARAM = "tuscany.composite";
+
+ /**
+ * Name of the servlet context-param that should contain the component id for the webapp.
+ */
+ public static final String COMPONENT_PARAM = "tuscany.component";
+
+ /**
+ * Servlet context-param name for user-specified application SCDL path.
+ */
+ static final String APPLICATION_SCDL_PATH_PARAM = "tuscany.applicationScdlPath";
+
+ /**
+ * Default application SCDL path.
+ */
+ public static final String APPLICATION_SCDL_PATH_DEFAULT = "/WEB-INF/default.scdl";
/**
* Servlet context-param name for setting if the runtime is online.
*/
- static final String ONLINE_PARAM = "tuscany.online";
+ public static final String ONLINE_PARAM = "tuscany.online";
/**
* Name of the context attribute that contains the ComponentContext.
*/
- static final String CONTEXT_ATTRIBUTE = "tuscany.context";
+ public static final String CONTEXT_ATTRIBUTE = "tuscany.context";
/**
* Name of the parameter that defines the name of webapp resource containing bootstrap jars.
@@ -51,16 +66,6 @@
* 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 = "tuscany.applicationScdlPath";
-
- /**
- * Default application SCDL path.
- */
- static final String APPLICATION_SCDL_PATH_DEFAULT = "/WEB-INF/default.scdl";
/**
* Context attribute to which the Tuscany runtime for this servlet context is stored.
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java Fri Feb 16 09:42:15 2007
@@ -26,9 +26,12 @@
import org.apache.tuscany.api.TuscanyRuntimeException;
import org.apache.tuscany.host.runtime.ShutdownException;
+import static org.apache.tuscany.runtime.webapp.Constants.COMPOSITE_PARAM;
import static org.apache.tuscany.runtime.webapp.Constants.COMPONENT_PARAM;
import static org.apache.tuscany.runtime.webapp.Constants.ONLINE_PARAM;
import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
/**
* Launches a Tuscany runtime in a web application, loading information from servlet context parameters. This listener
@@ -52,16 +55,22 @@
public class TuscanyContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
+ ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
ServletContext servletContext = event.getServletContext();
WebappUtil utils = getUtils(servletContext);
try {
- ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader bootClassLoader = utils.getBootClassLoader(webappClassLoader);
+ // FIXME work this out from the servlet context
+ String defaultComposite = "http://locahost/sca/";
+ URI compositeId = new URI(utils.getInitParameter(COMPOSITE_PARAM, defaultComposite));
+ URI componentId = new URI(utils.getInitParameter(COMPONENT_PARAM, "webapp"));
+ String scdlPath = utils.getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
+ URL scdl = servletContext.getResource(scdlPath);
+
boolean online = Boolean.valueOf(utils.getInitParameter(ONLINE_PARAM, "true"));
- URI componentId = new URI(servletContext.getInitParameter(COMPONENT_PARAM));
WebappRuntimeInfo info = new WebappRuntimeInfoImpl(servletContext,
servletContext.getResource("/WEB-INF/tuscany/"),
online);
+ ClassLoader bootClassLoader = utils.getBootClassLoader(webappClassLoader);
URL systemScdl = utils.getSystemScdl(bootClassLoader);
WebappRuntime runtime = utils.getRuntime(bootClassLoader);
@@ -72,7 +81,7 @@
runtime.initialize();
servletContext.setAttribute(RUNTIME_ATTRIBUTE, runtime);
- runtime.bindComponent(componentId);
+ runtime.deploy(compositeId, scdl, componentId);
} catch (TuscanyRuntimeException e) {
servletContext.log(e.getMessage(), e);
e.printStackTrace();
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java Fri Feb 16 09:42:15 2007
@@ -53,14 +53,8 @@
void setServletContext(ServletContext servletContext);
/**
- * Bind the parameters, references and context for a component to the ServletContext.
- *
- * @param componentId the id of the component to bind
- */
- void bindComponent(URI componentId);
-
- /**
* Returns the request injector for the runtime
+ * @return the runtime's request injector
*/
ServletRequestInjector getRequestInjector();
@@ -75,21 +69,25 @@
void stopRequest();
/**
- * Request has been started for the given request
+ * Request has been started for the given request.
+ * @param request the servlet request
*/
void httpRequestStarted(HttpServletRequest request);
/**
- * Request has been ended with the given session id
+ * Request has been ended with the given session id.
+ * @param id the session id
*/
void httpRequestEnded(Object id);
/**
* Temporary method for deploying SCDL supplied with an application to the runtime.
*
- * @param componentID the id of the component that the supplied SCDL should implement
+ * @param compositeId the id of the component that the supplied SCDL should implement
* @param applicationScdl the location of an application composite
+ * @param componentId the id of the component that should be bound to the webapp
+ * @throws InitializationException if there was a problem initializing the composite
*/
@Deprecated
- void deploy(URI componentID, URL applicationScdl) throws InitializationException;
+ void deploy(URI compositeId, URL applicationScdl, URI componentId) throws InitializationException;
}
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java Fri Feb 16 09:42:15 2007
@@ -32,17 +32,21 @@
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+
/**
* @version $Rev$ $Date$
*/
public class TuscanyContextListenerTestCase extends TestCase {
+ private String contextName;
private ServletContext context;
private TuscanyContextListener listener;
private ClassLoader cl;
private ClassLoader bootClassLoader;
private URL systemUrl;
+ private URL scdl;
private WebappUtil utils;
- private URI componentId;
public void testInitializationUsingDefaults() throws Exception {
ServletContextEvent event = createMock(ServletContextEvent.class);
@@ -51,13 +55,17 @@
WebappRuntime runtime = createMock(WebappRuntime.class);
expect(utils.getBootClassLoader(cl)).andReturn(bootClassLoader);
+ expect(utils.getInitParameter("tuscany.composite", "http://locahost/sca/")).andReturn("http://locahost/sca/");
+ expect(utils.getInitParameter("tuscany.component", contextName)).andReturn(contextName);
expect(utils.getInitParameter("tuscany.online", "true")).andReturn("true");
+ expect(utils.getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT))
+ .andReturn(APPLICATION_SCDL_PATH_DEFAULT);
expect(utils.getRuntime(bootClassLoader)).andReturn(runtime);
expect(utils.getSystemScdl(bootClassLoader)).andReturn(systemUrl);
replay(utils);
expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null);
- expect(context.getInitParameter("tuscany.component")).andReturn(componentId.toString());
+ expect(context.getResource(APPLICATION_SCDL_PATH_DEFAULT)).andReturn(scdl);
context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE), isA(WebappRuntime.class));
replay(context);
replay(cl);
@@ -69,7 +77,7 @@
runtime.setHostClassLoader(cl);
runtime.setSystemScdl(systemUrl);
runtime.initialize();
- runtime.bindComponent(componentId);
+ runtime.deploy(URI.create("http://locahost/sca/"), scdl, URI.create(contextName));
replay(runtime);
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
@@ -97,6 +105,7 @@
cl = createMock(ClassLoader.class);
bootClassLoader = createMock(ClassLoader.class);
systemUrl = new URL("file:/system.scdl");
- componentId = URI.create("http://example.com/aComponent");
+ scdl = new URL("file:/app.scdl");
+ contextName = "webapp";
}
}
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java Fri Feb 16 09:42:15 2007
@@ -34,6 +34,7 @@
import org.apache.tuscany.spi.component.Component;
import org.apache.tuscany.spi.component.ComponentException;
import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.loader.LoaderException;
import org.apache.tuscany.spi.model.ComponentDefinition;
import org.apache.tuscany.spi.model.CompositeImplementation;
@@ -118,16 +119,16 @@
*/
@Deprecated
- public void deploy(URI componentID, URL applicationScdl) throws InitializationException {
+ public void deploy(URI compositeId, URL applicationScdl, URI componentId) throws InitializationException {
CompositeImplementation impl = new CompositeImplementation();
impl.setScdlLocation(applicationScdl);
impl.setClassLoader(getHostClassLoader());
ComponentDefinition<CompositeImplementation> definition =
- new ComponentDefinition<CompositeImplementation>(componentID, impl);
+ new ComponentDefinition<CompositeImplementation>(compositeId, impl);
+ CompositeComponent composite;
try {
- Component component = getDeployer().deploy(null, definition);
- component.start();
+ composite = (CompositeComponent) getDeployer().deploy(null, definition);
} catch (LoaderException e) {
throw new InitializationException(e);
} catch (BuilderException e) {
@@ -137,9 +138,9 @@
} catch (ResolutionException e) {
throw new InitializationException(e);
}
- }
+ composite.start();
- public void bindComponent(URI componentId) {
+ componentId = compositeId.resolve(componentId);
Component component = getComponentManager().getComponent(componentId);
if (component == null) {
throw new TuscanyInitException("No component found with id " + componentId, componentId.toString());
Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl?view=diff&rev=508518&r1=508517&r2=508518
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl Fri Feb 16 09:42:15 2007
@@ -46,16 +46,6 @@
<system:implementation.system class="org.apache.tuscany.core.component.scope.ScopeRegistryImpl"/>
</component>
- <!-- Store infrastructure -->
- <component name="store">
- <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
- </component>
-
- <!-- Resource host registry -->
- <component name="resourceHostRegistry">
- <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
- </component>
-
<!-- Builder and BuilderRegistry -->
<component name="builder">
<system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
@@ -80,6 +70,11 @@
<system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
</component>
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
<!-- Default scopes -->
<component name="scope.module">
<system:implementation.system class="org.apache.tuscany.core.component.scope.CompositeScopeObjectFactory"/>
@@ -144,6 +139,11 @@
<component name="propertyFactory">
<system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
</component>
<component name="artifactRepository">
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org