Writing a custom valve for Jboss EAP 6

Jboss provides a way to intercept all web requests before they are dispatched to appropriate contexts.

Valve is a component that will be inserted into the request processing pipeline.

You can configure a valve ( Jboss provides a number of valves which you can use according to your need ) in the standalone.xml in the following section.

<subsystem xmlns="urn:jboss:domain:web:1.4" default-virtual-server="default-host" native="false">
   <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
   <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
   <valve name="myvalve" module="org.jboss.web-valves" class-name="org.apache.catalina.valves.AccessLogValve">

You can also write a custom valve to suit your requirement.

You need in extend the ValveBase class in order to do so, and then implement the invoke method.


package org.apache.catalina.valves;

import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;

public class CustomValve extends ValveBase {

   public void invoke(Request request, Response response) 
                         throws IOException, ServletException{
      // Add custom logic here
      getNext().invoke(request, response);

Then package this into a jar and add this as a module in the modules subsystem in jboss.

├── jboss-eap
└── modules
└── system
└── layers
└── base
└── org
└── jboss
└── web-valves
└── main
└── valves.jar
└── modules.xml
Posted in Java Tagged with: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

Hit Counter provided by technology news