EJB Intercepts

EJB3 offers the ability to intercept EJB business methods by using AroundInvoke interceptors.

From this you can access the method name, the parameters passed, and the EJB context.

This is useful for

1. Performing security checks
2. Performing audits
3. Changing the values of method parameters in your Java EE applications using EJB interceptors

Here is a simple EJB interceptor:

public class InterceptorHandler {

 private EJBContext context;

protected Object audit(InvocationContext ctx) throws Exception {
    Principal principal = context.getCallerPrincipal();
    if (userIsValid(principal)) {
  // Complete code for logging
  // Complete code for logging and exception handling
    return ctx.proceed();
To use this interceptor put an annotation on the designated EJB, for example

public class TestBean {
  // Complete code here


  1. I heve read your blog it's very interesting and informative. Keep sharing.
    erp providers in chennai | erp software solutions in chennai

  2. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. erp in chennai.

  3. I found a lot of interesting information here. A really good post
    office 2011 mac download deutsch


Post a Comment

Popular posts from this blog

ActiveMQ, easy to use open source message oriented middleware (MOM)

Basic Send Message to MQ with Java and IBM MQ JMS

Apache Apollo