How to enable valve in JBoss EAP 6
Environment
- JBoss Enterprise Application Platform (EAP) 6.x
Issue
-
How do I enable a valve in JBoss EAP 6?
-
In previous versions of JBoss it was possible to configure Tomcat Valves by adding jar to
$JBOSS_HOME/server/$PROFILE/libandsetting in: - JBoss EAP 4.x:
$JBOSS_HOME/server/$PROFILE/deploy/jboss-web.deployer/server.xml
or$JBOSS_HOME/server/$PROFILE/deploy/jboss-web.deployer/context.xml
- JBoss EAP 5.x:
$JBOSS_HOME/server/$PROFILE/deploy/jbossweb.sar/server.xml
or$JBOSS_HOME/server/$PROFILE//deploy/jbossweb.sar/context.xml
How can the same be achieved in JBoss EAP 6.x?
- JBoss EAP 4.x:
-
We have a customised Valve class to whitelist specific paths in a request. Is it possible to make our application dependent on this module instead of loaded as global module?
Resolution
Global Valves are not supported in EAP 6.0.x. Upgrade to EAP 6.1 or higher to use them.
Valves on a per application basis (for all versions of EAP 6.x) are configured in jboss-web.xml:
<jboss-web>
...(snip)...
<valve>
<class-name>com.redhat.jboss.support.MyCustomValve</class-name>
<param>
<param-name>somename</param-name>
<param-value>somevalue</param-value>
</param>
</valve>
...(snip)...
</jboss-web>
Starting from EAP 6.1, global valves can be configured by the following steps:
Create a custom module for your valve using this CLI command:
module add --name=com.redhat.jboss.support.MyCustomValve --resources=/path/to/MyCustomValve.jar --dependencies=sun.jdk,javax.servlet.api,org.jboss.as.web,org.jboss.logging
This will result in the following directory structure:
$JBOSS_HOME/modules/com/redhat/jboss/support/MyCustomValve/main/MyCustomValve.jar
$JBOSS_HOME/modules/com/redhat/jboss/support/MyCustomValve/main/module.xml
module.xml will contain:
<module xmlns="urn:jboss:module:1.1" name="com.redhat.jboss.support.MyCustomValve">
<resources>
<resource-root path="MyCustomValve.jar"/>
</resources>
<dependencies>
<module name="sun.jdk"/>
<module name="javax.servlet.api"/>
<module name="org.jboss.as.web"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
Add the valve to the web subsystem. Prefix the "cd" command with /profile=myprofile when in domain mode:
cd /subsystem=web
./valve=MyCustomValve:add(class-name=com.redhat.jboss.support.MyCustomValve,module=com.redhat.jboss.support.MyCustomValve,enabled=false)
./valve=MyCustomValve:add-param(param-name=somename,param-value=somevalue)
./valve=MyCustomValve:write-attribute(name=enabled,value=true)
/:reload
This results in a valve entry in the web subsystem:
<valve name="MyCustomValve" module="com.redhat.jboss.support.MyCustomValve"
class-name="com.redhat.jboss.support.MyCustomValve" enabled="true">
<param param-name="somename" param-value="somevalue"/>
</valve>
More information can be found in the This content is not included.documentation on global valves
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.