You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by co...@christian-vogel.info on 2012/07/09 15:20:28 UTC

AOP in Apache Felix

Hi guys,

Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:

* using dynamic proxies (Spring AOP or DependencyManager)
* Equinox Weaving (but does not work in Apache Felix)

All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project? 

Underlying development will be done by Bnd(tools), maybe it could be relevant :)

Greetings.
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: AOP in Apache Felix

Posted by co...@christian-vogel.info.
That is really pity, but nevertheless thx for your help. The implementation is the only problem. I already found out that you added code for `WeavingHooks` in the framework code ;) So if I have the implementation the rest will be easy hopefully ^^

-Christian

----- Original Message -----
From: heavy@ungoverned.org
To: users@felix.apache.org
Date: 09.07.2012 18:07:29
Subject: Re: AOP in Apache Felix


> On 7/9/12 11:56 , contact@christian-vogel.info wrote:
>> Hi Richard,
>> 
>> I already had a look to the `WeaverHook` interface, but I did not find any good example how to implement it. Do you have any sources?
> 
> Not really. Just google it. The spec has an example in it. If you are 
> looking for help with doing the byte code manipulation, then you're on 
> your own there...
> 
> Implementing the hook is fairly straightforward, though. Just implement 
> a weaving hook and register it as a service and then it will be called 
> by the framework to give you a chance to manipulate the class bytes.
> 
> -> richard
> 
>> 
>> Greetings.
>> Christian
>> 
>> ----- Original Message -----
>> From: heavy@ungoverned.org
>> To: users@felix.apache.org
>> Date: 09.07.2012 16:12:13
>> Subject: Re: AOP in Apache Felix
>> 
>> 
>>> On 7/9/12 9:20 AM, contact@christian-vogel.info wrote:
>>>> Hi guys,
>>>> 
>>>> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>>>> 
>>>> * using dynamic proxies (Spring AOP or DependencyManager)
>>>> * Equinox Weaving (but does not work in Apache Felix)
>>>> 
>>>> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
>>>> 
>>>> Underlying development will be done by Bnd(tools), maybe it could be relevant :)
>>> Check the weaving hook section in the R4.3 or R5 OSGi core spec.
>>> 
>>> -> richard
>>> 
>>>> Greetings.
>>>> Christian
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: AOP in Apache Felix

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 7/9/12 11:56 , contact@christian-vogel.info wrote:
> Hi Richard,
>
> I already had a look to the `WeaverHook` interface, but I did not find any good example how to implement it. Do you have any sources?

Not really. Just google it. The spec has an example in it. If you are 
looking for help with doing the byte code manipulation, then you're on 
your own there...

Implementing the hook is fairly straightforward, though. Just implement 
a weaving hook and register it as a service and then it will be called 
by the framework to give you a chance to manipulate the class bytes.

-> richard

>
> Greetings.
> Christian
>
> ----- Original Message -----
> From: heavy@ungoverned.org
> To: users@felix.apache.org
> Date: 09.07.2012 16:12:13
> Subject: Re: AOP in Apache Felix
>
>
>> On 7/9/12 9:20 AM, contact@christian-vogel.info wrote:
>>> Hi guys,
>>>
>>> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>>>
>>> * using dynamic proxies (Spring AOP or DependencyManager)
>>> * Equinox Weaving (but does not work in Apache Felix)
>>>
>>> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
>>>
>>> Underlying development will be done by Bnd(tools), maybe it could be relevant :)
>> Check the weaving hook section in the R4.3 or R5 OSGi core spec.
>>
>> -> richard
>>
>>> Greetings.
>>> Christian
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: AOP in Apache Felix

Posted by co...@christian-vogel.info.
Hi Richard,

I already had a look to the `WeaverHook` interface, but I did not find any good example how to implement it. Do you have any sources?

Greetings.
Christian

----- Original Message -----
From: heavy@ungoverned.org
To: users@felix.apache.org
Date: 09.07.2012 16:12:13
Subject: Re: AOP in Apache Felix


> On 7/9/12 9:20 AM, contact@christian-vogel.info wrote:
>> Hi guys,
>> 
>> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>> 
>> * using dynamic proxies (Spring AOP or DependencyManager)
>> * Equinox Weaving (but does not work in Apache Felix)
>> 
>> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
>> 
>> Underlying development will be done by Bnd(tools), maybe it could be relevant :)
> 
> Check the weaving hook section in the R4.3 or R5 OSGi core spec.
> 
> -> richard
> 
>> 
>> Greetings.
>> Christian
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: AOP in Apache Felix

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 7/9/12 9:20 AM, contact@christian-vogel.info wrote:
> Hi guys,
>
> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>
> * using dynamic proxies (Spring AOP or DependencyManager)
> * Equinox Weaving (but does not work in Apache Felix)
>
> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
>
> Underlying development will be done by Bnd(tools), maybe it could be relevant :)

Check the weaving hook section in the R4.3 or R5 OSGi core spec.

-> richard

>
> Greetings.
> Christian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: Re: AOP in Apache Felix

Posted by co...@christian-vogel.info.
Ah I realized that I'm having a start level problem ^^ The bundle that contains the weaver hook impl should be loaded before all other bundles :)

----- Original Message -----
From: contact@christian-vogel.info
To: users@felix.apache.org
Date: 09.07.2012 19:17:51
Subject: Re: Re: AOP in Apache Felix


> Hi Marcel,
> 
> here are some examples:
> 
> 1. Looking for special annotations on service methods
> 
> @Authorize
> public void executeSomethingOnlyAllowedIfUserIsAuthorized() {
> ...
> }
> 
> All method that is annotated with @Authorize will be handled with a `before` aspect which is checking some credentials.
> 
> 2. Default Logging for thrown Exceptions, Bundle start/stop, etc. 
> 
> Is it clear what I want to do?
> 
> I'm currently looking how the weaving hooks are working. But if I register an `WeavingHook` impl and start it with some of my bundles, nothing happens. So the weave method will not be called :( Do not know what I'm doing wrong. 
> 
> WeavingHookImpl Code: 
> 
> public class WeavingHookImpl implements WeavingHook {
> 
>     @Override
>     public void weave(WovenClass arg0) {
>         System.out.println("load class " + arg0.getClassName());
> 
>     }
> 
> }
> 
> Activator Code:
> 
> public class Activator implements BundleActivator {
> 
>     @Override
>     public void start(BundleContext arg0) throws Exception {
>         System.out.println("start weaving bundle");
>         arg0.registerService(WeavingHook.class, new WeavingHookImpl(), null);
>     }
> 
>     @Override
>     public void stop(BundleContext arg0) throws Exception {
>         // TODO Auto-generated method stub
> 
>     }
> 
> }
> 
> Greetings.
> Christian
> 
> ----- Original Message -----
> From: marcel.offermans@luminis.nl
> To: users@felix.apache.org
> Date: 09.07.2012 18:43:27
> Subject: Re: AOP in Apache Felix
> 
> 
>> Hey Christian,
>> 
>> On Jul 9, 2012, at 15:20 PM, <co...@christian-vogel.info> <co...@christian-vogel.info> wrote:
>> 
>>> Hi guys,
>>> 
>>> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>>> 
>>> * using dynamic proxies (Spring AOP or DependencyManager)
>>> * Equinox Weaving (but does not work in Apache Felix)
>>> 
>>> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
>> 
>> So do you want to be able to apply your weaving to any implementation class in any bundle? Or do you want to still do it on an interface, just without specifying what specific interface(s) you want to apply the weaving to? Maybe if you explain your use cases a bit more, we can help you think about alternative solutions.
>> 
>> Greetings, Marcel
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: AOP in Apache Felix

Posted by co...@christian-vogel.info.
Hi Marcel,

here are some examples:

1. Looking for special annotations on service methods

@Authorize
public void executeSomethingOnlyAllowedIfUserIsAuthorized() {
...
}

All method that is annotated with @Authorize will be handled with a `before` aspect which is checking some credentials.

2. Default Logging for thrown Exceptions, Bundle start/stop, etc. 

Is it clear what I want to do?

I'm currently looking how the weaving hooks are working. But if I register an `WeavingHook` impl and start it with some of my bundles, nothing happens. So the weave method will not be called :( Do not know what I'm doing wrong. 

WeavingHookImpl Code: 

public class WeavingHookImpl implements WeavingHook {

	@Override
	public void weave(WovenClass arg0) {
		System.out.println("load class " + arg0.getClassName());

	}

}

Activator Code:

public class Activator implements BundleActivator {

	@Override
	public void start(BundleContext arg0) throws Exception {
		System.out.println("start weaving bundle");
		arg0.registerService(WeavingHook.class, new WeavingHookImpl(), null);
	}

	@Override
	public void stop(BundleContext arg0) throws Exception {
		// TODO Auto-generated method stub

	}

}

Greetings.
Christian

----- Original Message -----
From: marcel.offermans@luminis.nl
To: users@felix.apache.org
Date: 09.07.2012 18:43:27
Subject: Re: AOP in Apache Felix


> Hey Christian,
> 
> On Jul 9, 2012, at 15:20 PM, <co...@christian-vogel.info> <co...@christian-vogel.info> wrote:
> 
>> Hi guys,
>> 
>> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
>> 
>> * using dynamic proxies (Spring AOP or DependencyManager)
>> * Equinox Weaving (but does not work in Apache Felix)
>> 
>> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?
> 
> So do you want to be able to apply your weaving to any implementation class in any bundle? Or do you want to still do it on an interface, just without specifying what specific interface(s) you want to apply the weaving to? Maybe if you explain your use cases a bit more, we can help you think about alternative solutions.
> 
> Greetings, Marcel
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: AOP in Apache Felix

Posted by Marcel Offermans <ma...@luminis.nl>.
Hey Christian,

On Jul 9, 2012, at 15:20 PM, <co...@christian-vogel.info> <co...@christian-vogel.info> wrote:

> Hi guys,
> 
> Currently I'm trying to add AOP support to my Felix OSGi environment. After some research I came up with following possibilities:
> 
> * using dynamic proxies (Spring AOP or DependencyManager)
> * Equinox Weaving (but does not work in Apache Felix)
> 
> All the above solutions doesnt suit my use case. I need aspects which weaves in terms of special annotations. I do not want to know the service interfaces which could be implemented by a proxy like the DependencyManager is doing. Is there any possibility to add "real" AOP support to my project?

So do you want to be able to apply your weaving to any implementation class in any bundle? Or do you want to still do it on an interface, just without specifying what specific interface(s) you want to apply the weaving to? Maybe if you explain your use cases a bit more, we can help you think about alternative solutions.

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org