Java Reference
In-Depth Information
In addition to creating new interceptor bindings with additional interceptor bindings, the
beans themselves may annotate several interceptor bindings. For example, you can audit,
profile, and keep statistics on the addBid() method by adding those annotations to
BidService :
@Stateless
@Audited
public class BidService {
@Profiled @Statistics
public void addBid(Bid bid) {
bidDao.addBid(bid);
}
...
}
BidService is annotated in such a way that every method in BidService will be
audited because @Audited is annotated at the class level. In addition to being audited,
statistics will be collected on calls to addBid() by @Statistics , and the addBid()
method will also be profiled by @Profiled . Again, the listing of the interceptors in
beans.xml determines the interceptor execution order.
Binding multiple interceptors to a bean is fairly straightforward. The bindings are associ-
ated with one or more interceptors, so there's a collection of interceptor calls before getting
to the bean's method. Interceptors themselves may be bound to multiple bindings as well,
and when interceptors have multiple bindings, it really changes how they get executed. The
best way to explain this is with an example. Suppose ActionBazaar secure business pro-
cesses require additional auditing. The auditing provided by @Audited is good, but more
is needed. To fulfill this requirement, a new interceptor is created:
@Secured @Audited @Interceptor
public class SecuredAuditedInterceptor {
@AroundInvoke
public Object extraAudit(InvocationContext context)
throws Exception {
...
return context.proceed();
}
}
This interceptor has multiple bindings. It's bound to both @Secured and @Audited .
This means that this interceptor will only be called if both the @Secured and @Audited
are applied to the method. If you go back and look at removeBid() , you'll see that it
Search WWH ::




Custom Search