Creating your own valve is really simple using NetBeans 7.2.1 along with Apache Maven.
- Create a Maven Java Application.
- Add the following dependency:
- Create your Java class and extend it from ValveBase.
- Implement
invoke(Request request, Response response)
- Build your library (.jar) file
- Install the library in the ${tomcat.home}/lib directory.
- Configure
server.xml
to use your new Valve. For example:
- Start the server to see your new valve in action
ProcessingValve.java
Here is the output...INFO: Server startup in 1442 ms Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke INFO: Header --> host Value --> localhost:8080 Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke INFO: Header --> host Value --> localhost:8080 Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke INFO: Header --> host Value --> localhost:8080 Dec 27, 2012 5:54:01 PM com.bluelotussoftware.tomcat.ProcessingValve invoke INFO: Header --> host Value --> localhost:8080
As you can see it was very easy to implement. Here is the code for my example: valve-example.zip
The source can also be found on Bitbucket: valve-example
2 comments :
Forgive my ignorance, but is used for valve?.
-------------------------------------
Perdona mi ignorancia, pero para que se usa una valve?.
That is a great question. Valves are used in a similar way that filters are used for servlets, but in this case it applies to the Apache Tomcat. One valve is the SingleSignOn which supports SSO on Tomcat, another is the RequestFilterValve which is used to control allow/deny access to the tomcat instance. Please see the API for more details: http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/ValveBase.html
Post a Comment