Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspectJ with EJB problem

There seems to be a few more issues here.  Your pointcut is not
matching the joinpoint you think it is.  First, what Dean said is
probably right.  But also, I don't see that your pointcut is capturing
any arguments.  You probably want to add an "args" pointcut
designator.


pointcut insertSurname(String name) : execution(public String
MyBean+.sayHello(String)) && args(name);

after() returning(String name) : insertSurname(String) {
  ...
}

What this will do is capture the "name" argument and make it
accessible in the body of the advice.  I'm actually surprised that the
previous aspect compiled.

(or something like this...I haven't tried to compile this)

On Tue, Jun 3, 2008 at 5:26 AM, Dean Wampler <dean@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Actually, it would print
> Hi Toy My Surname
> Hi Toy
> If you run this code as a normal Java application (replacing the
> InitialContext stuff with "new MyBean()", for example), it works fine.
> First, did you compile the code with ajc? If not, are you using load-time
> weaving with your EJB container?
> I haven't used EJBs in a long time, so I'm not sure how this code is really
> implemented and managed by the container. However, I suspect that you aren't
> getting an object of type MyBean, but some proxied object or even a subclass
> (like they used to do in EJB v2).
> Try adding a plus sign, "+" in your pointcut definition:
> pointcut insertSurname() : execution(public String MyBean+.sayHello(..));
> This tells AspectJ to match on subclasses too. That might work. If not,
> perhaps someone else on the list will have the answer.
> Good luck,
> Dean
> On Jun 3, 2008, at 4:53 AM, Noppanit Charassinvichai wrote:
>
>
> Dear, All
>
> I was trying to use AspectJ with EJB. My program is very simple, but I have
> a little problem.
>
> This is my Bean which is very simple
>
> @Stateless(mappedName="HelloWorld")
> public class MyBean implements MyBeanFacade
> {
>       @Override
>       public String sayHello(String name) {
>             return "Hi "+name;
>       }
>
> }
>
> And this is my aspect
> public aspect TestAOP {
>
>       pointcut insertSurname() : execution(public String
> MyBean.sayHello(..));
>
>       after() returning(String name) : insertSurname()
>       {
>             System.out.println(name +" My Surname");
>       }
> }
>
>
>
> And this is my client tester
>
>       public static void main(String[] args) throws Exception {
>             // TODO Auto-generated method stub
>             InitialContext context = new InitialContext();
>             MyBeanFacade bean = (MyBeanFacade)context.lookup("HelloWorld");
>             System.out.println(bean.sayHello("Toy"));
>       }
>
> And I packed these classes together and deployed to Glassfish, but when I
> invoked the bean. It did show "My Surname". It just showed "Hi Toy" on my
> Console. I think it suppose to show "Hi Toy My Surname". Something like
> this. Please help me!!!
> Kindly Regards,
> Noppanit Charassinvichai
> =====================================
> Application Development & Technology
> G-ABLE COMPANY LIMITED
> 127/27,29-31 Panjathani Tower, Nonsee Rd,
> Chongnonsee,Yanawa, Bangkok 10120 Thailand.
> Mobile: 081-962-1412
> Website: www.g-able.com
> E-Mail: noppanit.c@xxxxxxxxxx
> ====================================
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> Dean Wampler, Ph.D.
> dean at objectmentor.com
> http://www.objectmentor.com
> See also:
> http://www.aspectprogramming.com  AOP advocacy site
> http://aquarium.rubyforge.org     AOP for Ruby
> http://www.contract4j.org         Design by Contract for Java5
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top