[jboss-user] [JBoss AOP] - I'm in trouble....help

Giordacchio++ do-not-reply at jboss.com
Mon Nov 6 12:50:34 EST 2006


Hi, I'm trying to use Jboss AOP within Jboss AS.
I've already tried to deploy the "Booking" example of Jboss seam (and it works) and the "Inboss" example of Jboss AOP (and it works too).

Now I've written an annotation bound to intercept a login method inside the Booking app.

the annotation interface is:


  | @Retention(RetentionPolicy.RUNTIME)
  | @Target({ElementType.METHOD})
  | public @interface Logger {
  | 	
  | 	Label label() default Label.WARNING;
  | 	String body() default "";
  | }
  | 

the Aspect bound to the annotation is:
@Aspect(scope = org.jboss.aop.advice.Scope.PER_JOINPOINT)
  | public class LoggerAspect {
  | 	
  | 	
  | 	
  | 	
  | 	public LoggerAspect() throws FileNotFoundException
  | 	{
  | 		System.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
  | 	}
  | 	
  | 	
  | 	@PointcutDef("execution( static void *->@logger.Logger(..))  ")
  | 	public static Pointcut mypoint;
  | 	
  | 	
  | 	
  | 	@Bind (pointcut="logger.LoggerAspect.mypoint")
  | 	public Object logger(MethodInvocation invocation) throws Throwable
  | 	{
  | 		
  | 		Logger Lg = (Logger) Invocation.resolveAnnotation(Logger.class);
  | 			
  | 		String s="\n<EVENT>\n\t"+ "<"+Lg.label()+">\n\t\t" +Lg.body()+"\n\t<\\"+Lg.label()+">" +"\n<\\EVENT>";
  | 	    
  | 		invocation.invokeNext();
  | 		
  | 		System.out.println(s);
  | 		return null;
  | 	}
  | 	
  | 
  | }

Using the annotation Bind let me free to don't use the jboss-aop.xml file.
Now I've inserted my new annotation on the login EJB:

@Stateless
  | @Name("login")
  | public class LoginAction implements Login
  | {
  |    
  |    @In @Out
  |    private User user;
  |    
  |    @PersistenceContext
  |    private EntityManager em;
  | 
  |    @Logger(label = Label.WARNING,body="evento XXXXX")
  |    public String login()
  |    {
  |       List<User> results = em.createQuery("select u from User u where u.username=:username and u.password=:password")
  |             .setParameter("username", user.getUsername())
  |             .setParameter("password", user.getPassword())
  |             .getResultList();
  |       
  |       if ( results.size()==0 )
  |       {
  |          FacesMessages.instance().add("Invalid login");
  |          return "login";
  |       }
  |       else
  |       {
  |          user = results.get(0);
  |          Contexts.getSessionContext().set("loggedIn", true);
  |          FacesMessages.instance().add("Welcome, #{user.name}");
  |          return "main";
  |       }
  |       
  |    }
  | 
  | }
  | 

By the way inside my annotation I use a ENUM like the following:

  | public enum Label
  | {
  | 	WARNING,
  | 	DEBUG,
  | 	ERROR
  | }


So...why it doesn't work ?? I don't see any result...I know that the println should appear on the log.....the Booking app works but there is no interception !!!

Hellllpppp I'm going crazy.....
Thx

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983507#3983507

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983507



More information about the jboss-user mailing list