Este contenido no está disponible en el idioma seleccionado.
4.6. Create a Custom Valve
Procedure 4.3. Create a Custom Valve
Configure the Maven dependencies.
Add the following dependency configuration to the projectpom.xml
file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note
Thejbossweb-VERSION.jar
file should not be included in the application. It is available to the JBoss EAP server runtime classpath as a JBoss module at this location:EAP_HOME/modules/system/layers/base/org/jboss/as/web/main/jbossweb-7.5.7.Final-redhat-1.jar
.Create the Valve class
Create a subclass oforg.apache.catalina.valves.ValveBase
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Implement the invoke method.
Theinvoke()
method is called when this valve is executed in the pipeline. The request and response objects are passed as parameters. Perform any processing and modification of the request and response here.public void invoke(Request request, Response response) { }
public void invoke(Request request, Response response) { }
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Invoke the next pipeline step.
The last thing the invoke method must do is invoke the next step of the pipeline and pass the modified request and response objects along. This is done using thegetNext().invoke()
methodgetNext().invoke(request, response);
getNext().invoke(request, response);
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Specify parameters.
If the valve must be configurable, enable this by adding a parameter. Do this by adding an instance variable and a setter method for each parameter.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Review the completed code example.
The class should now look like the following example.Example 4.4. Sample Custom Valve
Copy to Clipboard Copied! Toggle word wrap Toggle overflow