You need to pass the current page object to the OSGi service.
public void readProperties(Page currentPage) {
ResourceResolver resolver = null;
InheritanceValueMap map = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
}
In the sling model call OSGI service
@Inject @Source("osgi-services")
TestService testService1;
@PostConstruct
public void activate(){
System.out.println("Inside Post Constructor Method");
testService1.readProperties(currentPage);
}You can also pass page path as a parameter to the service method and inside service method, you need to write something like this
@3214626
private ResourceResolverFactory resolverFactory;
public void testMethod(String resourcePath ) {
try {
Resource res = resourceResolver.getResource(resourcePath);
resourceResolver.close();
} catch (LoginException e) {
// log the error
}
}