• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to get mixin to intercept with IntroductionInterceptor

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've started experimenting Spring just for sometimes. Recently I got a strange case with IntroductionInterceptor. I don't know it's my understanding problem or the way I configured the framework was wrong.

Main Idea: I wanted to implement a greeting service which has the method sayGreeting(). Then I added an Introduction Interceptor to control if people can use that service or not.

so as you can see I called the lock() method on the lockMixin but the method was still running smoothly without throwing any RuntimeException.

This is my configuration of hello.xml:

Please pay attention to the bold parts with singleton="true"! I want to try that so I can retrieve back the bean for lockMixin and call the method lock() on it!

Please help me out!
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also recommend using the link to the Documentation I posted in that other thread you posted in that got me to this thread.

Those introductions uses Annotations in an Aspect class, that is much nicer loose coupling than having a class extend a Spring class. Now that class is tightly coupled to Spring. Whereas with an Aspect class and annotations on the method to add, you can still run that code as Plain Java code without having anything Spring related in your classpath at runtime.

Thanks

Mark
 
Bang Nguyen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kurt Xu wrote:Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.



Hi, it will not work. Moreover, this is not what we intended to do. Because just imagine the greetingServiceTarget is some JavaBean in our domain such as Student, Class, Course. From that, we can see that those objects must not be singleton. Otherwise, they will store dirty data from the same object type.

When we imagine this greetingServiceTarget as Student, Class Objects; we can see that sometimes we want to lock some specific services of these objects. That's the intention of this example.

Anyway, thanks for your contribution! Please give more suggestions so we can study!
 
Bang Nguyen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I also recommend using the link to the Documentation I posted in that other thread you posted in that got me to this thread.

Those introductions uses Annotations in an Aspect class, that is much nicer loose coupling than having a class extend a Spring class. Now that class is tightly coupled to Spring. Whereas with an Aspect class and annotations on the method to add, you can still run that code as Plain Java code without having anything Spring related in your classpath at runtime.

Thanks

Mark



Thanks! I got your ideas. However, this is just one of the examples. Of cause, when we do this in real life, we can use annotations. I'm also a fan of annotation.

But the idea of this example is to demonstrate the IntroductionInterceptor concept actually doesn't add more attributes or services to the original class. It just gives us a facility to control the behaviour of the services without adding irrelevant stuff into our business actions.

Kind Regards,
 
Kurt Xu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bang Nguyen wrote:

Kurt Xu wrote:Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.



Hi, it will not work. Moreover, this is not what we intended to do. Because just imagine the greetingServiceTarget is some JavaBean in our domain such as Student, Class, Course. From that, we can see that those objects must not be singleton. Otherwise, they will store dirty data from the same object type.

When we imagine this greetingServiceTarget as Student, Class Objects; we can see that sometimes we want to lock some specific services of these objects. That's the intention of this example.

Anyway, thanks for your contribution! Please give more suggestions so we can study!



Show me your test app, I did this kind of test, everything was ok. Not difficult
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bang Nguyen wrote:

Kurt Xu wrote:Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.



Hi, it will not work. Moreover, this is not what we intended to do. Because just imagine the greetingServiceTarget is some JavaBean in our domain such as Student, Class, Course. From that, we can see that those objects must not be singleton. Otherwise, they will store dirty data from the same object type.

When we imagine this greetingServiceTarget as Student, Class Objects; we can see that sometimes we want to lock some specific services of these objects. That's the intention of this example.

Anyway, thanks for your contribution! Please give more suggestions so we can study!



In the scenario of Domain objects, which won't be Spring beans because they hold state, that is where you can go to AspectJ and Bytecode instrumentation to get it done.

Mark
 
Bang Nguyen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:

Bang Nguyen wrote:

Kurt Xu wrote:Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.



Hi, it will not work. Moreover, this is not what we intended to do. Because just imagine the greetingServiceTarget is some JavaBean in our domain such as Student, Class, Course. From that, we can see that those objects must not be singleton. Otherwise, they will store dirty data from the same object type.

When we imagine this greetingServiceTarget as Student, Class Objects; we can see that sometimes we want to lock some specific services of these objects. That's the intention of this example.

Anyway, thanks for your contribution! Please give more suggestions so we can study!



In the scenario of Domain objects, which won't be Spring beans because they hold state, that is where you can go to AspectJ and Bytecode instrumentation to get it done.

Mark



I couldn't upload my files successfully because it's quite big. Please download from this

Please run the class com.bang.helloworld.StandaloneHelloApp only. This project is just for experimenting so forgive me because there are some other irrelevant files there.

When you're running it, please notice this snippet:

GreetingService greetingService =
(GreetingService) factory.getBean("greetingService");
LockMixin lockMixin= (LockMixin) factory.getBean("lockMixin");
lockMixin.lock();
greetingService.sayGreeting();

The expected result is a RuntimeException thrown at line greetingService.sayGreeting()

Thanks for your help!
reply
    Bookmark Topic Watch Topic
  • New Topic