Re: Support for interceptors?

2011-11-11 Thread Graham Charters
Hi Frederik,

The way to get interceptors involved in Blueprint is to add a
namespace handler.  This is something that processes a blueprint
namespace extension.  So you would define a namespace that you would
add to blueprint, and maybe an associated element that you would
include to identify the services to be intercepted, and then your
namespace handler would be engaged and have the opportunity to do its
work.

Apache Aries has a number of examples of this (e.g. JPA,
Transactions).  I'd probably start by taking a look at the one for
transactions: 
https://svn.apache.org/repos/asf/aries/trunk/transaction/transaction-blueprint/

I hope this helps.

Regards, Graham.

On 10 November 2011 06:48, De Backer Frederik (DBB)
frederik.debac...@dexia.com wrote:
 Hello all,

 I am wondering if the OSGi Enterprise specification has some support to
 define interceptors on OSGi service methods. Suppose for example that I want
 to log the request parameters of a method, is it possible to define an
 interceptor in the blueprint.xml method on the service definition. I guess
 not because I haven't found anything until now. Is there some recommended
 approach to implement this? For example, by using an AOP framework like
 aspectj or using spring annotations (however in the last case I don't how
 how it is possible to define the annotations since I would need another
 spring-beans.xml file to define my annotations, next to my blueprint.xml
 file). Has someone done any work on this?

 Thx a lot for the assistance and kind regards,

 Frederik.

 -
 Dexia disclaimer:

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




RE: Support for interceptors?

2011-11-11 Thread Timothy Ward

Hi Frederik,

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

The namespace handler can then do something like this:

public Metadata parse(Element elt, ParserContext pc)
{
Metadata m = pc.getEnclosingComponent();

ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();

Interceptor interceptor = getMyInterceptor();

if(cm instanceof ServiceMetadata)
cdr.registerInterceptorWithComponent(cm, interceptor);
else
throw new RuntimeException(Not a service component);

return null;
}

I hope this is helpful, it seems like you're using some pretty advanced 
blueprint, may I ask what it's for?

Tim Ward
---
Apache Aries PMC member  Enterprise OSGi advocate
Enterprise OSGi in Action (http://www.manning.com/cummins)
---


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