trouble with static pointcuts 2.0

View: New views
3 Messages — Rating Filter:   Alert me  

trouble with static pointcuts 2.0

by Michael Wyszinski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

 

All, I have several aspects running correctly in weblogic but, having trouble advising a certain static method, I’ve tried several diff pointcut definitions but it never works on this particular class. It has worked on a similar non-static method….Any help to debug this would be appreciated

 

Here are the details

 

=====================================================

XML def

=====================================================

 

       <!-- Aspect to capture username in trxns-->
     <aspect class="GetUserAspect" deployment-model="perInstance">
           <pointcut name="SetUser" expression="execution(public static void com.xxx.core.audit.Log.setUser(..))"/>
           <advice name="storeUserName(StaticJoinPoint jp)" type="after returning" bind-to="SetUser"/>
           <param name="test" value="i got loaded"/>
     </aspect>

 

=====================================================

target

=====================================================

 

package com.xxx.core.audit;

 

public class Log
{
 public static void setUser(String message)
 {stuff…}

}

 

=====================================================

Aspect clas

=====================================================

 

import org.codehaus.aspectwerkz.AspectContext;
import org.codehaus.aspectwerkz.joinpoint.*;

 


public class GetUserAspect{
     private static ThreadLocal userName = new ThreadLocal();
    private AspectContext myAspectContext = null;
   
     public NextgenGetUserAspect(AspectContext ac){
     myAspectContext = ac;
    System.out.println("test init->" + myAspectContext.getParameter("test"));
     } 

 

  public static void setUserName(String name) {
  userName.set(name);
 }
 public static String getUserName() {
  return (String) userName.get();
 }
 public Object storeUserName(StaticJoinPoint  joinPoint) throws Throwable {
  System.out.println("NextgenMonitoring SET USERNAME ");
  return null;
 }

 

}

 


Re: trouble with static pointcuts 2.0

by Alexandre Vasseur :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

an "after returning" joinpoint kind on a "void method(stuff)" will likely not match

use simply after perhaps


On Nov 7, 2007 10:36 PM, Michael Wyszinski <mike.wyszinski@...> wrote:

 

All, I have several aspects running correctly in weblogic but, having trouble advising a certain static method, I've tried several diff pointcut definitions but it never works on this particular class. It has worked on a similar non-static method….Any help to debug this would be appreciated

 

Here are the details

 

=====================================================

XML def

=====================================================

 

       <!-- Aspect to capture username in trxns-->
     <aspect class="GetUserAspect" deployment-model="perInstance">
           <pointcut name="SetUser" expression="execution(public static void com.xxx.core.audit.Log.setUser(..))"/>
           <advice name="storeUserName(StaticJoinPoint jp)" type="after returning" bind-to="SetUser"/>
           <param name="test" value="i got loaded"/>
     </aspect>

 

=====================================================

target

=====================================================

 

package com.xxx.core.audit;

 

public class Log
{
 public static void setUser(String message)
 {stuff…}

}

 

=====================================================

Aspect clas

=====================================================

 

import org.codehaus.aspectwerkz.AspectContext;
import org.codehaus.aspectwerkz.joinpoint.*;

 


public class GetUserAspect{
     private static ThreadLocal userName = new ThreadLocal();
    private AspectContext myAspectContext = null;
   
     public NextgenGetUserAspect(AspectContext ac){
     myAspectContext = ac;
    System.out.println("test init->" + myAspectContext.getParameter("test"));
     } 

 

  public static void setUserName(String name) {
  userName.set(name);
 }
 public static String getUserName() {
  return (String) userName.get();
 }
 public Object storeUserName(StaticJoinPoint  joinPoint) throws Throwable {
  System.out.println("NextgenMonitoring SET USERNAME ");
  return null;
 }

 

}

 



RE: trouble with static pointcuts 2.0

by Michael Wyszinski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Thx for the reply, in the end I got it working by changing the deployment-model to perJVM.

 

No Instance of com.xxx.core.audit.Log is ever created (it’s a static singleton ) so maybe the aspect could never get bind wih the perinstance setting?

Just a guess on my part….

Here is the working xml snippet

 

       <!-- Aspect to capture username in trxns-->
     <aspect class="GetUserAspect" deployment-model="perInstance">
           <pointcut name="SetUser" expression="execution(* void com.xxx.core.audit.Log.setUser(..))"/>
           <advice name="storeUserName(StaticJoinPoint jp)" type="after returning" bind-to="SetUser"/>     </aspect>

 

 


From: Alexandre Vasseur [mailto:avasseur@...]
Sent: Thursday, November 08, 2007 4:39 PM
To: user@...
Subject: Re: [aspectwerkz-user] trouble with static pointcuts 2.0

 

an "after returning" joinpoint kind on a "void method(stuff)" will likely not match

use simply after perhaps

On Nov 7, 2007 10:36 PM, Michael Wyszinski <mike.wyszinski@...> wrote:

 

All, I have several aspects running correctly in weblogic but, having trouble advising a certain static method, I've tried several diff pointcut definitions but it never works on this particular class. It has worked on a similar non-static method….Any help to debug this would be appreciated

 

Here are the details

 

=====================================================

XML def

=====================================================

 

       <!-- Aspect to capture username in trxns-->
     <aspect class="GetUserAspect" deployment-model="perInstance">
           <pointcut name="SetUser" expression="execution(public static void com.xxx.core.audit.Log.setUser(..))"/>
           <advice name="storeUserName(StaticJoinPoint jp)" type="after returning" bind-to="SetUser"/>
           <param name="test" value="i got loaded"/>
     </aspect>

 

=====================================================

target

=====================================================

 

package com.xxx.core.audit;

 

public class Log
{
 public static void setUser(String message)
 {stuff…}

}

 

=====================================================

Aspect clas

=====================================================

 

import org.codehaus.aspectwerkz.AspectContext;
import org.codehaus.aspectwerkz.joinpoint.*;

 


public class GetUserAspect{
     private static ThreadLocal userName = new ThreadLocal();
    private AspectContext myAspectContext = null;
   
     public NextgenGetUserAspect(AspectContext ac){
     myAspectContext = ac;
    System.out.println("test init->" + myAspectContext.getParameter("test"));
     } 

 

  public static void setUserName(String name) {
  userName.set(name);
 }
 public static String getUserName() {
  return (String) userName.get();
 }
 public Object storeUserName(StaticJoinPoint  joinPoint) throws Throwable {
  System.out.println("NextgenMonitoring SET USERNAME ");
  return null;
 }

 

}