package mypackage;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class CallerInterceptor {

	UserService service = null;

	private Context context;

	public CallerInterceptor() {
		try {

			context = new InitialContext();

			service = (UserService) context.lookup("ejb:AppA/EJBA/UserServiceBean!mypackage.UserService");
			System.out.println("UserService is found : " + service.toString());
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("In caller");
	}

	@AroundInvoke
	public Object filter(InvocationContext ic) throws Exception {
		service.target();
		return ic.proceed();
	}
}
