Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

Chapter 21. Interceptors

JBoss EAP messaging supports interceptors to intercept packets entering and exiting the server. Incoming and outgoing interceptors are called for every packet entering or exiting the server respectively. This allows custom code to be executed, such as for auditing or filtering packets. Interceptors can modify the packets they intercept. This makes interceptors powerful, but also potentially dangerous.

21.1. Implementing Interceptors

An interceptor must implement the Interceptor interface:

package org.apache.artemis.activemq.api.core.interceptor;

public interface Interceptor
{
   boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException;
}

The returned boolean value is important:

  • if true is returned, the process continues normally
  • if false is returned, the process is aborted, no other interceptors will be called and the packet will not be processed further by the server.

Interceptor classes should be added to JBoss EAP as a module. See Create a Custom Module in the JBoss EAP Configuration Guide for more information.

21.2. Configuring Interceptors

After adding their module to JBoss EAP as a custom module, both incoming and outgoing interceptors are added to the messaging subsystem configuration by using the management CLI.

Note

You must start JBoss EAP in administrator only mode before the new interceptor configuration will be accepted. See Running JBoss EAP in Admin-only Mode in the JBoss EAP Configuration Guide for details. Restart the server in normal mode after the new configuration is processed.

Each interceptor should be added according to the example management CLI command below. The examples assume each interceptor has already been added to JBoss EAP as a custom module.

/subsystem=messaging-activemq/server=default:list-add(name=incoming-interceptors, value={name => "foo.bar.MyIncomingInterceptor", module=>"foo.bar.interceptors"})

Adding an outgoing interceptor follows a similar syntax, as the example below illustrates.

/subsystem=messaging-activemq/server=default:list-add(name=outgoing-interceptors, value={name => "foo.bar.MyOutgoingInterceptor", module=>"foo.bar.interceptors"})