Java Reference
In-Depth Information
• Apply the audit trailing transparently on the business service.
• The audit trailing must be configurable.
• Allow an audit trace of requests, responses, and exceptions raised from a service.
Implement a centralized audit interceptor that can be declaratively used to apply the
auditing of the business service invocations.
Strategies with the Spring Framework
You can easily develop an audit interceptor with Spring AOP support. With AOP, you can
build the audit trail component as an independent reusable component and then apply
it transparently with configuration. Since the audit interceptor needs to support the pre-
and postprocessing of methods along with the exceptions, the first step to building the
interceptor is to develop an advice . An advice denotes a reusable piece of code that can
be applied transparently to the actual application code. Since the SLSBs are container-
managed components, I will apply the interceptor on the application service POJOs.
Listing 6-17 shows the audit interceptor advice.
Listing 6-17.
public class AuditAdviseInterceptor implements MethodInterceptor {
private AuditRules rules;
private boolean auditOn = true;
private AuditLog auditLog;
public Object invoke(MethodInvocation invocation) throws Throwable {
Object returnVal = null;
String eventCode = "";
Object arguments[] = null;
try {
returnVal = invocation.proceed();
} catch (Exception exp) {
Search WWH ::

Custom Search