org.axonframework.auditing
Class AuditingInterceptor

java.lang.Object
  extended by org.axonframework.auditing.AuditingInterceptor
All Implemented Interfaces:
CommandHandlerInterceptor

public class AuditingInterceptor
extends Object
implements CommandHandlerInterceptor

Interceptor that keeps track of commands and the events that were dispatched as a result of handling that command. The AuditingInterceptor uses the current Unit Of Work to track all events being stored and published. The auditing information provided by the AuditDataProvider is attached to each of these events just before the Unit Of Work is committed. After the Unit Of Work has been committed, an optional AuditLogger may write an entry to the audit logs.

Note that this class requires a Unit Of Work to be available. This means that you should always configure a Unit Of Work interceptor before the AuditingInterceptor. Failure to do so will result in an AxonConfigurationException.

The auditing interceptor can only attach meta data to event whose Message.getMetaData() methods returns an instance of MetaData, which is the default behavior for any event implementation provided by Axon.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AuditingInterceptor()
           
 
Method Summary
 Object handle(CommandMessage<?> command, UnitOfWork unitOfWork, InterceptorChain chain)
          The handle method is invoked each time a command is dispatched through the command bus that the CommandHandlerInterceptor is declared on.
 void setAuditDataProvider(AuditDataProvider auditDataProvider)
          Sets the AuditingDataProvider for this interceptor.
 void setAuditLogger(AuditLogger auditLogger)
          Sets the logger that writes events to the audit logs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditingInterceptor

public AuditingInterceptor()
Method Detail

handle

public Object handle(CommandMessage<?> command,
                     UnitOfWork unitOfWork,
                     InterceptorChain chain)
              throws Throwable
Description copied from interface: CommandHandlerInterceptor
The handle method is invoked each time a command is dispatched through the command bus that the CommandHandlerInterceptor is declared on. The incoming command and contextual information can be found in the given unitOfWork.

The interceptor is responsible for the continuation of the dispatch process by invoking the InterceptorChain.proceed(CommandMessage) method on the given interceptorChain.

Any information gathered by interceptors may be attached to the unitOfWork. This information is made available to the CommandCallback provided by the dispatching component.

Interceptors are highly recommended not to change the type of the command handling result, as the dispatching component might expect a result of a specific type.

Specified by:
handle in interface CommandHandlerInterceptor
Parameters:
command - The command being dispatched
unitOfWork - The UnitOfWork in which
chain - The interceptor chain that allows this interceptor to proceed the dispatch process
Returns:
the result of the command handler. May have been modified by interceptors.
Throws:
Throwable - any exception that occurs while handling the command

setAuditDataProvider

public void setAuditDataProvider(AuditDataProvider auditDataProvider)
Sets the AuditingDataProvider for this interceptor. Defaults to the EmptyDataProvider, which provides no correlation information.

Parameters:
auditDataProvider - the instance providing the auditing information to attach to the events.

setAuditLogger

public void setAuditLogger(AuditLogger auditLogger)
Sets the logger that writes events to the audit logs. Defaults to the NullAuditLogger, which does nothing.

Parameters:
auditLogger - the logger that writes events to the audit logs


Copyright © 2010-2016. All Rights Reserved.