I have locked a node using the below code
ocm.lock("/path1", true, true);
Here the 3rd argument is true which states that it is a Open-scoped Locks.
And it is successfully locked.
But now i am writing a new Java Program to unlock a node.
boolean b1 = ocm.isLocked("/path1");
System.out.println(b1); // RETURNS TRUE.
Node n = session.getNode("/path1");
Lock l = n.getLock();
ocm.unlock("/path1", l.getLockToken());
But i am getting a exception here. And it is not unlocking the node.
ERROR [main] ObjectContentManagerImpl.java:957 Cannot unlock path: /path1 Jcr user: admin has no lock token to do this. Lock was placed with user: admin
Exception in thread "main" org.apache.jackrabbit.ocm.exception.IllegalUnlockException
at org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl.unlock(ObjectContentManagerImpl.java:958)
at ocm.UnlockNode.main(UnlockNode.java:36)
How i can unlock the node?
My UnlockNode.java code.
Repository repository = new URLRemoteRepository("http://localhost:8083/rmi");
Session session = repository.login(new SimpleCredentials("admin","admin".toCharArray()));
Mapper mapper = new AnnotationMapperImpl(classes);
ObjectContentManager ocm = new ObjectContentManagerImpl(session, mapper);
LockManager lm = session.getWorkspace().getLockManager();
lm.addLockToken("a096a79c-5edf-4a17-baa4-aba01f8013d8-J");
boolean b1 = ocm.isLocked("/path1");
System.out.println(b1);
try {
ocm.unlock("/path1","a096a79c-5edf-4a17-baa4-aba01f8013d8-J");
}catch (Exception e) {
System.out.println(e);
}
Thanks.
Sounds like you’re trying to get the lock from another session…
Either get the lock token, after locking, and store it for later or write your own LockManager with a checkUnlock() method that does what you want it to.