Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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]
1 Accepted Solution

Avatar

Correct answer by
Former Community Member

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-throw...

View solution in original post

6 Replies

Avatar

Correct answer by
Former Community Member

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-throw...

Avatar

Level 2

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 !

Avatar

Level 2

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-throw...

 

@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

 

Avatar

Level 3

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.

Avatar

Former Community Member

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-throw...

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----