File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How to get mixin to intercept with IntroductionInterceptor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to get mixin to intercept with IntroductionInterceptor" Watch "How to get mixin to intercept with IntroductionInterceptor" New topic
Author

How to get mixin to intercept with IntroductionInterceptor

Bang Nguyen
Greenhorn

Joined: Feb 03, 2009
Posts: 15
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!


http://trongbang86.blogspot.com
http://twitter.com/trongbang86
Kurt Xu
Ranch Hand

Joined: Sep 29, 2009
Posts: 32
Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bang Nguyen
Greenhorn

Joined: Feb 03, 2009
Posts: 15
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

Joined: Feb 03, 2009
Posts: 15
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

Joined: Sep 29, 2009
Posts: 32
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
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Feb 03, 2009
Posts: 15
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get mixin to intercept with IntroductionInterceptor
 
Similar Threads
Problem with "Spring in Action" Book First Example
Spring: Hello World Does Not Work
A simple try on IntroductionInterceptor
spring inside eclipse
dependency injection by annotations