If a business method has two or more interceptors, then it is possible for interceptors to pass data between each other within the same business method invocation. This is done using the InvocationContext.getContextData()
method. This method returns a Map
object containing the data passed between the interceptors. This is best illustrated with an example.
As the Auditor
class interceptor is fired first for any business method invocation, we will get this interceptor to send a message to any subsequent interceptors in the chain. The message merely indicates that the Auditor
was the first interceptor in the chain. The code below shows the modified version of Auditor
:
public class Auditor { @PersistenceContext(unitName="BankService") private EntityManager em; public Object audit(InvocationContext invctx) throws Exception { String className = invctx.getClass().getName(); String methodName = invctx.getMethod().getName(); Formatter fmt = new Formatter(); Calendar cal...