summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp')
-rw-r--r--tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ContextBinder.java39
-rw-r--r--tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/LazyHTTPSessionId.java56
-rw-r--r--tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ServletHost.java58
-rw-r--r--tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyRequestFilter.java96
-rw-r--r--tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java129
5 files changed, 0 insertions, 378 deletions
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ContextBinder.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ContextBinder.java
deleted file mode 100644
index 70b40e7269..0000000000
--- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ContextBinder.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.core.webapp;
-
-import org.osoa.sca.ModuleContext;
-import org.osoa.sca.SCA;
-
-/**
- * @version $Rev$ $Date$
- */
-class ContextBinder extends SCA {
- static final ContextBinder BINDER = new ContextBinder();
-
- public void setContext(ModuleContext context) {
- setModuleContext(context);
- }
-
- public void start() {
- throw new AssertionError();
- }
-
- public void stop() {
- throw new AssertionError();
- }
-}
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/LazyHTTPSessionId.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/LazyHTTPSessionId.java
deleted file mode 100644
index c9e69eaa82..0000000000
--- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/LazyHTTPSessionId.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.core.webapp;
-
-import org.apache.tuscany.core.context.ScopeIdentifier;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * Implements a <code>ScopeIdentifier</code> for a Servlet-based transport.
- * Wraps an <code>HttpServletRequest</code> so that the session id associated
- * with the current request may be lazily retrieved by the module context - i.e.
- * if a session context or session-scoped component is not accessed, no session
- * is created.
- *
- * @version $Rev$ $Date$
- */
-public class LazyHTTPSessionId implements ScopeIdentifier {
-
- private HttpServletRequest request;
-
- //----------------------------------
- // Constructors
- //----------------------------------
-
- public LazyHTTPSessionId(HttpServletRequest request) {
- this.request = request;
- }
-
- //----------------------------------
- // Methods
- //----------------------------------
-
- /**
- * Returns the session identifier
- *
- * @see org.apache.tuscany.core.context.ScopeIdentifier#getIdentifier()
- */
- public Object getIdentifier() {
- return request.getSession(true);
- }
-}
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ServletHost.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ServletHost.java
deleted file mode 100644
index 85a4a180c5..0000000000
--- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/ServletHost.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- *
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.core.webapp;
-
-import javax.servlet.Servlet;
-
-/**
- * Service interface implemented by host environments that allow Servlets
- * to be registered.
- * <p/>
- * This interface allows an SCA system component to register a servlet to handle
- * inbound requests.
- *
- * @version $Rev$ $Date$
- */
-public interface ServletHost {
- /**
- * Register a mapping for an instance of a Servlet.
- * This requests that the servlet container direct all requests to the
- * designated mapping to the supplied Servlet instance.
- *
- * @param mapping the uri-mapping for the Servlet
- * @param servlet the Servlet that should be invoked
- */
- void registerMapping(String mapping, Servlet servlet);
-
- /**
- * Unregister a servlet mapping.
- * This directs the servlet contain not to direct any more requests to
- * a previously registered Servlet.
- *
- * @param mapping the uri-mapping for the Servlet
- */
- void unregisterMapping(String mapping);
-
- /**
- * Get the servlet instance registered for the mapping.
- *
- * @param mapping the uri-mapping for the Servlet
- * @return the Servelt for the mapping or null if there is no Servlet registered for the mapping
- */
- @Deprecated
- Servlet getMapping(String mapping);
-}
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyRequestFilter.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyRequestFilter.java
deleted file mode 100644
index 6637448204..0000000000
--- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyRequestFilter.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.core.webapp;
-
-import org.apache.tuscany.core.context.CompositeContext;
-import org.apache.tuscany.core.context.event.HttpSessionBound;
-import org.apache.tuscany.core.context.event.RequestStart;
-import org.apache.tuscany.core.context.event.RequestEnd;
-import org.osoa.sca.CurrentModuleContext;
-import org.osoa.sca.ModuleContext;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.Filter;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletResponse;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletRequest;
-import java.io.IOException;
-
-/**
- * Notifies the {@link org.apache.tuscany.core.context.CompositeContext} of web request start and end events as well as setting up the
- * current session context. The latter is done using lazy Servlet-based session retrieval. The filter fires a session
- * start event, passing a <tt>LazyServletSessionId</tt> as the session id. The <tt>LazyServletSessionId</tt> is a
- * wrapper for the servlet request which may be called by the <tt>ModuleContext</tt> to retrieve the session id
- * lazily.
- *
- * @version $Rev: 379957 $ $Date: 2006-02-22 14:58:24 -0800 (Wed, 22 Feb 2006) $
- */
-public class TuscanyRequestFilter implements Filter {
- private CompositeContext moduleContext;
-
- public TuscanyRequestFilter() {
- }
-
- public void init(FilterConfig filterConfig) throws ServletException {
- ServletContext servletContext = filterConfig.getServletContext();
- moduleContext = (CompositeContext) servletContext.getAttribute(TuscanyServletListener.MODULE_COMPONENT_NAME);
- }
-
- public void destroy() {
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
- ModuleContext oldContext = CurrentModuleContext.getContext();
- try {
- // Set the current module context
- ContextBinder.BINDER.setContext((ModuleContext) moduleContext);
-
- // Handle a request
- if (request instanceof HttpServletRequest) {
- if (((HttpServletRequest) request).getSession(false) != null) {
-
- // A session is already active
- moduleContext.publish(new HttpSessionBound(this, ((HttpServletRequest) request).getSession(true)));
- } else {
- // Create a lazy wrapper since a session is not yet active
- moduleContext.publish(new HttpSessionBound(this, new LazyHTTPSessionId((HttpServletRequest) request)));
- }
- } else {
- moduleContext.publish(new HttpSessionBound(this, request));
- }
- // Start processing the request
- moduleContext.publish(new RequestStart(this, request));
- // Dispatch to the next filter
- filterChain.doFilter(request, response);
- } catch (Exception e) {
- throw new ServletException(e);
-
- } finally {
- try {
- // End processing the request
- moduleContext.publish(new RequestEnd(this, request));
- } catch (Exception e) {
- throw new ServletException(e);
- }
- ContextBinder.BINDER.setContext(oldContext);
- }
- }
-
-}
diff --git a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java b/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java
deleted file mode 100644
index 8c9c215d64..0000000000
--- a/tags/java-M1-20060518/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.core.webapp;
-
-import org.apache.tuscany.common.monitor.MonitorFactory;
-import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
-import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.client.BootstrapHelper;
-import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.context.CompositeContext;
-import org.apache.tuscany.core.context.SystemCompositeContext;
-import org.apache.tuscany.core.context.event.ModuleStop;
-import org.apache.tuscany.core.context.event.ModuleStart;
-import org.apache.tuscany.core.context.event.HttpSessionEnd;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-import org.apache.tuscany.model.assembly.AssemblyContext;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.osoa.sca.CurrentModuleContext;
-import org.osoa.sca.ModuleContext;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-
-/**
- * ServletContextListener that can be added to a standard web application to boot
- * a Tuscany runtime inside that application. All implementation classes should
- * be located in the web application itself.
- *
- * @version $Rev: 380792 $ $Date: 2006-02-24 11:25:11 -0800 (Fri, 24 Feb 2006) $
- */
-public class TuscanyServletListener implements ServletContextListener, HttpSessionListener {
- public static final String SCA_COMPONENT_NAME = "org.apache.tuscany.core.webapp.ModuleComponentName";
- public static final String MODULE_COMPONENT_NAME = "org.apache.tuscany.core.webapp.ModuleComponentContext";
- public static final String TUSCANY_RUNTIME_NAME = RuntimeContext.class.getName();
-
- private RuntimeContext runtime;
- private CompositeContext moduleContext;
-
- private static final String SYSTEM_MODULE_COMPONENT = "org.apache.tuscany.core.system";
-
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- ServletContext servletContext = servletContextEvent.getServletContext();
- String name = servletContext.getInitParameter(SCA_COMPONENT_NAME);
- String uri = name; // todo get from context path
- MonitorFactory monitorFactory = new NullMonitorFactory(); // todo have one that writes to the servlet log
-
- try {
- bootRuntime(name, uri, monitorFactory);
- } catch (ConfigurationException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
-
- servletContext.setAttribute(TUSCANY_RUNTIME_NAME, runtime);
- servletContext.setAttribute(MODULE_COMPONENT_NAME, moduleContext);
- }
-
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- moduleContext.publish(new ModuleStop(this));
- moduleContext.stop();
- SystemCompositeContext systemContext = runtime.getSystemContext();
- systemContext.publish(new ModuleStop(this));
- systemContext.stop();
- runtime.stop();
- servletContextEvent.getServletContext().removeAttribute(MODULE_COMPONENT_NAME);
- servletContextEvent.getServletContext().removeAttribute(TUSCANY_RUNTIME_NAME);
- }
-
- public void sessionCreated(HttpSessionEvent event) {
- // do nothing since sessions are lazily created in {@link TuscanyRequestFilter}
- }
-
- public void sessionDestroyed(HttpSessionEvent event) {
- // todo do we actually need to bind the module context to the thread to fire this event?
- ModuleContext oldContext = CurrentModuleContext.getContext();
- try {
- ContextBinder.BINDER.setContext((ModuleContext) moduleContext);
- moduleContext.publish(new HttpSessionEnd(this, event.getSession()));
- } finally{
- ContextBinder.BINDER.setContext(oldContext);
- }
- }
-
- private void bootRuntime(String name, String uri, MonitorFactory monitorFactory) throws ConfigurationException {
-
- // Create an assembly model context
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- AssemblyContext modelContext = BootstrapHelper.getModelContext(classLoader);
-
- // Create a runtime context and start it
- ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory);
- runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, new DefaultWireBuilder());
- runtime.start();
-
- // Load and start the system configuration
- SystemCompositeContext systemContext = runtime.getSystemContext();
- BootstrapHelper.bootstrapStaxLoader(systemContext, modelContext);
- ModuleComponentConfigurationLoader loader = BootstrapHelper.getConfigurationLoader(systemContext, modelContext);
- ModuleComponent systemModuleComponent = loader.loadSystemModuleComponent(SYSTEM_MODULE_COMPONENT, SYSTEM_MODULE_COMPONENT);
- CompositeContext context = BootstrapHelper.registerModule(systemContext, systemModuleComponent);
- context.publish(new ModuleStart(this));
-
- // Load the SCDL configuration of the application module
- CompositeContext rootContext = runtime.getRootContext();
- ModuleComponent moduleComponent = loader.loadModuleComponent(name, uri);
- moduleContext = BootstrapHelper.registerModule(rootContext, moduleComponent);
-
- moduleContext.publish(new ModuleStart(this));
- }
-}