Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

JCR Session.itemExists or nodeExists returns pathnotfound exception instead of true or false

Avatar

Level 4

Hi All,

I am trying to check if a node exist under a path and set some property. but when i try to check a path through session it returns PathNotFoundException instead of true/false.

if(!destSession.nodeExists(dRootPath)) / if(!destSession.itemExists(dRootPath))

is there any other way?

Regards,

Vikram.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

According to the stacktrace you get the exception in the "session.getNode()" API call, not in "session.nodeExists()". Thus it's perfectly valid.

View solution in original post

8 Replies

Avatar

Level 10

How are you getting the session? Does the service-user that you use has "read" access on that path?

Avatar

Level 4

i am using service user with admin rights. for now the node is not exist, in future it might be. so i want to check if the node exist or not then set property.

As per Session (Content Repository for Java Technology API Version 2.0) it should return true/false

Regards,

Vikram

Avatar

Level 10

Use javax.jcr.Node's method named hasNode() - see Javadocs.

Node (Content Repository for Java Technology API Version 2.0) 

This method returns false if this node does not exist.

Avatar

Level 7

Hi,

could you post the stacktrace? It seems an interesting behavior.

Thanks,

Antonio

Avatar

Level 10

For testing sake - use the admin login call to get session and whitelist the OSGi bundle. See if the API works properly then.

Avatar

Level 4

Hi All,

please find the sample code (using admin session) and exception below.

@smacdonald2008

to use hasNode() from Node API we need to have the root node. i am trying to check the root node with session and then get it.

if(!destSession.nodeExists(dFolderPath)) {

log.info("Node not found. creating : " + dFolderPath);

Node rootFolderNode = destSession.getNode(dParentPath);

}else{

log.info("Folder Exist : " + dFolderPath);

}

Exception:

javax.jcr.PathNotFoundException: /content/dam/geometrixx/migration/snowboarding

at org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntryImpl.getDeepNodeEntry(NodeEntryImpl.java:395) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManagerImpl.getNodeEntry(HierarchyManagerImpl.java:137) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.ItemManagerImpl.getNode(ItemManagerImpl.java:168) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.SessionImpl.getNode(SessionImpl.java:513) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

Avatar

Level 7

Hi,

could you attach the entire java class? Just to try to reproduce it.

Thanks,

Antonio

Avatar

Correct answer by
Employee Advisor

According to the stacktrace you get the exception in the "session.getNode()" API call, not in "session.nodeExists()". Thus it's perfectly valid.