gdamour 2004/01/20 06:58:08
Modified: modules/web project.xml Added: modules/web/src/java/org/apache/geronimo/webdav/jetty JettyConnectorImpl.java JettyConnector.java JettyDAVServer.java modules/web/src/java/org/apache/geronimo/webdav DAVRepository.java CatalinaDAVRepository.java DAVServer.java AbstractConnector.java Connector.java Log: Initiale check in of a WebDAV service using: - Jetty as the underlying HTTP server; and - Tomcat WebDAV servlet as the WebDAV implementation. The DAVServer and Connector classes are modelled after the Web layer implemented by Jan Bartel and Greg Wilkins. Revision Changes Path 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/jetty/JettyConnectorImpl.java Index: JettyConnectorImpl.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav.jetty; import java.lang.reflect.Constructor; import org.apache.geronimo.gbean.GAttributeInfo; import org.apache.geronimo.gbean.GBean; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.WaitingException; import org.apache.geronimo.webdav.AbstractConnector; import org.mortbay.http.HttpListener; import org.mortbay.http.SocketListener; import org.mortbay.http.SunJsseListener; import org.mortbay.http.ajp.AJP13Listener; import org.mortbay.util.ThreadedServer; /** * Connector using under the cover a Jetty HttpListener. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public class JettyConnectorImpl extends AbstractConnector implements GBean, JettyConnector { private static final String HTTP_PROTOCOL = "http"; private static final String HTTPS_PROTOCOL = "https"; private static final String AJP13_PROTOCOL = "ajp13"; private final static GBeanInfo GBEAN_INFO; private final static Class[] EMPTY_FORMAL_PARAM = new Class[]{}; private final static Object[] EMPTY_ARGS = new Object[]{}; /** * When the underlying listener is undefined, the GBean operations are * delegated to this state. */ private final GBean undefinedListenerState; /** * When the underlying listener is defined, the GBean operations are * delegated to this state. */ private final GBean definedListenerState; private HttpListener listener; private GBean lifeCycleState; public JettyConnectorImpl(String aProtocol, String anHost, int aPort, int aMaxCon, int aMaxIdle) { super(aProtocol, anHost, aPort, aMaxCon, aMaxIdle); undefinedListenerState = new UndefinedListenerState(); definedListenerState = new DefinedListenerState(); setListener(null); } public HttpListener getListener() { return listener; } private void setListener(HttpListener aListener) { listener = aListener; if ( null == listener ) { lifeCycleState = undefinedListenerState; } else { lifeCycleState = definedListenerState; } } public void doStart() throws WaitingException, Exception { log.info("Starting Jetty Connector"); lifeCycleState.doStart(); } public void doStop() throws WaitingException { log.info("Stopping Jetty Connector"); lifeCycleState.doStop(); } public void doFail() { log.info("Failing Jetty Connector"); lifeCycleState.doFail(); } static { GBeanInfoFactory infoFactory = new GBeanInfoFactory("Connector - Jetty", JettyConnectorImpl.class.getName(), AbstractConnector.getGBeanInfo()); infoFactory.addAttribute(new GAttributeInfo("Listener")); GBEAN_INFO = infoFactory.getBeanInfo(); } public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } private class DefinedListenerState implements GBean { public void doStart() throws WaitingException, Exception { if ( listener.isStarted() ) { return; } listener.start(); } public void doStop() throws WaitingException { try { listener.stop(); } catch (Exception e) { log.error("Problem stopping Jetty Connector", e); setListener(null); } } public void doFail() { try { if (listener.isStarted()) { listener.stop(); } } catch (Exception e) { log.error("Can not fail Jetty Connector", e); } setListener(null); } } private class UndefinedListenerState implements GBean { public void doStart() throws WaitingException, Exception { HttpListener tmpListener; try { if (null == protocol || protocol.equalsIgnoreCase(HTTP_PROTOCOL)) { tmpListener = new SocketListener(); } else if (protocol.equalsIgnoreCase(AJP13_PROTOCOL)) { tmpListener = new AJP13Listener(); } else if (protocol.equalsIgnoreCase(HTTPS_PROTOCOL)) { tmpListener = new SunJsseListener(); } else { Class listenerClass = Thread.currentThread().getContextClassLoader().loadClass( protocol); Constructor constructor = listenerClass.getConstructor(EMPTY_FORMAL_PARAM); tmpListener = (HttpListener) constructor.newInstance(EMPTY_ARGS); } tmpListener.setPort(getPort()); if ( getInterface() != null ) { tmpListener.setHost(getInterface()); } if ( getMaxConnections() > 0 ) { ((ThreadedServer) tmpListener).setMaxThreads(getMaxConnections()); } if ( getMaxIdleTime() > 0 ) { ((ThreadedServer) tmpListener).setMaxIdleTimeMs(getMaxIdleTime()); } ((ThreadedServer) tmpListener).open(); tmpListener.start(); } catch (Exception e) { log.error("Problem starting Connector", e); throw e; } setListener(tmpListener); } public void doStop() throws WaitingException { } public void doFail() { } } } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/jetty/JettyConnector.java Index: JettyConnector.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav.jetty; import org.apache.geronimo.webdav.Connector; import org.mortbay.http.HttpListener; /** * This interface is required by the IoC framework: JettyConnector is an * endpoint, whose implementation JettyConnectorImpl does not define a * constructor without parameters. * <BR> * This interface captures the operations and attributes, which are exposed * as GBean operations and attributes. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public interface JettyConnector extends Connector { public HttpListener getListener(); } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/jetty/JettyDAVServer.java Index: JettyDAVServer.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav.jetty; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geronimo.gbean.EndpointCollection; import org.apache.geronimo.gbean.EndpointCollectionEvent; import org.apache.geronimo.gbean.EndpointCollectionListener; import org.apache.geronimo.gbean.GBean; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.GEndpointInfo; import org.apache.geronimo.gbean.WaitingException; import org.apache.geronimo.webdav.DAVRepository; import org.apache.geronimo.webdav.DAVServer; import org.mortbay.http.HttpListener; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHolder; import org.mortbay.jetty.servlet.ServletHttpContext; /** * DAVServer using under the cover a light Jetty servlet container. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public class JettyDAVServer implements DAVServer, GBean { private static final Log log = LogFactory.getLog(JettyDAVServer.class); private final static GBeanInfo GBEAN_INFO; /** * Jetty Server doing the actual work. */ private final Server server; /** * DAVRepository to ServletHolder map. */ private final Map repToServletHolder; /** * Connector to HttpListener map. */ private final Map conToListener; /** * Repositories served by this server. */ private EndpointCollection repositories; private final EndpointCollectionListener repositoryListener = new EndpointCollectionListener() { public void memberAdded(EndpointCollectionEvent event) { addRepository((DAVRepository) event.getMember()); } public void memberRemoved(EndpointCollectionEvent event) { removeRepository((DAVRepository) event.getMember()); } }; /** * Connectors injecting requests to this server. */ private EndpointCollection connectors; private final EndpointCollectionListener connectorListener = new EndpointCollectionListener() { public void memberAdded(EndpointCollectionEvent event) { addConnector((JettyConnector) event.getMember()); } public void memberRemoved(EndpointCollectionEvent event) { removeConnector((JettyConnector) event.getMember()); } }; public JettyDAVServer() throws Exception { server = new Server(); repToServletHolder = new HashMap(); conToListener = new HashMap(); } public void setConnectors(Collection aCollOfConnectors) { if ( null == aCollOfConnectors ) { connectors.removeEndpointCollectionListener(connectorListener); for (Iterator iter = connectors.iterator(); iter.hasNext();) { removeConnector((JettyConnector) iter.next()); } } connectors = (EndpointCollection) aCollOfConnectors; if ( null != connectors ) { connectors.addEndpointCollectionListener(connectorListener); for (Iterator iter = connectors.iterator(); iter.hasNext();) { addConnector((JettyConnector) iter.next()); } } } public void addConnector(JettyConnector aConnector) { // The Connector MUST be running at this stage, otherwise a null // listener is returned. This is enforced by the endpoint mechanism, // which publishes only running endpoints. if ( null == aConnector.getListener() ) { throw new IllegalStateException("No defined listener."); } server.addListener(aConnector.getListener()); synchronized (conToListener) { conToListener.put(aConnector, aConnector.getListener()); } } public void removeConnector(JettyConnector aConnector) { // At this stage, the connector could be failed. In this later case // the underlying listener is undefined. Hence the conToListener Map. HttpListener httpListener; synchronized (conToListener) { httpListener = (HttpListener) conToListener.remove(aConnector); } if ( null == httpListener ) { throw new IllegalStateException("Connector not registered."); } server.removeListener(httpListener); } public void setRepositories(Collection aCollOfRepositories) { if ( null == aCollOfRepositories ) { repositories.removeEndpointCollectionListener(repositoryListener); for (Iterator iter = repositories.iterator(); iter.hasNext();) { removeRepository((DAVRepository) iter.next()); } } repositories = (EndpointCollection) aCollOfRepositories; if ( null != repositories ) { repositories.addEndpointCollectionListener(repositoryListener); for (Iterator iter = repositories.iterator(); iter.hasNext();) { addRepository((DAVRepository) iter.next()); } } } /** * Adds a DAVRepository to this server. * * @param aRepository DAVRepository to be served by this server. */ public void addRepository(DAVRepository aRepository) { // Gets the context associated to this repository. ServletHttpContext context = (ServletHttpContext) server.getContext( aRepository.getHost(), aRepository.getContext()); // Defines the servlet context attributes. Map attributes = aRepository.getServletContextAttr(); for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry attribute = (Map.Entry) iter.next(); context.setAttribute( (String) attribute.getKey(), attribute.getValue()); } ServletHolder holder = null; try { // Defines the WebDAV servlet. holder = context.addServlet( "DAVRepository", "/*", aRepository.getHandlingServlet().getName()); // Defines the servlet init parameters. attributes = aRepository.getServletInitParam(); for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry attribute = (Map.Entry) iter.next(); holder.setInitParameter( (String) attribute.getKey(), (String) attribute.getValue()); } context.start(); } catch (Exception e) { log.error(e); throw new RuntimeException(e); } synchronized (repToServletHolder) { repToServletHolder.put(aRepository, holder); } } public void removeRepository(DAVRepository aRepository) { ServletHolder holder; synchronized (repToServletHolder) { holder = (ServletHolder) repToServletHolder.remove(aRepository); if ( null == holder ) { throw new IllegalArgumentException(aRepository + " is not contained by " + this); } } holder.getHttpHandler().getHttpContext(). removeHandler(holder.getHttpHandler()); // Undefined the servlet context attributes. Map attributes = aRepository.getServletContextAttr(); for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { String attribute = (String) iter.next(); holder.getHttpHandler().getHttpContext(). removeAttribute((String) attribute); } } public Collection getRepositories() { return repositories; } public Collection getConnectors() { return connectors; } public void doStart() throws WaitingException, Exception { log.info("Starting Jetty DAV Server"); try { server.start(); } catch (Exception e) { log.error("Can not start Jetty DAV Server", e); throw e; } } public void doStop() throws WaitingException { log.info("Stopping Jetty DAV Server"); try { server.stop(); } catch (Exception e) { log.error("Can not start Jetty DAV server", e); } } public void doFail() { log.info("Failing Jetty DAV Server"); try { if ( server.isStarted() ) { server.stop(); } } catch (Exception e) { log.error("Can not start Jetty DAV server", e); } } static { GBeanInfoFactory infoFactory = new GBeanInfoFactory("DAV Server - Jetty", JettyDAVServer.class.getName()); infoFactory.addEndpoint(new GEndpointInfo("Connectors", JettyConnector.class.getName())); infoFactory.addEndpoint(new GEndpointInfo("Repositories", DAVRepository.class.getName())); GBEAN_INFO = infoFactory.getBeanInfo(); } public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/DAVRepository.java Index: DAVRepository.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav; import java.util.Map; /** * A DAVRepository defines a WebDAV servlet along with its execution context. * <BR> * A WebDAV servlet is a servlet, which implements the WebDAV specific methods * , e.g. PROPFIND. This servlet is deployed and managed by the DAVServer, * which has mounted this repository. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public interface DAVRepository { /** * Gets the host name filter. * <BR> * If defined, only the requests for this host are forwarded to this * repository. * * @return Host name filter. */ public String getHost(); /** * Gets the context of the WebDAV servlet. * <BR> * * @return Context name. */ public String getContext(); /** * Gets the WebDAV servlet Class. * * @return WebDAV servlet class. */ public Class getHandlingServlet(); /** * Gets the servlet context attributes. * * @return Map of attribute name to value. */ public Map getServletContextAttr(); /** * Gets the servlet initialization parameters. * * @return Map of parameter name to value. */ public Map getServletInitParam(); } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/CatalinaDAVRepository.java Index: CatalinaDAVRepository.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav; import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.naming.directory.DirContext; import org.apache.catalina.Globals; import org.apache.catalina.servlets.WebdavServlet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geronimo.gbean.GAttributeInfo; import org.apache.geronimo.gbean.GBean; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.GConstructorInfo; import org.apache.geronimo.gbean.WaitingException; import org.apache.naming.resources.FileDirContext; /** * DAVRepository implementation using the Tomcat WebDAV servlet as the * processing servlet. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public class CatalinaDAVRepository implements DAVRepository, GBean { private static final Log log = LogFactory.getLog(CatalinaDAVRepository.class); private static final Class HANDLING_SERVLET = WebdavServlet.class; private final static GBeanInfo GBEAN_INFO; /** * DirContext abstracting the repository exposed by this repository. */ private final DirContext dirContext; /** * Root of the repository. */ private final File root; /** * Host filter. */ private final String host; /** * Servlet context. */ private final String context; /** * Servlet context attribute name to value. */ private final Map servletContextAttr; /** * Servlet init parameter name to value. */ private final Map servletInitParam; /** * Builds a DAVRepository relying on Tomcat WebDAV servlet in order to * process the WebDAV request. * * @param aRoot Root of the directory/DirContext exposed by this repository. * @param aContext Context within which the servlet should be mounted. * @param anHost Host filter, if any. */ public CatalinaDAVRepository(File aRoot, String aContext, String anHost) { if ( null == aRoot ) { throw new IllegalArgumentException("Root MUST be specified."); } else if ( null == aContext ) { throw new IllegalArgumentException("Context MUST be specified."); } context = aContext; host = anHost; if ( !aRoot.isDirectory() ) { throw new IllegalArgumentException(aRoot.getAbsolutePath() + " does not exist."); } root = aRoot; dirContext = new FileDirContext(); ((FileDirContext)dirContext).setDocBase(root.getAbsolutePath()); servletContextAttr = new HashMap(); servletContextAttr.put(Globals.RESOURCES_ATTR, dirContext); servletInitParam = new HashMap(); servletInitParam.put("readonly", "false"); servletInitParam.put("listings", "true"); } public Class getHandlingServlet() { return HANDLING_SERVLET; } public String getHost() { return host; } public String getContext() { return context; } /** * Gets the root of the directory exposed by this repository. * * @return Root of the exposed directory. */ public File getRoot() { return root; } public DirContext getDirContext() { return dirContext; } public Map getServletContextAttr() { return Collections.unmodifiableMap(servletContextAttr); } public Map getServletInitParam() { return Collections.unmodifiableMap(servletInitParam); } public void doStart() throws WaitingException, Exception { log.info("Starting Catalina DAV Repository"); } public void doStop() throws WaitingException { log.info("Stopping Catalina DAV Repository"); } public void doFail() { log.info("Failing Catalina DAV Repository"); } static { GBeanInfoFactory infoFactory = new GBeanInfoFactory("DAV Repository - Catalina WebDAV Servlet", CatalinaDAVRepository.class.getName()); infoFactory.addAttribute(new GAttributeInfo("Root", true)); infoFactory.addAttribute(new GAttributeInfo("Context", true)); infoFactory.addAttribute(new GAttributeInfo("Host", true)); infoFactory.addAttribute(new GAttributeInfo("HandlingServlet")); infoFactory.addAttribute(new GAttributeInfo("ServletContextAttr")); infoFactory.addAttribute(new GAttributeInfo("ServletInitParam")); infoFactory.setConstructor(new GConstructorInfo( Arrays.asList(new Object[] {"Root", "Context", "Host"}), Arrays.asList(new Object[] {File.class, String.class, String.class}))); GBEAN_INFO = infoFactory.getBeanInfo(); } public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/DAVServer.java Index: DAVServer.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav; import java.util.Collection; /** * A DAVServer is an HTTP server providing WebDAV capabilities. It allows to * expose, edit and manage a set of repositories remotely via a WebDAV client. * <BR> * The WebDAV protocol could "potentially" be the preferred transport to * distribute a component as its base protocol, HTTP, can usually * traverse firewalls. * <BR> * It is a composition of connectors and repositories. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public interface DAVServer { /** * Gets the connectors of this server. * * @return Collection of Connector instances associated to this server. */ public Collection getConnectors(); /** * Gets the repositories of this server. * * @return Collection of DAVRepository instances associated to this server. */ public Collection getRepositories(); } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/AbstractConnector.java Index: AbstractConnector.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geronimo.gbean.GAttributeInfo; import org.apache.geronimo.gbean.GBean; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.GConstructorInfo; /** * Base implementation for the Connector contracts. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public abstract class AbstractConnector implements Connector, GBean { private final static GBeanInfo GBEAN_INFO; protected final Log log = LogFactory.getLog(getClass()); /** * Port. */ protected int port; /** * Protocol. */ protected String protocol; /** * Host. */ private String host; /** * Maximum number of connections. */ protected int maxCon; /** * Maximum idle time. */ protected int maxIdle; /** * Creates a connector having the specified specificities. * * @param aProtocol Protocol. * @param anHost Host. * @param aPort Port. * @param aMaxCon Maximum number of connections. * @param aMaxIdle Maximum idle time. */ public AbstractConnector(String aProtocol, String anHost, int aPort, int aMaxCon, int aMaxIdle) { protocol = aProtocol; host = anHost; port = aPort; maxCon = aMaxCon; maxIdle = aMaxIdle; } public void setPort(int aPort) { port = aPort; } public int getPort() { return port; } public void setProtocol(String aProtocol) { protocol = aProtocol; } public String getProtocol() { return protocol; } public void setInterface(String anInterface) { host = anInterface; } /** * Gets the interface/host of this Connector. * <BR> * If it has not been set explicitely, then the host name of the localhost * is set and returned. * * @return Interface. */ public synchronized String getInterface() { if ( null != host ) { return host; } try { host = InetAddress.getLocalHost().getHostName(); return host; } catch (UnknownHostException e) { // Should not happen. log.error(e); throw new RuntimeException(e); } } public void setMaxConnections(int aMaxConnects) { maxCon = aMaxConnects; } public int getMaxConnections() { return maxCon; } public void setMaxIdleTime(int aMaxIdleTime) { maxIdle = aMaxIdleTime; } public int getMaxIdleTime() { return maxIdle; } static { GBeanInfoFactory infoFactory = new GBeanInfoFactory("Abstract Connector", AbstractConnector.class.getName()); infoFactory.addAttribute(new GAttributeInfo("Port", true)); infoFactory.addAttribute(new GAttributeInfo("Protocol", true)); infoFactory.addAttribute(new GAttributeInfo("Interface", true)); infoFactory.addAttribute(new GAttributeInfo("MaxConnections", true)); infoFactory.addAttribute(new GAttributeInfo("MaxIdleTime", true)); infoFactory.setConstructor(new GConstructorInfo( Arrays.asList(new Object[] {"Protocol", "Interface", "Port", "MaxConnections", "MaxIdleTime"}), Arrays.asList(new Object[] {String.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE}) )); GBEAN_INFO = infoFactory.getBeanInfo(); } public static GBeanInfo getGBeanInfo() { return GBEAN_INFO; } } 1.1 incubator-geronimo/modules/web/src/java/org/apache/geronimo/webdav/Connector.java Index: Connector.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Geronimo" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Geronimo", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ package org.apache.geronimo.webdav; /** * A Connector is a request listener and response broker. * * @version $Revision: 1.1 $ $Date: 2004/01/20 14:58:08 $ */ public interface Connector { /** * Listening port. * * @param aPort Listening port. */ public void setPort(int aPort); public int getPort(); /** * Protocol. * * @param aProtocol */ public void setProtocol(String aProtocol); public String getProtocol(); /** * Interface. * * @param aProtocol */ public void setInterface(String anInterface); public String getInterface(); /** * Maximum number of connections. * * @param aProtocol */ public void setMaxConnections(int aMaxConnects); public int getMaxConnections(); /** * Maximum idle time. * * @param aProtocol */ public void setMaxIdleTime(int aMaxIdleTime); public int getMaxIdleTime(); } 1.15 +91 -1 incubator-geronimo/modules/web/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/web/project.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- project.xml 19 Jan 2004 06:28:05 -0000 1.14 +++ project.xml 20 Jan 2004 14:58:08 -0000 1.15 @@ -279,6 +279,96 @@ </properties> </dependency> + <!-- WebDAV service using the Tomcat WebDAV servlet. --> + <dependency> + <groupId>tomcat</groupId> + <artifactId>catalina</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>catalina-optional</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>naming-common</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>naming-resources</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>servlets-common</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>servlets-default</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>servlets-webdav</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + <dependency> + <groupId>tomcat</groupId> + <artifactId>tomcat-util</artifactId> + <version>5.0.16</version> + <properties> + <runtime>true</runtime> + <destinations> + deploy/webdav/lib + </destinations> + </properties> + </dependency> + </dependencies>