Java Reference
In-Depth Information
an intercepted method. In this case, we check that the names of candidates start
with Sir , if this is not the case, it is added.
The following code is an example of a session bean containing interceptors:
@Stateless
public class StudentSessionBean {
private Logger logger = Logger.getLogger(
"studentSessionBean.targetClassInterceptor");
public Student createEntity(Student std){
logger.info("createEntity-Name of the
student :"+std.getFirstname());
return std;
}
@AroundInvoke
public Object
targetClassMethodInterceptor(InvocationContext
ctx) throws Exception{
logger.info("targetClassMethodInterceptor -
method :"+ctx.getMethod().getName()+", "
+ "parameters :
"+Arrays.toString(ctx.getParameters())+", date:
"+new Date());
if(ctx.getMethod().getName().equals("createEntity")){
Student std = (Student)
ctx.getParameters()[0];
logger.info("targetClassMethodInterceptor
-Name of student before : "+std.getFirstname());
if(!std.getFirstname().startsWith("Sir")){
std.setFirstname("Sir
"+std.getFirstname());
}
}
Search WWH ::




Custom Search