fazy
fazy

Reputation: 2155

Unable to move (rename) a node with Jackrabbit and WebDAV

I am trying to rename a node in Jackrabbit, but it fails as shown below. Given the node "/fooNode", I want it to be renamed to "/fooNodeRenamed".

My client is a simple Java program based on JavaDavexClient using Apache Jackrabbit 2.6.2 and Oracle Java 1.7.0_25 on Debian Wheezy.

Here is the code:

import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.*;
import ch.liip.jcr.davex.DavexClient;

public class Client
{
    public static void main(String[] args)
    {
        try {
            // Config
            String url = "http://localhost:8080/jackrabbit/server/";
            String sourceWorkspaceName = "test-preview";

            // Setup
            DavexClient Client = new DavexClient(url);
            Repository repo = Client.getRepository();
            Credentials sc = new SimpleCredentials("admin", "admin".toCharArray());
            Session sourceSession = repo.login(sc, sourceWorkspaceName);

            // Create a node
            Node fooNode = sourceSession.getRootNode().addNode("fooNode");
            sourceSession.save();

            // Rename the node - GIVES EXCEPTION
            sourceSession.move("/fooNode", "/fooNodeMoved");

            // This line is never reached
            sourceSession.save();

        } catch (RepositoryException e) {
            e.printStackTrace();
        }
    }
}

I am purging the workspace each time before running the above. Here is the exception:

javax.jcr.RepositoryException: Internal Server Error
        at org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:120)
        at org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:51)
        at org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:45)
        at org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.isGranted(RepositoryServiceImpl.java:904)
        at org.apache.jackrabbit.jcr2spi.WorkspaceManager.canRead(WorkspaceManager.java:695)
        at org.apache.jackrabbit.jcr2spi.state.ItemStateValidator.checkIsWritable(ItemStateValidator.java:199)
        at org.apache.jackrabbit.jcr2spi.state.ItemStateValidator.checkRemoveItem(ItemStateValidator.java:431)
        at org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager.visit(SessionItemStateManager.java:282)
        at org.apache.jackrabbit.jcr2spi.operation.Move.accept(Move.java:89)
        at org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager.execute(SessionItemStateManager.java:215)
        at org.apache.jackrabbit.jcr2spi.SessionImpl.move(SessionImpl.java:323)
        at Client.main(Client.java:32)
Caused by: org.apache.jackrabbit.webdav.DavException: Internal Server Error
        at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.getResponseException(DavMethodBase.java:165)
        at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.checkSuccess(DavMethodBase.java:174)
        at org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.isGranted(RepositoryServiceImpl.java:876)
        ... 8 more

Any idea what's wrong? Is it a problem with my code, or the environment?

Upvotes: 2

Views: 1612

Answers (3)

massfords
massfords

Reputation: 729

Falcon's workaround worked for me on Jackrabbit 2.7.0. I think was reported as fixed as part of JCR-3364. I just tried with Jackrabbit 2.7.3 and both Session.move and Workspace.move work as expected.

As with the bug report below, the user performing the move didn't have read access to the complete source and destination tree. The 2.7.0 version was mistakenly requiring read/remove/add access to the full tree as opposed to just the nodes and parents being moved.

Upvotes: 0

Nigel Sheridan-Smith
Nigel Sheridan-Smith

Reputation: 775

This is definitely an issue with jackrabbit-spi2dav - version 2.7.2. It wasn't present in version 2.5.2.

Upvotes: 0

Falcon
Falcon

Reputation: 3160

I had the same problem. I solved it by using the move method of the Workspace object instead of the Session object:

getSession().getWorkspace().move(node.getPath(), parentPath + newName);

Upvotes: 2

Related Questions