summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache')
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java55
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java68
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java51
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java68
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java42
-rw-r--r--branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java116
6 files changed, 0 insertions, 400 deletions
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java
deleted file mode 100644
index e6300c81b9..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import java.io.File;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-
-import org.apache.tuscany.sca.host.embedded.impl.HotUpdatableSCADomain;
-
-/**
- * A WebApp ContextListener that starts a Tuscany runtime supporting multiple
- * SCA contribution jars. All contribution jars found in the repository
- * directory named "sca-contributions" will be contributed to the SCA
- * domain. Any changes to the contributions in the repository will be
- * automatically detected and the sca domain updated accordingly.
- */
-public class HotUpdateContextListener extends TuscanyContextListener {
-
- public static final String REPOSITORY_FOLDER_NAME = "sca-contributions";
-
- @Override
- public void contextInitialized(ServletContextEvent event) {
- ServletContext servletContext = event.getServletContext();
-
- // TODO better domaiURI, maybe based on webapp name?
- String domainURI = "http://localhost/" + servletContext.getServletContextName().replace(' ', '.');
-
- File repository = new File(servletContext.getRealPath(REPOSITORY_FOLDER_NAME));
- HotUpdatableSCADomain scaDomain = new HotUpdatableSCADomain(domainURI, repository, 2000);
-
- servletContext.setAttribute(SCADomainHelper.SCA_DOMAIN_ATTRIBUTE, scaDomain);
-
- super.contextInitialized(event);
- }
-
-}
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java
deleted file mode 100644
index dff63ed01e..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.servlet.ServletContext;
-
-import org.apache.tuscany.sca.host.embedded.SCADomain;
-
-/**
- * Utility class to initialize the SCADomian associated with a webapp
- */
-public class SCADomainHelper {
-
- public static final String SCA_DOMAIN_ATTRIBUTE = "org.apache.tuscany.sca.SCADomain";
-
- /**
- * Initializes the SCADomian associated with a webapp context. If a SCADomain
- * doesn't exist already then one is create based on the webapp config.
- */
- public static SCADomain initSCADomain(ServletContext servletContext) {
- SCADomain scaDomain = (SCADomain)servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE);
-
- String domainURI = "http://localhost/" + servletContext.getServletContextName().replace(' ', '.');
- String contributionRoot = null;
-
- try {
- URL rootURL = servletContext.getResource("/");
- if (rootURL.getProtocol().equals("jndi")) {
- //this is tomcat case, we should use getRealPath
- File warRootFile = new File(servletContext.getRealPath("/"));
- contributionRoot = warRootFile.toURL().toString();
- } else {
- //this is jetty case
- contributionRoot = rootURL.toString();
- }
- } catch(MalformedURLException mf) {
- //ignore, pass null
- }
-
-
- if (scaDomain == null) {
- scaDomain = SCADomain.newInstance(domainURI, contributionRoot);
- servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
- }
- return scaDomain;
- }
-}
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
deleted file mode 100644
index 5bc83df77f..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.apache.tuscany.sca.host.embedded.SCADomain;
-
-/**
- * A ServletContextListener to create and close the SCADomain
- * when the webapp is initialized or destroyed.
- */
-public class TuscanyContextListener implements ServletContextListener {
-
- public void contextInitialized(ServletContextEvent event) {
- ServletContext servletContext = event.getServletContext();
- try {
- SCADomainHelper.initSCADomain(servletContext);
- } catch (Throwable e) {
- servletContext.log("exception initializing SCADomain", e);
- }
- }
-
- public void contextDestroyed(ServletContextEvent event) {
- ServletContext servletContext = event.getServletContext();
- SCADomain scaDomain = (SCADomain) servletContext.getAttribute(SCADomainHelper.SCA_DOMAIN_ATTRIBUTE);
- if (scaDomain != null) {
- scaDomain.close();
- }
- }
-
-}
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
deleted file mode 100644
index 0e64ebc9b8..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import java.io.IOException;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * A servlet that forwards requests to the servlets registered with the Tuscany
- * ServletHost.
- */
-public class TuscanyServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
-
- protected transient WebAppServletHost servletHost;
-
- @Override
- public void init(ServletConfig config) throws ServletException {
- ServletContext servletContext = config.getServletContext();
- SCADomainHelper.initSCADomain(servletContext);
-
- // TODO: must be a better way to get this than using a static
- servletHost = WebAppServletHost.getInstance();
- servletHost.init(config);
- }
-
- @Override
- public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
- String path = ((HttpServletRequest)req).getPathInfo();
- Servlet servlet = servletHost.getServlet(path);
- if (servlet == null) {
- path = ((HttpServletRequest)req).getRequestURI();
- servlet = servletHost.getServlet(path);
-
- if (servlet == null) {
- throw new IllegalStateException("No servlet registered for path: " + path);
- }
- }
-
- servlet.service(req, res);
- }
-
-}
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
deleted file mode 100644
index 09b11145d6..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.ModuleActivator;
-import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
-
-/**
- * Activates the webapp host by registering the webapp ServletHost impl
- */
-public class WebAppModuleActivator implements ModuleActivator {
-
- public void start(ExtensionPointRegistry extensionPointRegistry) {
-
- ServletHostExtensionPoint servletHosts =
- extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
-
- servletHosts.addServletHost(WebAppServletHost.getInstance());
- }
-
- public void stop(ExtensionPointRegistry registry) {
- }
-
-}
diff --git a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
deleted file mode 100644
index 4e0d3d88c5..0000000000
--- a/branches/sca-java-0.99/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.sca.host.webapp;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-
-import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
-import org.apache.tuscany.sca.host.http.ServletHost;
-import org.apache.tuscany.sca.host.http.ServletMappingException;
-
-/**
- * ServletHost impl singleton thats shared between the SCADomain
- * instance and the TuscanyServlet instance.
- * TODO: using a static singleton seems a big hack but how
- * should it be shared? Need some way for TuscanyServlet
- * to pull it out of the SCADomain instance.
- *
- */
-public class WebAppServletHost implements ServletHost {
- private static final Logger logger = Logger.getLogger(WebAppServletHost.class.getName());
- private static WebAppServletHost instance = new WebAppServletHost();
-
- private Map<String, Servlet> servlets;
-
- private WebAppServletHost() {
- servlets = new HashMap<String, Servlet>();
- }
-
- public void addServletMapping(String path, Servlet servlet) throws ServletMappingException {
- URI pathURI = URI.create(path);
-
- // Ignore registrations of our default resource servlet, as resources
- // are already served by the web container
- if (servlet instanceof DefaultResourceServlet) {
- //TODO maybe ignore registration of the servlet only if it's
- // mapped to "/" and still honor other registrations, to do this
- // we will need a way to determine what's the default servlet
- // in the web container that we are running in.
- return;
- }
-
- // For webapps just use the path and ignore the host and port
- path = pathURI.getPath();
- if (!path.startsWith("/")) {
- path = '/' + path;
- }
- servlets.put(path, servlet);
- logger.info("addServletMapping: " + path);
- }
-
- public Servlet removeServletMapping(String path) throws ServletMappingException {
- URI pathURI = URI.create(path);
- path = pathURI.getPath();
- if (!path.startsWith("/")) {
- path = '/' + path;
- }
- // for webapps just use the path and ignore the host and port
- return servlets.remove(path);
- }
-
- public Servlet getServlet(String path) {
- if (path == null) {
- return null;
- }
- if (!path.startsWith("/")) {
- path = '/' + path;
- }
- Servlet servlet = servlets.get(path);
- if (servlet != null) {
- return servlet;
- }
- for (String servletPath : servlets.keySet()) {
- if (servletPath.endsWith("*")) {
- if (path.startsWith(servletPath.substring(0, servletPath.length() - 1))) {
- return servlets.get(servletPath);
- }
- }
- }
- return null;
- }
-
- public static WebAppServletHost getInstance() {
- return instance;
- }
-
- public void init(ServletConfig config) throws ServletException {
- for (Servlet servlet : servlets.values()) {
- servlet.init(config);
- }
- }
-
-}