Return-Path: X-Original-To: apmail-aries-user-archive@www.apache.org Delivered-To: apmail-aries-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 133D59FA4 for ; Mon, 14 Nov 2011 11:03:02 +0000 (UTC) Received: (qmail 25488 invoked by uid 500); 14 Nov 2011 11:03:01 -0000 Delivered-To: apmail-aries-user-archive@aries.apache.org Received: (qmail 25454 invoked by uid 500); 14 Nov 2011 11:03:01 -0000 Mailing-List: contact user-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@aries.apache.org Delivered-To: mailing list user@aries.apache.org Received: (qmail 25446 invoked by uid 99); 14 Nov 2011 11:03:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2011 11:03:01 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of timothyjward@hotmail.com designates 65.55.116.83 as permitted sender) Received: from [65.55.116.83] (HELO blu0-omc3-s8.blu0.hotmail.com) (65.55.116.83) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2011 11:02:56 +0000 Received: from BLU128-W17 ([65.55.116.74]) by blu0-omc3-s8.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 14 Nov 2011 03:02:35 -0800 Message-ID: Content-Type: multipart/alternative; boundary="_95bf743c-e9d9-4290-a00c-d1f211dc612f_" X-Originating-IP: [195.212.29.67] From: Timothy Ward Sender: To: Subject: RE: Support for interceptors? Date: Mon, 14 Nov 2011 11:02:34 +0000 Importance: Normal In-Reply-To: <99F6924F7BAB824EB73C7D866E72333601B65727@DLU0VEXM033P.dbb.int.dexwired.net> References: <99F6924F7BAB824EB73C7D866E72333601B65723@DLU0VEXM033P.dbb.int.dexwired.net>,,,<99F6924F7BAB824EB73C7D866E72333601B65727@DLU0VEXM033P.dbb.int.dexwired.net> MIME-Version: 1.0 X-OriginalArrivalTime: 14 Nov 2011 11:02:35.0544 (UTC) FILETIME=[EA4E1980:01CCA2BC] --_95bf743c-e9d9-4290-a00c-d1f211dc612f_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi=2C It is possible to use Service Hooks to hide the original services and publi= sh proxied ones that you want people to use=2C however I would regard this = as a very risky approach. Firstly=2C it is difficult to write a Service Hoo= k correctly without accidentally breaking the service registry=2C accidenta= lly filtering the wrong events can make things go badly wrong. Secondly it = creates a very unpleasant ordering requirement (which is a bad thing in OSG= i). If your hook is registered after one of the services it should have bee= n filtering then there may be bundles using it already. At this point hidin= g the service from those clients prevents them finding out when the service= goes away. There's quite a good blog post about Service Hooks here: http://www.osgi.or= g/blog/2009/02/osgi-service-hooks.html which explains why they aren't for t= he faint hearted. I would strongly recommend using blueprint instead=2C mos= tly because it's simpler to implement=2C but also because it won't break an= ything else if it goes wrong=2C and it will reliably work in any ordering s= cenario. As for your worry about dynamism=2C interceptors are not a static model. Yo= u can change the behaviour of your interceptor every time it is called (if = that's what you want). You could stop logging=2C starting transactions=2C c= ounting invocations=2C or whatever you are doing with your aspect=2C at any= time then start doing it again later if you want. My personal recommendation would be to avoid service hooks for this sort of= use case=2C particularly when Aries blueprint already offers you a proxied= =2C intercepted service model. Tim Ward ------------------- Apache Aries PMC member & Enterprise OSGi advocate Enterprise OSGi in Action (http://www.manning.com/cummins) ------------------- Subject: RE: Support for interceptors? Date: Mon=2C 14 Nov 2011 09:50:25 +0100 From: Frederik.DeBacker@dexia.com To: user@aries.apache.org Hi all=2C =20 Thx for the response. I had started looking into the spec and was=20 thinking to use the Service Hook specs to solve this. What is your opinion = about=20 using this approach? I guess the advantage could be that we can put the pro= xy=20 implementation in a separate bundle and that we can deploy/activate=20 this dynamically without having to change the 'to be proxied'=20 service. =20 thx and kr=2C =20 Frederik. From: timothyjward@hotmail.com=20 [mailto:timothyjward@hotmail.com] On Behalf Of Timothy=20 Ward Sent: vrijdag 11 november 2011 16:33 To:=20 user@aries.apache.org Subject: RE: Support for=20 interceptors? Hi Frederik=2C As Graham says=2C the way to implement this is=20 with a namespace handler. If you create your own namespace then you can add= an=20 element (or attribute) in the service you want to be intercepted. The=20 namespace handler can then do something like this: public Metadata=20 parse(Element elt=2C ParserContext pc) =20 { Metadata m =3D=20 pc.getEnclosingComponent()=3B =20 ComponentDefinitionRegistry cdr =3D=20 pc.getComponentDefinitionRegistry()=3B =20 Interceptor interceptor =3D=20 getMyInterceptor()=3B if(cm=20 instanceof=20 ServiceMetadata) =20 cdr.registerInterceptorWithComponent(cm=2C=20 interceptor)=3B =20 else throw=20 new RuntimeException("Not a service=20 component")=3B return=20 null=3B } I hope this is helpful=2C it seems like=20 you're using some pretty advanced blueprint=2C may I ask what it's for? Tim=20 Ward ------------------- Apache Aries PMC member & Enterprise OSGi=20 advocate Enterprise OSGi in Action (http://www.manning.com/cummins) ------------------- > Date: Fri=2C 11 Nov 2011 09:20:06 +0000 > Subject: Re: Support for=20 interceptors? > From: gcharters@gmail.com > To:=20 user@aries.apache.org >=20 > Hi Frederik=2C >=20 > The way to=20 get interceptors involved in Blueprint is to add a > namespace handler.=20 This is something that processes a blueprint > namespace extension. So you=20 would define a namespace that you would > add to blueprint=2C and maybe an=20 associated element that you would > include to identify the services to be=20 intercepted=2C and then your > namespace handler would be engaged and have=20 the opportunity to do its > work. >=20 > Apache Aries has a=20 number of examples of this (e.g. JPA=2C > Transactions). I'd probably start=20 by taking a look at the one for > transactions:=20 https://svn.apache.org/repos/asf/aries/trunk/transaction/transaction-bluepr= int/ >=20 > I hope this helps. >=20 > Regards=2C Graham. >=20 >=20 On 10 November 2011 06:48=2C De Backer Frederik (DBB) >=20 wrote: > > Hello all=2C >=20 > > > I am wondering if the OSGi Enterprise specification has some=20 support to > > define interceptors on OSGi service methods. Suppose for=20 example that I want > > to log the request parameters of a method=2C is=20 it possible to define an > > interceptor in the blueprint.xml method on=20 the service definition. I guess > > not because I haven't found=20 anything until now. Is there some recommended > > approach to implement=20 this? For example=2C by using an AOP framework like > > aspectj or using=20 spring annotations (however in the last case I don't how > > how it is=20 possible to define the annotations since I would need another > >=20 spring-beans.xml file to define my annotations=2C next to my blueprint.xml >=20 > file). Has someone done any work on this? > > > > Thx a=20 lot for the assistance and kind regards=2C > > > >=20 Frederik. > > > >=20 ------------------------------------------------------------------------- >=20 > Dexia disclaimer: > > > >=20 http://www.dexia.com/maildisclaimer.htm > >=20 ------------------------------------------------------------------------- >=20 > > > ------------------------------------------------------------------------- Dexia disclaimer: http://www.dexia.com/maildisclaimer.htm ------------------------------------------------------------------------- = --_95bf743c-e9d9-4290-a00c-d1f211dc612f_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi=2C

It is possible to use Service Hooks to hide t= he original services and publish proxied ones that you want people to use= =2C however I would regard this as a very risky approach. Firstly=2C it is = difficult to write a Service Hook correctly without accidentally breaking t= he service registry=2C accidentally filtering the wrong events can make thi= ngs go badly wrong. Secondly it creates a very unpleasant ordering requirem= ent (which is a bad thing in OSGi). If your hook is registered after one of= the services it should have been filtering then there may be bundles using= it already. At this point hiding the service from those clients prevents t= hem finding out when the service goes away.

There's quite a good blo= g post about Service Hooks here: http://www.osgi.org/blog/2009/02/osgi-service-ho= oks.html which explains why they aren't for the faint hearted. I would = strongly recommend using blueprint instead=2C mostly because it's simpler t= o implement=2C but also because it won't break anything else if it goes wro= ng=2C and it will reliably work in any ordering scenario.

As for you= r worry about dynamism=2C interceptors are not a static model. You can chan= ge the behaviour of your interceptor every time it is called (if that's wha= t you want). You could stop logging=2C starting transactions=2C counting in= vocations=2C or whatever you are doing with your aspect=2C at any time then= start doing it again later if you want.

My personal recommendation = would be to avoid service hooks for this sort of use case=2C particularly w= hen Aries blueprint already offers you a proxied=2C intercepted service mod= el.


Tim Ward
-------------------
Apache Aries PMC member &= amp=3B Enterprise OSGi advocate
Enterprise OSGi in Action (http://www.manning.com/cumm= ins)
-------------------



Sub= ject: RE: Support for interceptors?
Date: Mon=2C 14 Nov 2011 09:50:25 +0= 100
From: Frederik.DeBacker@dexia.com
To: user@aries.apache.org
Hi all=2C
 =3B
Thx for the response. I had started looki= ng into the spec and was=20 thinking to use the Service Hook specs to solve this. What is your opinion = about=20 using this approach? I guess the advantage could be that we can put the pro= xy=20 implementation in a separate bundle and that we can deploy/activate=20 this =3Bdynamically without having to change the 'to be proxied'=20 service.
 =3B
thx and kr=2C
 =3B
Frederik.


From: timothyjward@hotmail.com=20 [mailto:timothyjward@hotmail.com] On Behalf Of Timothy=20 Ward
Sent: vrijdag 11 november 2011 16:33
To:=20 user@aries.apache.org
Subject: RE: Support for=20 interceptors?

Hi Frederik=2C

As Graham says=2C the way to impleme= nt this is=20 with a namespace handler. If you create your own namespace then you can add= an=20 element (or attribute) in the service you want to be intercepted.

Th= e=20 namespace handler can then do something like this:

public Metadata=20 parse(Element elt=2C ParserContext pc)
 =3B =3B =3B=20 {
 =3B =3B =3B =3B =3B =3B =3B Metadata m = =3D=20 pc.getEnclosingComponent()=3B
 =3B =3B =3B =3B =3B&n= bsp=3B =3B=20
 =3B =3B =3B =3B =3B =3B =3B ComponentDefin= itionRegistry cdr =3D=20 pc.getComponentDefinitionRegistry()=3B
 =3B =3B =3B =3B&= nbsp=3B =3B =3B=20
 =3B =3B =3B =3B =3B =3B =3B Interceptor in= terceptor =3D=20 getMyInterceptor()=3B

 =3B =3B =3B =3B =3B = =3B =3B if(cm=20 instanceof=20 ServiceMetadata)
 =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B=20 cdr.registerInterceptorWithComponent(cm=2C=20 interceptor)=3B
 =3B =3B =3B =3B =3B =3B =3B= =20 else
 =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B throw=20 new RuntimeException("Not a service=20 component")=3B

 =3B =3B =3B =3B =3B =3B = =3B return=20 null=3B
 =3B =3B =3B }

I hope this is helpful=2C it s= eems like=20 you're using some pretty advanced blueprint=2C may I ask what it's for?
=
Tim=20 Ward
-------------------
Apache Aries PMC member &=3B Enterprise O= SGi=20 advocate
Enterprise OSGi in Action (http://www.manning.com/cummins)
-----------= --------


>=3B Date: Fri=2C 11 Nov 2011 09:20:06 +0000
>=3B Subject: Re: = Support for=20 interceptors?
>=3B From: gcharters@gmail.com
>=3B To:=20 user@aries.apache.org
>=3B
>=3B Hi Frederik=2C
>=3B
>= =3B The way to=20 get interceptors involved in Blueprint is to add a
>=3B namespace hand= ler.=20 This is something that processes a blueprint
>=3B namespace extension.= So you=20 would define a namespace that you would
>=3B add to blueprint=2C and m= aybe an=20 associated element that you would
>=3B include to identify the service= s to be=20 intercepted=2C and then your
>=3B namespace handler would be engaged a= nd have=20 the opportunity to do its
>=3B work.
>=3B
>=3B Apache Aries= has a=20 number of examples of this (e.g. JPA=2C
>=3B Transactions). I'd probab= ly start=20 by taking a look at the one for
>=3B transactions:=20 https://svn.apache.org/repos/asf/aries/trunk/transaction/transaction-bluepr= int/
>=3B=20
>=3B I hope this helps.
>=3B
>=3B Regards=2C Graham.
&g= t=3B
>=3B=20 On 10 November 2011 06:48=2C De Backer Frederik (DBB)
>=3B=20 <=3BFrederik.DeBacker@dexia.com>=3B wrote:
>=3B >=3B Hello all= =2C
>=3B=20 >=3B
>=3B >=3B I am wondering if the OSGi Enterprise specification= has some=20 support to
>=3B >=3B define interceptors on OSGi service methods. Su= ppose for=20 example that I want
>=3B >=3B to log the request parameters of a met= hod=2C is=20 it possible to define an
>=3B >=3B interceptor in the blueprint.xml = method on=20 the service definition. I guess
>=3B >=3B not because I haven't foun= d=20 anything until now. Is there some recommended
>=3B >=3B approach to = implement=20 this? For example=2C by using an AOP framework like
>=3B >=3B aspect= j or using=20 spring annotations (however in the last case I don't how
>=3B >=3B h= ow it is=20 possible to define the annotations since I would need another
>=3B >= =3B=20 spring-beans.xml file to define my annotations=2C next to my blueprint.xml<= br>>=3B=20 >=3B file). Has someone done any work on this?
>=3B >=3B
>=3B= >=3B Thx a=20 lot for the assistance and kind regards=2C
>=3B >=3B
>=3B >= =3B=20 Frederik.
>=3B >=3B
>=3B >=3B=20 ------------------------------------------------------------------------->=3B=20 >=3B Dexia disclaimer:
>=3B >=3B
>=3B >=3B=20 http://www.dexia.com/maildisclaimer.htm
>=3B >=3B=20 ------------------------------------------------------------------------->=3B=20 >=3B
>=3B >=3B
-------------------------------=
------------------------------------------
Dexia disclaimer:

http://www.dexia.com/maildisclaimer.htm
-------------------------------------------------------------------------

= --_95bf743c-e9d9-4290-a00c-d1f211dc612f_--