Adding interceptors


Adding interceptors is a common technique to implement non-functional aspects such as security. The ServiceBinder supports the addition of interceptors that sit between component instances. The addition of an interceptor for a particular component instance can be done either at the providing side or at the requiring side.

The GenericActivator provides two methods methods to insert the interceptors, these methods need to be redefined in the subclass of the GenericActivator to add the interceptors (otherwise this is not necessary). It is interesting to note that since these methods are located inside the activator, they can access the service registry, so that it is possible to use OSGi services to implement the non-functional capabilities.

The methods that can must be overloaded to insert interceptors are the following:

The first parameter of both methods contains the object to which a proxy will be added.

The first method is called right after the component instance is created. The InstanceMetadata passed as a parameter provides the information about the component found on the descriptor file.

The second method is called right before an invocation to a bind method takes place. The DependencyMetadata passed as a parameter contains information about the dependency such as the filter and the name of the service.

It is very important to return a non-null value from these calls. If null is returned (or an exception is thrown), the call to the methods is ignored and the original values are used instead. It is also crucial to return an object that implements the exact same interfaces as the original one.

Last revision: 05 February 2004
(c) H. Cervantes and R.S. Hall

Next : Factories and scopes

Previous : The component implementation class

Index