I am using magnolia for one of my project and in that I have created a REST Endpoint. The rest endpoint will read the nodes from my custom workspace and return the result to client. It is very simple.
If I run the below query in magnolia JCR Utils query app it is working fine and returning the correct results.
SELECT * FROM [mgnl:contentIndex]
Below is a screenshot
http://s1.postimg.org/gl59arw2n/correct_result.png
If I run the below code in my REST ENDPOINT Handler it is returning empty result set.
// Get JCR session for "dinnacoDriven" workspace
try {
Session session = MgnlContext.getJCRSession("dinnacoDriven");
StringBuilder queryBuilder = new StringBuilder("SELECT * FROM [mgnl:contentIndex]");
System.out.println(queryBuilder.toString());
Query query = session.getWorkspace().getQueryManager().createQuery(queryBuilder.toString(), Query.JCR_SQL2);
List<String> suggestions = new ArrayList<String>();
NodeIterator iterator = query.execute().getNodes();
while(iterator.hasNext()) {
System.out.println("next node");
Node node = iterator.nextNode();
suggestions.add(node.getProperty("title").getString());
}
return suggestions;
} catch(RepositoryException ex) {
throw new ServiceException("Internal Server Error", ex);
}
I can see in the logs that System.out.println(queryString.toString());
will print the exact same query that I am running above but next node
will never get printed. It is returning empty results.
Its been 12 hours since I am trying to figure out what is wrong with this code, but I can't find anything.
What is problem with my code ? Why it is returning empty result set ?
EDIT: Adding some additional information. When I am accessing from code, I am not logged in. I am accessing anonymously.
The contentIndex nodes are stored in dinnacoDriven workspace under root node contentIndex.
Some more information, I exported the dinnacoDriven workspace into xml, this is the xml file