Hi,
now my component reads its annotation properties with the activation function.
I need to have a property shared by two components.
Can i read the property of another component inside the activation function?
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
This is the solution:
BundleContext bundleContext = FrameworkUtil.getBundle(PublishPagesService.class).getBundleContext(); ServiceReference osgiRef = bundleContext.getServiceReference(PublishPagesService.class.getName()); PublishPagesService service = (PublishPagesService) bundleContext.getService(osgiRef);
Views
Replies
Total Likes
You can code a public method that returns that property in a given service. So if ServiceA has prop Foo and you want the Foo prop in ServiceB, create a method in ServiceA that returns Foo. Then in Service B, create an instance of ServiceA and invoke the method that returns Foo. You can use dependency injection to get a ServiceA instance.
Views
Replies
Total Likes
I have a component that is also a service. It initialize the variables inside the activate function and return them with another function.
Inside the jsp i have MyService pageService = sling.MyService(MyService.class) that launch the activate method. This part of code work fine
Now inside the java code if i create an object of MyServiceImplementation and i try to retrieve the variables, they are all empty because the activate function isn't launched.
Can i force the launch pageService.activate(ctx)? What can i put as ctx?
Another way is to use the service directly inside the java but i don't have the sling variable and i don't know how to retrieve that
Views
Replies
Total Likes
The activate function that is located within an OSGi service is invoked when you activate the Bundle.
From within your Java service - you can use the Sling API to read a node property.
Views
Replies
Total Likes
This is the solution:
BundleContext bundleContext = FrameworkUtil.getBundle(PublishPagesService.class).getBundleContext(); ServiceReference osgiRef = bundleContext.getServiceReference(PublishPagesService.class.getName()); PublishPagesService service = (PublishPagesService) bundleContext.getService(osgiRef);
Views
Replies
Total Likes
You can also use @reference and get the instance of your service in another service.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies