RE: [aspectwerkz-user] trouble with static pointcuts 2.0

"Michael Wyszinski" <[email protected]> Thu, 8 Nov 2007 16:44:16 -0500
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <003701c82250$83693f60$6601a8c0@mike>
------=_NextPart_000_0038_01C82226.9A933760
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

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:[email protected]] 
Sent: Thursday, November 08, 2007 4:39 PM
To: [email protected]
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 < [email protected]
<mailto:[email protected]> > 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;
 }

 

}

 

 


------=_NextPart_000_0038_01C82226.9A933760
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:blue;
	text-decoration:underline;}
p
	{mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dblue>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Thx for the reply, in the end I got =
it
working by changing the </span></font><font size=3D2 face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>deployment-model to perJVM. =
<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>No Instance of <b><span =
style=3D'font-weight:bold'>com.xxx.core.audit.Log</span></b>
is ever created (it&#8217;s a static singleton ) so maybe the aspect =
could never get bind
wih the perinstance setting?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Just a guess on my part&#8230;.<font =
color=3Dnavy><span
style=3D'color:navy'><o:p></o:p></span></font></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Here is the working xml =
snippet<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;
&lt;!-- Aspect to capture username in trxns--&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;aspect =
class=3D&quot;GetUserAspect&quot;
deployment-model=3D&quot;perInstance&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;pointcut
name=3D&quot;SetUser&quot; expression=3D&quot;execution(<b><span =
style=3D'font-weight:
bold'>* void =
com.xxx.core.audit.Log.setUser(..)</span></b>)&quot;/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;advice
name=3D&quot;storeUserName(StaticJoinPoint jp)&quot; type=3D&quot;after
returning&quot; =
bind-to=3D&quot;SetUser&quot;/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/aspe=
ct&gt;</span></font><o:p></o:p></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>

</span></font></div>

<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'> =
Alexandre
Vasseur [mailto:[email protected]] <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Thursday, November =
08, 2007
4:39 PM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> =
[email protected]<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Re: =
[aspectwerkz-user]
trouble with static pointcuts 2.0</span></font><o:p></o:p></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'margin-bottom:12.0pt'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>an &quot;after =
returning&quot;
joinpoint kind on a &quot;void method(stuff)&quot; will likely not =
match<br>
<br>
use simply after perhaps<br>
<br>
</span></font><o:p></o:p></p>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>On Nov 7, 2007 10:36 PM, Michael Wyszinski &lt;<a
href=3D"mailto:[email protected]"> =
[email protected]</a>&gt; wrote:<o:p></o:p></span></font></p>

<div link=3Dblue vlink=3Dpurple>

<div>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>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&#8230;.Any help to debug this would be =
appreciated</span></font><o:p></o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;</span></font><o:p></o=
:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Here
are the details</span></font><o:p></o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;</span></font><o:p></o=
:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>XML
def</span></font><o:p></o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;</span></font><o:p></o=
:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;
&lt;!-- Aspect to capture username in trxns--&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;aspect =
class=3D&quot;GetUserAspect&quot;
deployment-model=3D&quot;perInstance&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;pointcut
name=3D&quot;SetUser&quot; expression=3D&quot;execution(<b><span =
style=3D'font-weight:
bold'>public static void =
com.xxx.core.audit.Log.setUser(..)</span></b>)&quot;/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;advice
name=3D&quot;storeUserName(StaticJoinPoint jp)&quot; type=3D&quot;after
returning&quot; bind-to=3D&quot;SetUser&quot;/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;par=
am
name=3D&quot;test&quot; value=3D&quot;i got loaded&quot;/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/aspect&gt;</span></font><o:p></o:p></p=
>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>target</span></font><o:p></o=
:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>package
com.xxx.core.audit;</span></font><o:p></o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>public
class Log<br>
{<br>
&nbsp;public static void setUser(String message)<br>
&nbsp;{stuff&#8230;}</span></font><o:p></o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>}</span></font><o:p></o:p></=
p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>Aspect
clas</span></font><o:p></o:p></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></font><o:p>=
</o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>import
org.codehaus.aspectwerkz.AspectContext;<br>
import =
org.codehaus.aspectwerkz.joinpoint.*;</span></font><o:p></o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><br>
public class GetUserAspect{<br>
&nbsp;&nbsp;&nbsp;&nbsp; private static ThreadLocal userName =3D new
ThreadLocal();<br>
&nbsp;&nbsp;&nbsp; private AspectContext myAspectContext =3D null;<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; public NextgenGetUserAspect(AspectContext =
ac){<br>
&nbsp;&nbsp;&nbsp;&nbsp; myAspectContext =3D ac;<br>
&nbsp;&nbsp;&nbsp; System.out.println(&quot;test init-&gt;&quot; +
myAspectContext.getParameter(&quot;test&quot;));<br>
&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; </span></font><o:p></o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;public
static void setUserName(String name) {<br>
&nbsp;&nbsp;userName.set(name);<br>
&nbsp;}<br>
&nbsp;public static String getUserName() {<br>
&nbsp;&nbsp;return (String) userName.get();<br>
&nbsp;}<br>
&nbsp;public Object storeUserName(StaticJoinPoint&nbsp; joinPoint) =
throws
Throwable {<br>
&nbsp;&nbsp;System.out.println(&quot;NextgenMonitoring SET USERNAME =
&quot;);<br>
&nbsp;&nbsp;return null;<br>
&nbsp;}</span></font><o:p></o:p></p>

<p><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>}</span></font><o:p></o:p></=
p>

<p><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'>&nbsp;</span></font><o:p></o=
:p></p>

</div>

</div>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0038_01C82226.9A933760--