Reputation: 71
I am using Jersey 2.x and HK2 which is built-in into Jersey.
I need to decorate certain methods in my services marked by annotation, i.e. I'd like to perform some additional actions before and after such methods calls. Unfortunately, HK2 doesn't have any AOP capabilities. I thought that I could bind my factory to a service's interface and create a proxy of the service whenever factory's provide
method is called. However, I need a couple of things to my factory to work:
1) the service's class and interface to create a proxy
2) ServiceLocator
instance to properly inject all service's dependencies
And I just don't see any way to have both. If I bind factory using bindFactory(MyFactory.class)
then I can't pass information about the service into it, but can have ServiceLocator instance injected into it. And if I bind factory using bindFactory(new MyFactory(Service.class, ServiceImpl.class))
then I have information about the service, but I don't have ServiceLocator
instance to properly create that service, because HK2 doesn't inject anything into factories instances and I don't see anyway to get a ServiceLocator instance from AbstractBinder to provide my factory with locator during binding.
I would really appreciate any suggestions and recommendations. I hope I am not the first one who wants to uniformly proxy my services.
Upvotes: 1
Views: 1321
Reputation: 2404
In the most recent version of hk2 (2.2.0-b25) we have added the ability to add AOP alliance interceptors to any method. But this feature is not yet fully baked (we will be adding constructor injection) and not yet fully documented. But you might want to start playing around with it, as it will give you the ability to add AOP MethodInterceptors to any method on your service.
Upvotes: 0