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 {
@Resource
private EJBContext context;
@AroundInvoke
protected Object audit(InvocationContext ctx) throws Exception {
Principal principal = context.getCallerPrincipal();
if (userIsValid(principal)) {
// Complete code for logging
}else{
// Complete code for logging and exception handling
}
return ctx.proceed();
}
}
To use this interceptor put an annotation on the designated EJB, for example
@Interceptors(InterceptorHandler.class)
@Stateless
public class TestBean {
// Complete code here
}
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 {
@Resource
private EJBContext context;
@AroundInvoke
protected Object audit(InvocationContext ctx) throws Exception {
Principal principal = context.getCallerPrincipal();
if (userIsValid(principal)) {
// Complete code for logging
}else{
// Complete code for logging and exception handling
}
return ctx.proceed();
}
}
To use this interceptor put an annotation on the designated EJB, for example
@Interceptors(InterceptorHandler.class)
@Stateless
public class TestBean {
// Complete code here
}
I heve read your blog it's very interesting and informative. Keep sharing.
ReplyDeleteerp providers in chennai | erp software solutions in chennai
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.
ReplyDeleteI found a lot of interesting information here. A really good post
ReplyDeleteoffice 2011 mac download deutsch
amazing
ReplyDeletejobbörse Neunkirchen
,