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]
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Happy Helping !
Views
Replies
Total Likes
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
@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
@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.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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:
Views
Replies
Total Likes
Views
Likes
Replies