-
1. Re: Adding a Tomcat Valve Via An MBean?
jiwils Oct 25, 2005 3:07 PM (in response to jiwils)It looks like JBoss deploys valves in semi-dynamic fashion since the tomcat5-service.jar contains Tomcat MBean descriptor XML files. I am unsure how these are getting deployed however. I tried mocking up my own JAR with a descriptor for a valve and placed it in the jbossweb-tomcat55.sar directory, but I had no luck with that. I also tried using the Listener concept in server.xml as described by http://tomcat.apache.org/tomcat-5.0-doc/mbeans-descriptor-howto.html to refer to the same mock JAR's descriptor, but that did not seem to make a difference. Am I approaching this the correct way?
-
2. Re: Adding a Tomcat Valve Via An MBean?
starksm64 Dec 5, 2005 1:48 PM (in response to jiwils)Valves can be deployed via the tomcat sar context.xml as well as war level WEB-INF/context.xml descriptors.
http://wiki.jboss.org/wiki/Wiki.jsp?page=CustomizingSecurityUsingValves -
3. Re: Adding a Tomcat Valve Via An MBean?
jofree Jun 21, 2006 2:34 PM (in response to jiwils)I've been able to achieve this by binding to the MBean that represents the Host and calling the Pipeline.addValve() method as shown here:
ObjectName objectName = null; Object resource = null; Valve someValve = (Valve) new SomeValve(); try { objectName = new ObjectName("jboss.web:type=Host,host=localhost"); resource = (Object) server.getAttribute(objectName, "managedResource"); if (resource != null && someValve != null) { StandardHost standardHost = (StandardHost) resource; standardHost.getPipeline().addValve(someValve); } else { //TODO Error Checking } } catch (Exception e) { //TODO Error Checking }
My MBean instanceates the valve in the start() lifecycle method and keeps a reference to it so it can also call removeValve in the same fashion in the stop lifecycle method. This way the valve is installed when the SAR (or MBean) is deployed and uninstalled when the SAR is undeployed. Of course this can also be controlled via the JMX console as well.
I did have to do a couple of other tricks... I had to move this code into a utility class to avoid class loader issues (namely Valve and ValveBase aren't available until Tomcat has started). I also had to set up a BarrierController on Tomcat so I can make my MBean depend on Tomcat starting.
Hope this helps,
Josh Freeman