FileDocCategorySizeDatePackage
ValveBase.javaAPI DocApache Tomcat 6.0.1410502Fri Jul 20 04:20:34 BST 2007org.apache.catalina.valves

ValveBase

public abstract class ValveBase extends Object implements org.apache.catalina.Contained, org.apache.catalina.Valve, MBeanRegistration
Convenience base class for implementations of the Valve interface. A subclass MUST implement an invoke() method to provide the required functionality, and MAY implement the Lifecycle interface to provide configuration management and lifecycle support.
author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private static org.apache.juli.logging.Log
log
protected org.apache.catalina.Container
container
The Container whose pipeline this Valve is a component of.
protected org.apache.juli.logging.Log
containerLog
Container log
protected static String
info
Descriptive information about this Valve implementation. This value should be overridden by subclasses.
protected org.apache.catalina.Valve
next
The next Valve in the pipeline this Valve is a component of.
protected static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected String
domain
protected ObjectName
oname
protected MBeanServer
mserver
protected ObjectName
controller
Constructors Summary
Methods Summary
public voidbackgroundProcess()
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.

    
public javax.management.ObjectNamecreateObjectName(java.lang.String domain, javax.management.ObjectName parent)

        Container container=this.getContainer();
        if( container == null || ! (container instanceof ContainerBase) )
            return null;
        this.containerLog = container.getLogger();
        ContainerBase containerBase=(ContainerBase)container;
        Pipeline pipe=containerBase.getPipeline();
        Valve valves[]=pipe.getValves();

        /* Compute the "parent name" part */
        String parentName="";
        if (container instanceof Engine) {
        } else if (container instanceof Host) {
            parentName=",host=" +container.getName();
        } else if (container instanceof Context) {
                    String path = ((Context)container).getPath();
                    if (path.length() < 1) {
                        path = "/";
                    }
                    Host host = (Host) container.getParent();
                    parentName=",path=" + path + ",host=" +
                            host.getName();
        } else if (container instanceof Wrapper) {
            Context ctx = (Context) container.getParent();
            String path = ctx.getPath();
            if (path.length() < 1) {
                path = "/";
            }
            Host host = (Host) ctx.getParent();
            parentName=",servlet=" + container.getName() +
                    ",path=" + path + ",host=" + host.getName();
        }
        log.debug("valve parent=" + parentName + " " + parent);

        String className=this.getClass().getName();
        int period = className.lastIndexOf('.");
        if (period >= 0)
            className = className.substring(period + 1);

        int seq=0;
        for( int i=0; i<valves.length; i++ ) {
            // Find other valves with the same name
            if (valves[i] == this) {
                break;
            }
            if( valves[i]!=null &&
                    valves[i].getClass() == this.getClass() ) {
                log.debug("Duplicate " + valves[i] + " " + this + " " + container);
                seq++;
            }
        }
        String ext="";
        if( seq > 0 ) {
            ext=",seq=" + seq;
        }

        ObjectName objectName = 
            new ObjectName( domain + ":type=Valve,name=" + className + ext + parentName);
        log.debug("valve objectname = "+objectName);
        return objectName;
    
public voidevent(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response, org.apache.catalina.CometEvent event)
Process a Comet event. This method will rarely need to be provided by a subclass, unless it needs to reassociate a particular object with the thread that is processing the request.

param
request The servlet request to be processed
param
response The servlet response to be created
exception
IOException if an input/output error occurs, or is thrown by a subsequently invoked Valve, Filter, or Servlet
exception
ServletException if a servlet error occurs, or is thrown by a subsequently invoked Valve, Filter, or Servlet

        // Perform the request
        getNext().event(request, response, event);
    
public org.apache.catalina.ContainergetContainer()
Return the Container with which this Valve is associated, if any.



    //-------------------------------------------------------------- Properties


                    
       

        return (container);

    
public javax.management.ObjectNamegetContainerName()

        if( container== null) return null;
        return ((ContainerBase)container).getJmxName();
    
public javax.management.ObjectNamegetController()

        return controller;
    
public java.lang.StringgetDomain()

        return domain;
    
public java.lang.StringgetInfo()
Return descriptive information about this Valve implementation.


        return (info);

    
public org.apache.catalina.ValvegetNext()
Return the next Valve in this pipeline, or null if this is the last Valve in the pipeline.


        return (next);

    
public javax.management.ObjectNamegetObjectName()

        return oname;
    
public javax.management.ObjectNamegetParentName(javax.management.ObjectName valveName)
From the name, extract the parent object name

param
valveName The valve name
return
ObjectName The parent name


        return null;
    
public abstract voidinvoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)
The implementation-specific logic represented by this Valve. See the Valve description for the normal design patterns for this method.

This method MUST be provided by a subclass.

param
request The servlet request to be processed
param
response The servlet response to be created
exception
IOException if an input/output error occurs
exception
ServletException if a servlet error occurs

public voidpostDeregister()

    
public voidpostRegister(java.lang.Boolean registrationDone)

    
public voidpreDeregister()

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

        oname=name;
        mserver=server;
        domain=name.getDomain();


        return name;
    
public voidsetContainer(org.apache.catalina.Container container)
Set the Container with which this Valve is associated, if any.

param
container The new associated container


        this.container = container;

    
public voidsetController(javax.management.ObjectName controller)

        this.controller = controller;
    
public voidsetNext(org.apache.catalina.Valve valve)
Set the Valve that follows this one in the pipeline it is part of.

param
valve The new next valve


        this.next = valve;

    
public voidsetObjectName(javax.management.ObjectName oname)

        this.oname = oname;
    
public java.lang.StringtoString()
Return a String rendering of this object.

        StringBuffer sb = new StringBuffer(this.getClass().getName());
        sb.append("[");
        if (container != null)
            sb.append(container.getName());
        sb.append("]");
        return (sb.toString());