geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r570534 [3/7] - in /geronimo/plugins/tuscany: ./ branches/ tags/ trunk/ trunk/geronimo-tuscany-http-jetty/ trunk/geronimo-tuscany-http-jetty/src/ trunk/geronimo-tuscany-http-jetty/src/main/ trunk/geronimo-tuscany-http-jetty/src/main/java/ t...
Date Tue, 28 Aug 2007 19:26:54 GMT
Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/LICENSE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt Tue Aug 28 12:26:50
2007
@@ -0,0 +1,6 @@
+Apache Geronimo 
+Copyright 2003-2007 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml Tue Aug 28 12:26:50
2007
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.geronimo.plugins</groupId>
+		<artifactId>tuscany-parent</artifactId>
+		<version>1.0-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+
+	<artifactId>geronimo-tuscany-http-jetty</artifactId>
+	<name>Geronimo Plugins :: Tuscany Servlet Host for Geronimo Jetty</name>
+
+	<dependencies>
+	    <!--  Geronimo dependencies -->
+		<dependency>
+			<groupId>org.apache.geronimo.components</groupId>
+			<artifactId>geronimo-transaction</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-j2ee</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-naming</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-jetty6</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-kernel</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-servlet_2.5_spec</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.mortbay.jetty</groupId>
+			<artifactId>jetty</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.mortbay.jetty</groupId>
+			<artifactId>jetty-util</artifactId>
+		</dependency>
+
+        <!-- Tuscany dependencies -->
+		<dependency>
+			<groupId>org.apache.tuscany.sca</groupId>
+			<artifactId>tuscany-host-http</artifactId>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+		</plugins>
+
+		<sourceDirectory>src/main/java</sourceDirectory>
+		<testSourceDirectory>src/test</testSourceDirectory>
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<filtering>true</filtering>
+			</resource>
+		</resources>
+		<testResources>
+			<testResource>
+				<directory>src/test/resources</directory>
+			</testResource>
+		</testResources>
+	</build>
+
+</project>
+
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
Tue Aug 28 12:26:50 2007
@@ -0,0 +1,341 @@
+/*
+ * 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.geronimo.tuscany.http.jetty;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executor;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.transaction.TransactionManager;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.jetty6.Host;
+import org.apache.geronimo.jetty6.JettyContainer;
+import org.apache.geronimo.jetty6.JettyWebAppContext;
+import org.apache.geronimo.jetty6.handler.ComponentContextHandler;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
+import org.apache.geronimo.management.geronimo.NetworkConnector;
+import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
+import org.apache.geronimo.transaction.GeronimoUserTransaction;
+
+import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletMappingException;
+
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.security.SecurityHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.jetty.servlet.SessionHandler;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.jetty.servlet.DefaultServlet;
+
+/**
+ * A Geronimo based implementation of ServletHost. This works only on those
+ * versions of Geronimo 2.0 that use Jetty as the Web Container. Adds contexts
+ * to the Jetty Server as and when required. In case of existing contexts it
+ * adds the servlets to those contexts provided they were created by this
+ * servlet host implementation. If the context provided in the URL where the
+ * service is exposed is an existing J2EE context then an error is thrown.
+ * 
+ * @version $Rev$ $Date$
+ */
+
+@SuppressWarnings("deprecation")
+public class GeronimoServletHost implements ServletHost {
+    private static final Log log = LogFactory.getLog(GeronimoServletHost.class);
+
+    private static final int DEFAULT_PORT = 8080;
+    private NetworkConnector[] connectors;
+    private JettyContainer container = null;
+    private Kernel kernel = null;
+    private ClassLoader cl = null;
+    private WebAppContext webAppContext = null;
+    private Context componentContext = null;
+    private static Map<String, ComponentContextHandler> contextHandlers = new Hashtable<String,
ComponentContextHandler>();
+    private Map<String, JettyWebAppContext> jettyWebAppContexts = new HashMap<String,
JettyWebAppContext>();
+    private TransactionManager transactionManager = null;
+    private Host host = null;
+    private ComponentContextHandler contextHandler = null;
+
+    private static final String JMX_APP_NAME = "Tuscany Service Context";
+    private static final String JMX_SERVER_NAME = "geronimo";
+    private static final String SEPARATOR = "/";
+    private static final String WILDCARD = "*";
+    private static final String docext = "work";
+    private static final String transactionManagerGBeanName = "TransactionManager";
+    private static final String jettyContainerGBeanName = "JettyWebContainer";
+
+    public void init() {
+        log.debug("Start of init() method");
+        kernel = KernelRegistry.getSingleKernel();
+        try {
+            container = (JettyContainer) kernel.getGBean(
+                    jettyContainerGBeanName, JettyContainer.class);
+        } catch (Exception e) {
+            log.fatal("Cannot find GBean named " + jettyContainerGBeanName, e);
+            throw new IllegalStateException("Cannot find GBean named "
+                    + jettyContainerGBeanName, e);
+        }
+        try {
+            transactionManager = (TransactionManager) kernel.getGBean(
+                    transactionManagerGBeanName, TransactionManager.class);
+        } catch (Exception e) {
+            log.fatal("Cannot find GBean named " + transactionManagerGBeanName,
+                    e);
+            throw new IllegalStateException("Cannot find GBean named "
+                    + transactionManagerGBeanName, e);
+        }
+        this.connectors = container.getConnectors();
+        log.debug("End of init() method");
+    }
+
+    public void addServletMapping(String strURI, Servlet servlet) {
+        log.debug("Start of addServletMapping() method");
+        Set abstractNames = kernel.listGBeans(new AbstractNameQuery(
+                JettyWebAppContext.class.getName()));
+        Iterator iterator = abstractNames.iterator();
+        JettyWebAppContext jettyWebAppContext = null;
+        while (iterator.hasNext()) {
+            try {
+                jettyWebAppContext = (JettyWebAppContext) kernel
+                        .getGBean((AbstractName) iterator.next());
+            } catch (GBeanNotFoundException e) {
+                throw new IllegalStateException(e.getMessage(),e);
+            } catch (InternalKernelException e) {
+                throw new IllegalStateException(e.getMessage(),e);
+            } catch (IllegalStateException e) {
+                throw e;
+            }
+            jettyWebAppContexts.put(jettyWebAppContext.getContextPath(),
+                    jettyWebAppContext);
+        }
+
+        URI uri = URI.create(strURI);
+        boolean validport = false;
+        String host = uri.getHost();
+        int port = uri.getPort();
+        if (port == -1) {
+            port = DEFAULT_PORT;
+        }
+        for (int i = 0; i < connectors.length; i++) {
+            GeronimoManagedBean gmbean = (GeronimoManagedBean) connectors[i];
+            if (gmbean.getStateInstance().isRunning()
+                    && port == connectors[i].getPort()) {
+                validport = true;
+                break;
+            }
+        }
+        if (!validport) {
+            throw new IllegalStateException("Invalid port '" + port
+                    + "'.  Do you have a connector configured for that port?");
+        }
+        String path = uri.getPath();
+        path = (path.startsWith(SEPARATOR)) ? path.substring(1) : path;
+        String contextPath = SEPARATOR + (path.indexOf(SEPARATOR) != -1 ? path.substring(0,path.indexOf(SEPARATOR))
: path);
+        String mapping = path.indexOf(SEPARATOR) != -1 ? path.substring(path.indexOf(SEPARATOR))
: SEPARATOR;
+        if(mapping.equals(SEPARATOR)) {
+            // For url's of kind http://localhost/servicename, use context path "/".
+            mapping = contextPath;
+            contextPath = SEPARATOR;
+        }
+        SessionHandler sessionHandler = null;
+        ServletHandler servletHandler = null;
+        SecurityHandler securityHandler = null;
+
+        if (jettyWebAppContexts.get(contextPath) != null) {
+            throw new IllegalStateException(
+                    "The context "
+                            + contextPath
+                            + "already exists for a web application and cannot be used by
the binding.");
+        } else if (contextHandlers.get(contextPath) == null) {
+            sessionHandler = new SessionHandler();
+            servletHandler = new ServletHandler();
+            securityHandler = new SecurityHandler();
+            webAppContext = new WebAppContext(securityHandler, sessionHandler,
+                    servletHandler, null);
+            webAppContext.setContextPath(contextPath);
+            webAppContext.setAllowNullPathInfo(true);
+            webAppContext.setClassLoader(Thread.currentThread()
+                    .getContextClassLoader());
+            webAppContext.setCopyWebDir(false);
+            webAppContext.setExtractWAR(false);
+            webAppContext.setWar("./");
+            GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(
+                    transactionManager);
+            try {
+                this.componentContext = EnterpriseNamingContext
+                        .createEnterpriseNamingContext(new HashMap(),
+                                userTransaction, kernel, cl);
+            } catch (NamingException e1) {
+                log.fatal("JNDI Context creation failed for the context "
+                        + webAppContext.getContextPath()
+                        + " in the Tuscany Plugin", e1);
+                throw new IllegalStateException(
+                        "JNDI Context creation failed for the context "
+                                + webAppContext.getContextPath()
+                                + " in the Tuscany Plugin");
+            }
+            webAppContext.getInitParams().put(
+                    "org.mortbay.jetty.servlet.Default.dirAllowed", "false");
+        
+            webAppContext.setVirtualHosts(new String[] { host });
+        
+            contextHandler = new ComponentContextHandler(webAppContext,
+                    this.componentContext);
+        } else {
+            contextHandler = contextHandlers.get(contextPath);
+            servletHandler = (ServletHandler) contextHandler
+                    .getChildHandlerByClass(ServletHandler.class);
+        }
+
+        // FIXME - Need to Assign JSR 77 Names to Context but How?        
+        ServletHolder holder;
+        if (servlet instanceof DefaultResourceServlet) {
+
+            // Optimize the handling of resource requests, use the Jetty default
+            // servlet
+            // instead of our default resource servlet
+            String servletPath = uri.getPath();
+            if (servletPath.endsWith("*")) {
+                servletPath = servletPath
+                        .substring(0, servletPath.length() - 1);
+            }
+            if (servletPath.endsWith("/")) {
+                servletPath = servletPath
+                        .substring(0, servletPath.length() - 1);
+            }
+            if (!servletPath.startsWith("/")) {
+                servletPath = '/' + servletPath;
+            }
+            DefaultResourceServlet resourceServlet = (DefaultResourceServlet) servlet;
+            DefaultServlet defaultServlet = new JettyDefaultServlet(
+                    servletPath, resourceServlet.getDocumentRoot());
+            holder = new ServletHolder(defaultServlet);
+
+        } else {
+            holder = new ServletHolder(servlet);
+        }
+        servletHandler.addServlet(holder);
+        ServletMapping servletMapping = new ServletMapping();
+        servletMapping.setServletName(holder.getName());
+        servletMapping.setPathSpec(mapping);
+        servletHandler.addServletMapping(servletMapping);
+        if (contextHandlers.get(contextPath) == null) {
+            container.addContext(contextHandler);
+            try {
+                contextHandler.start();
+            } catch (Exception e) {
+                log.fatal("The context " + webAppContext.getContextPath()
+                        + " failed to start", e);
+                throw new IllegalStateException("The context "
+                        + webAppContext.getContextPath() + " failed to start");
+            }
+            contextHandlers.put(contextPath, contextHandler);
+        } else {
+            try {
+                holder.start();
+            } catch (Exception e) {
+                log.fatal("The Servlet Handler containing the holder "
+                        + holder.getDisplayName() + " failed to start", e);
+                throw new IllegalStateException(
+                        "The Servlet Handler containing the holder "
+                                + holder.getDisplayName() + " failed to start");
+            }
+        }
+        log.debug("End of addServletMapping() method");
+    }
+
+    public Servlet removeServletMapping(String uri) {
+        log.debug("Start of removeServletMapping() method");
+
+        String path = URI.create(uri).getPath();
+        path = (path.startsWith(SEPARATOR)) ? path.substring(1) : path;
+        String contextPath = SEPARATOR + (path.indexOf(SEPARATOR) != -1 ? path.substring(0,path.indexOf(SEPARATOR))
: path);
+        String mapping = path.indexOf(SEPARATOR) != -1 ? path.substring(path.indexOf(SEPARATOR))
: SEPARATOR;
+        if(mapping.equals(SEPARATOR)) {
+            // For url's of kind http://localhost/servicename, use context path "/".
+            mapping = contextPath;
+            contextPath = SEPARATOR;
+        }
+        ServletHandler servletHandler = (ServletHandler) contextHandler
+                .getChildHandlerByClass(ServletHandler.class);
+        Servlet removedServlet = null;
+        List<ServletMapping> mappings = new ArrayList<ServletMapping>(Arrays
+                .asList(servletHandler.getServletMappings()));
+        List<ServletHolder> servletHolders = new ArrayList<ServletHolder>(
+                Arrays.asList(servletHandler.getServlets()));
+        for (ServletMapping servletMapping : mappings) {
+            if (Arrays.asList(servletMapping.getPathSpecs()).contains(mapping)) {
+                try {
+                    removedServlet = servletHandler.getServlet(
+                            servletMapping.getServletName()).getServlet();
+                } catch (ServletException e) {
+                    throw new IllegalStateException(e);
+                }
+                mappings.remove(servletMapping);
+                servletHolders.remove(servletHandler.getServlet(servletMapping
+                        .getServletName()));
+                break;
+            }
+        }
+        if (removedServlet != null) {
+            servletHandler.setServletMappings(mappings
+                    .toArray(new ServletMapping[mappings.size()]));
+        }
+
+        try {
+            if (mappings.size() < 3) {
+                contextHandler.stop();
+                contextHandler.destroy();
+                container.removeContext(contextHandler);
+                contextHandlers.remove(contextPath);
+            } else {
+
+                servletHandler.start();
+            }
+        } catch (Exception e) {
+            log.error("Removal failed with Exception ", e);
+        }
+        log.debug("End of removeServletMapping() method");
+        return removedServlet;
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
Tue Aug 28 12:26:50 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.geronimo.tuscany.http.jetty;
+
+import org.mortbay.jetty.servlet.DefaultServlet;
+import org.mortbay.resource.Resource;
+
+/**
+ * Customizes the Jetty default servlet.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JettyDefaultServlet extends DefaultServlet {
+    private static final long serialVersionUID = 7000218247190209353L;
+
+    private String documentRoot;
+    private String servletPath;
+    
+    public JettyDefaultServlet(String servletPath, String documentRoot) {
+        this.servletPath = servletPath + '/';
+        this.documentRoot = documentRoot;
+    }
+
+    @Override
+    public Resource getResource(String pathInContext) {
+        if (pathInContext.startsWith(servletPath)) {
+            if (pathInContext.length() > servletPath.length()) {
+                pathInContext = pathInContext.substring(servletPath.length());
+            } else {
+                pathInContext = "";
+            }
+        } else {
+            if ((pathInContext + "/").equals(servletPath)) {
+                pathInContext = "";
+            }
+        }
+        return super.getResource(pathInContext);
+    }
+    
+    @Override
+    public String getInitParameter(String name) {
+        if ("resourceBase".equals(name)) {
+            return documentRoot;
+        } else if ("redirectWelcome".equals(name)) {
+            return "true";
+        } else {
+            return super.getInitParameter(name);
+        }
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/JettyDefaultServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
Tue Aug 28 12:26:50 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.geronimo.tuscany.http.jetty.module;
+
+import java.util.List;
+
+import org.apache.geronimo.tuscany.http.jetty.GeronimoServletHost;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoRuntimeModuleActivator implements ModuleActivator {
+
+    private GeronimoServletHost servletHost;
+
+    public Object[] getExtensionPoints() {
+        return null;
+    }
+
+    public void start(ExtensionPointRegistry extensionPointRegistry) {
+        // Register a Jetty servlet host
+        ServletHostExtensionPoint servletHosts =
+            extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);  
     
+        servletHost = new GeronimoServletHost();  
+        servletHost.init();
+        servletHosts.addServletHost(servletHost);
+    }
+
+    public void stop(ExtensionPointRegistry registry) {
+        ServletHostExtensionPoint servletHosts =
+            registry.getExtensionPoint(ServletHostExtensionPoint.class);
+        List hostList = servletHosts.getServletHosts();
+        for(int i = 0; i < hostList.size(); i++){
+            if(hostList.get(i) instanceof GeronimoServletHost){
+                servletHosts.removeServletHost((GeronimoServletHost)hostList.get(i));
+                return;
+            }
+        }
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
(added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
Tue Aug 28 12:26:50 2007
@@ -0,0 +1,18 @@
+# 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.
+# Implementation class for the ModuleActivator
+org.apache.geronimo.tuscany.http.jetty.module.GeronimoRuntimeModuleActivator



Mime
View raw message