After debugging for long long time, I found out the real problem. Actually there's a bug in the org.apache.jackrabbit.core.lock.LockInfo class of the '2.1.1' version of0 'jackRabbit-core' module, which is used in the latest sling builds. The bug is very simple. The logic of 'isExpired()' method is wrong (just revers). As a result after locking any non session scope lock on some node, the node is automatically unlocked by the 'LockManager'. So, I tried to modify the source of LockInfo in jackrabbit-core, build it again and then rebuild Sling. But it seems not to be working. Jackrabbit team already resolved this issue on their latest version, i.e. 2.2.2. So can anyone please update the jackrabbit version for Sling or just fix this issue or let me know how to build and integrate jackrabbit-core in Sling? Any help will be much appreciated. Thanks & Regards. On Tue, Jan 25, 2011 at 9:18 PM, Gazi Mushfiqur Rahman < gazimushfiqurrahman@gmail.com> wrote: > Hi all, > > I am facing a problem on locking a node or resource. I am using Jackrabbit > from Apache Sling and I have the following code (esp file) to lock a node: > > > > <% > var session = > request.getResourceResolver().adaptTo(Packages.javax.jcr.Session);; > var wasLockableNode = currentNode.isNodeType("mix:lockable"); > if (!wasLockableNode) { > currentNode.addMixin("mix:lockable"); > session.save(); > } > var lockOwner = null; > var workspace = session.workspace; > var lockManager = workspace.lockManager; > var wasLocked = lockManager.isLocked(currentNode.path); > var locked = false; > if (!wasLocked) { > var lock = lockManager.lock(currentNode.path, true, false, 120, > lockOwner); > lockManager.addLockToken(lock.lockToken); > locked = true; > } else { > var lock = lockManager.getLock(currentNode.path); > } > session.save(); > %> > > > <%= currentNode.title %> is locked: <%= locked %> > > >

> Is Locking Supported by Repository <%= > session.repository.getDescriptorValue(session.repository.OPTION_LOCKING_SUPPORTED).string > %>
> Is Locked <%= locked %>
> Lock Owner: <%= lock.lockOwner %>
> Lock Token: <%= lock.lockToken %>
> Is Deep: <%= lock.deep %>
> Is Session Scoped: <%= lock.sessionScoped %>
> Is Current Session Owning Lock: id="isLockOwningSession"><%= lock.lockOwningSession %>
> Was lockable node: <%= wasLockableNode %>
> Was Locked: <%= wasLocked %>
> Remaining Seconds for the Lock <%= lock.secondsRemaining %>
/> > Current Lock Tokens: <%= > Packages.java.util.Arrays.toString(lockManager.lockTokens) %>
>

> > > > After executing the above script, I find that the node was locked. But if I > execute the following script just after executing the previous one, I find > that node ia not locked!: > > > > > <%= currentNode.title %> > > > > >

<%= currentNode.title %>

>

> Title: <%= currentNode.title %>
> Is Locked: <%= currentNode.locked %>
>

> > >
> > Can anyone help me to find out the problem in my code or give me suggestion > on how to implement locking on nodes using Sling? > > Thanks & Regards. > >