Valves
A Valve element represents a component that will be inserted into the request processing pipeline for the associated Catalina container (Engine, Host, or Context). Individual Valves have distinct processing capabilities. Valves simply provide ways of inserting custom functionality within the Tomcat request/response stream.
In WSO2 products, users can either extend the generic org.apache.catalina.valve.ValveBase abstract class in Tomcat or the Carbon-specific org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve in order to create a custom valve. See the Tomcat Valve documentation for further information on the Tomcat-specific valve implementation.
Sample Valve
public class CarbonSimpleValve extends ValveBase { public CarbonSimpleValve() { //enable async support super(true); } @Override public void invoke(Request request, Response response) throws IOException, ServletException { //valve specific logic } }
The following valves are available in Carbon Kernel:
org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve
org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve
org.wso2.carbon.tomcat.ext.valves.SecureTheWorldValve
org.wso2.carbon.tomcat.ext.valves.CarbonTomcatSessionReplicationValve
org.wso2.carbon.webapp.mgt.GhostWebappDeployerValve
org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve
If you implement your own Valve by extending the CarbonTomcatValve, you need to add that to the Valve pipe using the TomcatValveContainer. The value needs to be added to the Engine, Host or to the Context. Adding a Host level valve in the <PRODUCT_HOME>/repository/conf/tomcat/catalina-server.xml
file.
<Server> <Service> <Engine> <Host> ….. <Valve className="org.wso2.carbon.sample.CarbonSimpleValve"/> ….. </Host> </Engine> </Service> </Server>