views:

99

answers:

1

Hi,

I wrote a custom Tomcat valve. (I'm using Tomcat 6.0.24 and Java 1.6) Here's the XML element where I declare my valve:

<Valve className="mypkg.MyValve"  foo="bar"/>

When I put this declaration inside server.xml's Host element. Tomcat calls the setFoo() method on my valve with the value "bar". That's what I want to happen.

However, when I put this same declaration in my webapp's META-INF/context.xml, inside the Context element, Tomcat loads the valve and the valve runs fine. But Tomcat never calls the setFoo() method to provide the "bar" value the valve needs.

I'm don't understand why Tomcat properly configures a valve declared in server.xml but not in context.xml.

Does anyone know how I can get Tomcat to properly configure my valve when it's declared in my webapp's META-INF/context.xml?

Thanks, Dan

This causes my valve to load and be properly configured by Tomcat:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"
   xmlValidation="false" xmlNamespaceAware="false">

    <Valve className="mypkg.MyValve"  foo="bar"/>
</Host>

This causes my valve to load, but Tomcat won't give it the config parameter "bar":

<Context privileged="true" >
    <Valve className="mypkg.MyValve"  foo="bar"/>
</Context>
A: 

This is my researched guess. It could be that your Valve is bound to the Host container ?

Is your custom valve directly subclassing org.apache.catalina.valves.ValveBase ? If so, it should have worked.

You could try and print out the getContainer() on your Valve from both your settings to see if it correctly identifies which of the Catalina containers (Engine, Host, Context) it is set at each time.

Certain Valves like SingleSignOn are bound to a container like Host which means it wont work on others. This will apply to subclassed Valves too.

JoseK