1) Create Util class and write this re-usabled method in it, and call it where ever required.
2) Create service and service user and configurations in
OSGI config: Apache Sling Service User Mapper Service
Field: Service Mappings
Value format: <unique-package-name>:<service-name>=<service-user-name>
3) User this service name to get service resource resolver
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "my-custom-service");
BundleContext bundleContext = FrameworkUtil.getBundle(MyUtils.class).getBundleContext();
ServiceReference resourceResolverFactoryRef = bundleContext
.getServiceReference(ResourceResolverFactory.class.getName());
ResourceResolverFactory resFactory = (ResourceResolverFactory) bundleContext
.getService(resourceResolverFactoryRef);
return resFactory.getServiceResourceResolver(param);}
No comments:
Post a Comment