Custom Tomcat Valve Configuration

I wrote a special Tomcat valve. (I am using Tomcat 6.0.24 and Java 1.6) Here is the XML element where I declare my valve:

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

When I put this ad in the Host.xml element of Host.xml. Tomcat calls the setFoo () method on my valve with a value of "bar". This is what I want.

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

I don’t understand why Tomcat correctly configures the valve specified in server.xml, but not in the .xml context.

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

Thanks Dan

This causes my valve to load and configure Tomcat correctly:

 <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 will not give it the configuration parameter "bar":

 <Context privileged="true" > <Valve className="mypkg.MyValve" foo="bar"/> </Context> 
+4
source share
2 answers

This is my research. Maybe your Valve bound to a Host container?

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

You can try printing getContainer() on your valve from both settings to make sure that it correctly identifies which of the Catalina Containers (Engine, Host, Context) it is installed each time.

Some valves, such as SingleSignOn , are tied to a container like Host , which means that it will not work on others. This also applies to Valves subclasses.

+3
source

SetPropertiesRule, as part of the launch, will try to find getters for your custom properties.

0
source

All Articles