unable to get data from query.. showing error at SUBSERVICE,getServiceResourceResolver(param). | Community
Skip to main content
harsha__
Level 2
October 16, 2015
Solved

unable to get data from query.. showing error at SUBSERVICE,getServiceResourceResolver(param).

  • October 16, 2015
  • 6 replies
  • 3049 views

unable to get data from query.. showing error at SUBSERVICE,getServiceResourceResolver(param).

Code: Please excuse me as the code logic is in inchoate state. but this my java class and I am trying to call getCustomerData() method to query node.

And i also want to know whether this class can be used not as a service and still can it query the node?

attached java file as the code is too large to paste here [img]error.png[/img]
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by

Are you trying this on AEM 6.1?

Try these:

1. Override the "activate" method in your class to instantiate the "ResourceResolver"..  here's a sample

@Component(immediate = true, label = "SiteContent Helper", description = "SiteContent Helper") @Service(value = SiteContentHelper.class) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "SiteContent Helper") }) public class SiteContentHelper { @Reference private ResourceResolverFactory resolverFactory; private ResourceResolver resourceResolver; private static Session session; private static final String AEM_SUBSERVICE = "readService"; @Activate private void activate(ComponentContext context) { Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, AEM_SUBSERVICE); try { resourceResolver = resolverFactory.getServiceResourceResolver(param); } catch (LoginException e) { log.info("..." + e); } } public String getPropertyValueFromRepository(SlingHttpServletRequest request, String propertyName) throws Exception { resourceResolver = request.getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); .... Node aNode = session.getNode(....); } }

2. I'm getting the "resourceResolver" from "request"

3. If in AEM 6.1.. i have defined a "Service User". The below link will help you with the process

http://stackoverflow.com/questions/31350548/resourceresolverfactory-getserviceresourceresolver-throws-exception-in-aem-6-1/31394583#31394583

6 replies

smacdonald2008
Level 10
October 16, 2015

See this AEM community artilce that talks about how to use JCR API to query JCR Data: 

https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Accepted solution
October 16, 2015

Are you trying this on AEM 6.1?

Try these:

1. Override the "activate" method in your class to instantiate the "ResourceResolver"..  here's a sample

@Component(immediate = true, label = "SiteContent Helper", description = "SiteContent Helper") @Service(value = SiteContentHelper.class) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "SiteContent Helper") }) public class SiteContentHelper { @Reference private ResourceResolverFactory resolverFactory; private ResourceResolver resourceResolver; private static Session session; private static final String AEM_SUBSERVICE = "readService"; @Activate private void activate(ComponentContext context) { Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, AEM_SUBSERVICE); try { resourceResolver = resolverFactory.getServiceResourceResolver(param); } catch (LoginException e) { log.info("..." + e); } } public String getPropertyValueFromRepository(SlingHttpServletRequest request, String propertyName) throws Exception { resourceResolver = request.getResourceResolver(); Session session = resourceResolver.adaptTo(Session.class); .... Node aNode = session.getNode(....); } }

2. I'm getting the "resourceResolver" from "request"

3. If in AEM 6.1.. i have defined a "Service User". The below link will help you with the process

http://stackoverflow.com/questions/31350548/resourceresolverfactory-getserviceresourceresolver-throws-exception-in-aem-6-1/31394583#31394583

harsha__
harsha__Author
Level 2
October 16, 2015

smacdonald2008 wrote...

See this AEM community artilce that talks about how to use JCR API to query JCR Data: 

https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

 

Thanks for ur reply @ smacdonald2008 . I have tried this example before posting the question. it is not working to the fullest.! there are some changes
we need to do in order to make it work, probably that is just me. yessmiley

Happy Helping !

harsha__
harsha__Author
Level 2
October 16, 2015

SurendraKonathala wrote...

Are you trying this on AEM 6.1?

Try these:

1. Override the "activate" method in your class to instantiate the "ResourceResolver"..  here's a sample

  1. @Component(immediate = true, label = "SiteContent Helper", description = "SiteContent Helper")
  2. @Service(value = SiteContentHelper.class)
  3. @Properties({
  4. @Property(name = Constants.SERVICE_DESCRIPTION, value = "SiteContent Helper") })
  5. public class SiteContentHelper {
  6. @Reference
  7. private ResourceResolverFactory resolverFactory;
  8. private ResourceResolver resourceResolver;
  9. private static Session session;
  10. private static final String AEM_SUBSERVICE = "readService";
  11.  
  12. @Activate
  13. private void activate(ComponentContext context) {
  14. Map<String, Object> param = new HashMap<String, Object>();
  15. param.put(ResourceResolverFactory.SUBSERVICE, AEM_SUBSERVICE);
  16.  
  17. try {
  18. resourceResolver = resolverFactory.getServiceResourceResolver(param);
  19. } catch (LoginException e) {
  20. log.info("..." + e);
  21. }
  22. }
  23.  
  24. public String getPropertyValueFromRepository(SlingHttpServletRequest request, String propertyName) throws Exception {
  25. resourceResolver = request.getResourceResolver();
  26. Session session = resourceResolver.adaptTo(Session.class);
  27. ....
  28. Node aNode = session.getNode(....);
  29. }
  30. }

2. I'm getting the "resourceResolver" from "request"

3. If in AEM 6.1.. i have defined a "Service User". The below link will help you with the process

http://stackoverflow.com/questions/31350548/resourceresolverfactory-getserviceresourceresolver-throws-exception-in-aem-6-1/31394583#31394583

 

@SurendraKonathala.. Sorry for the late reply..! I am Using AEM 6.0

I Could not get the  "ResourceResolverFactory" using "@Reference" . So i got resourceResolver from request and moved forward. I will definitely try the override of Activate method,after my project is done.

Thanks for Sharing a good amount of knowledge. yesyes

 
Level 3
December 9, 2015

Hi Surendra,

Is the sub service name (AEM_SUBSERVICE) "readService" your custom service?

I am upgrading to AEM 6.1 and looking to find suitable replacements to the deprecated methods getAdministrativeResourceResolver() and repository.loginAdministrative(null). I am using these methods in few common utility class methods which are not services. In such scenarios, what would be the sub service name?

In custom servlets(extends SlingAllMethodsServlet implements OptingServlet), i gave the sub service name as the servlet name(for example ContactUsFormServlet) but it does not work. I mean, i am able to get resource resolver object but it does not resolve the content path or cloud service configuration path.

Unlike your example, i do not have dedicated services for read operation and write operation.

Any help on this would be highly appreciated.

 

Thanks & Regards,

Srikanth Pogula.

December 10, 2015

Yes.. so i define the "readService" in OSGI (Apache Sling User Mapper) and a user name who can access the service. In 6.1 "admin" does not have default access, you will have to create a "system user". I have more details on how i did this here:

http://stackoverflow.com/questions/31350548/resourceresolverfactory-getserviceresourceresolver-throws-exception-in-aem-6-1/31394583#31394583