/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. * * * This file incorporates work covered by the following copyright and * permission notice: * * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina; import javax.naming.directory.DirContext; import javax.servlet.ServletException; import java.beans.PropertyChangeListener; import java.io.IOException; /** * A <b>Container</b> is an object that can execute requests received from * a client, and return responses based on those requests. A Container may * optionally support a pipeline of Valves that process the request in an * order configured at runtime, by implementing the <b>Pipeline</b> interface * as well. * <p> * Containers will exist at several conceptual levels within Catalina. The * following examples represent common cases: * <ul> * <li><b>Engine</b> - Representation of the entire Catalina servlet engine, * most likely containing one or more subcontainers that are either Host * or Context implementations, or other custom groups. * <li><b>Host</b> - Representation of a virtual host containing a number * of Contexts. * <li><b>Context</b> - Representation of a single ServletContext, which will * typically contain one or more Wrappers for the supported servlets. * <li><b>Wrapper</b> - Representation of an individual servlet definition * (which may support multiple servlet instances if the servlet itself * implements SingleThreadModel). * </ul> * A given deployment of Catalina need not include Containers at all of the * levels described above. For example, an administration application * embedded within a network device (such as a router) might only contain * a single Context and a few Wrappers, or even a single Wrapper if the * application is relatively small. Therefore, Container implementations * need to be designed so that they will operate correctly in the absence * of parent Containers in a given deployment. * <p> * A Container may also be associated with a number of support components * that provide functionality which might be shared (by attaching it to a * parent Container) or individually customized. The following support * components are currently recognized: * <ul> * <li><b>Loader</b> - Class loader to use for integrating new Java classes * for this Container into the JVM in which Catalina is running. * <li><b>Logger</b> - Implementation of the <code>log()</code> method * signatures of the <code>ServletContext</code> interface. * <li><b>Manager</b> - Manager for the pool of Sessions associated with * this Container. * <li><b>Realm</b> - Read-only interface to a security domain, for * authenticating user identities and their corresponding roles. * <li><b>Resources</b> - JNDI directory context enabling access to static * resources, enabling custom linkages to existing server components when * Catalina is embedded in a larger server. * </ul> * * @author Craig R. McClanahan * @author Remy Maucherat * @version $Revision: 1.4 $ $Date: 2006/12/15 18:56:51 $ */ public interface Container { // ----------------------------------------------------- Manifest Constants /** * The ContainerEvent event type sent when a child container is added * by <code>addChild()</code>. */ String ADD_CHILD_EVENT = "addChild"; /** * The ContainerEvent event type sent when a Mapper is added * by <code>addMapper()</code>. */ String ADD_MAPPER_EVENT = "addMapper"; /** * The ContainerEvent event type sent when a valve is added * by <code>addValve()</code>, if this Container supports pipelines. */ String ADD_VALVE_EVENT = "addValve"; /** * The ContainerEvent event type sent when a child container is removed * by <code>removeChild()</code>. */ String REMOVE_CHILD_EVENT = "removeChild"; /** * The ContainerEvent event type sent when a Mapper is removed * by <code>removeMapper()</code>. */ String REMOVE_MAPPER_EVENT = "removeMapper"; /** * The ContainerEvent event type sent when a valve is removed * by <code>removeValve()</code>, if this Container supports pipelines. */ String REMOVE_VALVE_EVENT = "removeValve"; // ------------------------------------------------------------- Properties /** * Return descriptive information about this Container implementation and * the corresponding version number, in the format * <code><description>/<version></code>. */ String getInfo(); /** * Return the Loader with which this Container is associated. If there is * no associated Loader, return the Loader associated with our parent * Container (if any); otherwise, return <code>null</code>. */ Loader getLoader(); /** * Set the Loader with which this Container is associated. * * @param loader The newly associated loader */ void setLoader(Loader loader); /** * Return the Logger with which this Container is associated. If there is * no associated Logger, return the Logger associated with our parent * Container (if any); otherwise return <code>null</code>. */ Logger getLogger(); /** * Set the Logger with which this Container is associated. * * @param logger The newly associated Logger */ void setLogger(Logger logger); /** * Return the Manager with which this Container is associated. If there is * no associated Manager, return the Manager associated with our parent * Container (if any); otherwise return <code>null</code>. */ Manager getManager(); /** * Set the Manager with which this Container is associated. * * @param manager The newly associated Manager */ void setManager(Manager manager); /** * Return an object which may be utilized for mapping to this component. */ Object getMappingObject(); /** * Return the Pipeline object that manages the Valves associated with * this Container. */ Pipeline getPipeline(); /** * @return true if this container was configured with a custom pipeline, * false otherwise */ boolean hasCustomPipeline(); /** * Get the delay between the invocation of the backgroundProcess method on * this container and its children. Child containers will not be invoked * if their delay value is not negative (which would mean they are using * their own thread). Setting this to a positive value will cause * a thread to be spawn. After waiting the specified amount of time, * the thread will invoke the executePeriodic method on this container * and all its children. */ int getBackgroundProcessorDelay(); /** * Set the delay between the invocation of the execute method on this * container and its children. * * @param delay The delay in seconds between the invocation of * backgroundProcess methods */ void setBackgroundProcessorDelay(int delay); /** * Return a name string (suitable for use by humans) that describes this * Container. Within the set of child containers belonging to a particular * parent, Container names must be unique. */ String getName(); /** * Set a name string (suitable for use by humans) that describes this * Container. Within the set of child containers belonging to a particular * parent, Container names must be unique. * * @param name New name of this container * * @exception IllegalStateException if this Container has already been * added to the children of a parent Container (after which the name * may not be changed) */ void setName(String name); /** * Return the Container for which this Container is a child, if there is * one. If there is no defined parent, return <code>null</code>. */ Container getParent(); /** * Set the parent Container to which this Container is being added as a * child. This Container may refuse to become attached to the specified * Container by throwing an exception. * * @param container Container to which this Container is being added * as a child * * @exception IllegalArgumentException if this Container refuses to become * attached to the specified Container */ void setParent(Container container); /** * Return the parent class loader (if any) for web applications. */ ClassLoader getParentClassLoader(); /** * Set the parent class loader (if any) for web applications. * This call is meaningful only <strong>before</strong> a Loader has * been configured, and the specified value (if non-null) should be * passed as an argument to the class loader constructor. * * @param parent The new parent class loader */ void setParentClassLoader(ClassLoader parent); /** * Return the Realm with which this Container is associated. If there is * no associated Realm, return the Realm associated with our parent * Container (if any); otherwise return <code>null</code>. */ Realm getRealm(); /** * Set the Realm with which this Container is associated. * * @param realm The newly associated Realm */ void setRealm(Realm realm); /** * Return the Resources with which this Container is associated. If there * is no associated Resources object, return the Resources associated with * our parent Container (if any); otherwise return <code>null</code>. */ DirContext getResources(); /** * Set the Resources object with which this Container is associated. * * @param resources The newly associated Resources */ void setResources(DirContext resources) throws Exception; // --------------------------------------------------------- Public Methods /** * Execute a periodic task, such as reloading, etc. This method will be * invoked inside the classloading context of this container. Unexpected * throwables will be caught and logged. */ void backgroundProcess(); /** * Add a new child Container to those associated with this Container, * if supported. Prior to adding this Container to the set of children, * the child's <code>setParent()</code> method must be called, with this * Container as an argument. This method may thrown an * <code>IllegalArgumentException</code> if this Container chooses not * to be attached to the specified Container, in which case it is not added * * @param child New child Container to be added * * @exception IllegalArgumentException if this exception is thrown by * the <code>setParent()</code> method of the child Container * @exception IllegalArgumentException if the new child does not have * a name unique from that of existing children of this Container * @exception IllegalStateException if this Container does not support * child Containers */ void addChild(Container child); /** * Add a container event listener to this component. * * @param listener The listener to add */ void addContainerListener(ContainerListener listener); /** * Notifies all event listeners of this Container of the given event. * * @param type Event type * @param data Event data */ void fireContainerEvent(String type, Object data); /** * Add a property change listener to this component. * * @param listener The listener to add */ void addPropertyChangeListener(PropertyChangeListener listener); /** * Return the child Container, associated with this Container, with * the specified name (if any); otherwise, return <code>null</code> * * @param name Name of the child Container to be retrieved */ Container findChild(String name); /** * Return the set of children Containers associated with this Container. * If this Container has no children, a zero-length array is returned. */ Container[] findChildren(); /** * Return the set of container listeners associated with this Container. * If this Container has no registered container listeners, a zero-length * array is returned. */ ContainerListener[] findContainerListeners(); /** * Process the specified Request, and generate the corresponding Response, * according to the design of this particular Container. * * @param request Request to be processed * @param response Response to be produced * * @exception IOException if an input/output error occurred while * processing * @exception ServletException if a ServletException was thrown * while processing this request */ void invoke(Request request, Response response) throws IOException, ServletException; /** * Remove an existing child Container from association with this parent * Container. * * @param child Existing child Container to be removed */ void removeChild(Container child); /** * Remove a container event listener from this component. * * @param listener The listener to remove */ void removeContainerListener(ContainerListener listener); /** * Remove a property change listener from this component. * * @param listener The listener to remove */ void removePropertyChangeListener(PropertyChangeListener listener); /** * Indicates whether the request will be checked to see if it is secure * before adding Pragma and Cache-control headers when proxy caching has * been disabled. * * @return true if the check is required; false otherwise. */ boolean isCheckIfRequestIsSecure(); /** * Sets the checkIfRequestIsSecure property of this Container. * * Setting this property to true will check if the request is secure * before adding Pragma and Cache-Control headers when proxy caching has * been disabled. * * @param checkIfRequestIsSecure true if check is required, false * otherwise */ void setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure); }