Search in sources :

Example 66 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class XATest method testAddNodeCommit.

/**
     * Add a node inside a transaction and commit changes. Make sure
     * node exists for other sessions only after commit.
     * @throws Exception
     */
public void testAddNodeCommit() throws Exception {
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser);
    // start transaction
    utx.begin();
    // add node and save
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixReferenceable);
    testRootNode.save();
    // assertion: node exists in this session
    try {
        superuser.getNodeByUUID(n.getUUID());
    } catch (ItemNotFoundException e) {
        fail("New node not visible after save()");
    }
    // assertion: node does not exist in other session
    Session otherSuperuser = getHelper().getSuperuserSession();
    try {
        otherSuperuser.getNodeByUUID(n.getUUID());
        fail("Uncommitted node visible for other session");
    } catch (ItemNotFoundException e) {
    /* expected */
    }
    // commit
    utx.commit();
    // assertion: node exists in this session
    try {
        superuser.getNodeByUUID(n.getUUID());
    } catch (ItemNotFoundException e) {
        fail("Committed node not visible in this session");
    }
    // assertion: node also exists in other session
    try {
        otherSuperuser.getNodeByUUID(n.getUUID());
    } catch (ItemNotFoundException e) {
        fail("Committed node not visible in other session");
    }
    // logout
    otherSuperuser.logout();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException) Session(javax.jcr.Session)

Example 67 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class XATest method testDistributedThreadAccess.

/**
     * Tests two different Threads for prepare and commit in a Transaction
     */
public void testDistributedThreadAccess() throws Exception {
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser, true);
    //utx.setTransactionTimeout(50);
    // start transaction
    utx.begin();
    // add node and save
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixReferenceable);
    testRootNode.save();
    // assertion: node exists in this session
    try {
        superuser.getNodeByUUID(n.getUUID());
    } catch (ItemNotFoundException e) {
        fail("New node not visible after save()");
    }
    // commit
    utx.commit();
    // assertion: node exists in this session
    try {
        superuser.getNodeByUUID(n.getUUID());
    } catch (ItemNotFoundException e) {
        fail("Committed node not visible in this session");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 68 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class JcrRemotingServlet method doGet.

@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
        // return json representation of the requested resource
        DavResourceLocator locator = davResource.getLocator();
        String path = locator.getRepositoryPath();
        Session session = getRepositorySession(webdavRequest);
        try {
            Node node = session.getNode(path);
            int depth = ((WrappingLocator) locator).getDepth();
            webdavResponse.setContentType("text/plain;charset=utf-8");
            webdavResponse.setStatus(DavServletResponse.SC_OK);
            JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
            String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
            if (includes == null) {
                if (depth < BatchReadConfig.DEPTH_INFINITE) {
                    NodeType type = node.getPrimaryNodeType();
                    depth = brConfig.getDepth(type.getName());
                }
                writer.write(node, depth);
            } else {
                writeMultiple(writer, node, includes, depth);
            }
        } catch (PathNotFoundException e) {
            // properties cannot be requested as json object.
            throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
        } catch (RepositoryException e) {
            // should only get here if the item does not exist.
            log.debug(e.getMessage());
            throw new JcrDavException(e);
        }
    } else {
        super.doGet(webdavRequest, webdavResponse, davResource);
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) NodeType(javax.jcr.nodetype.NodeType) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 69 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit-oak by apache.

the class NodeDelegate method unlock.

public void unlock() throws RepositoryException {
    String path = getPath();
    Root root = sessionDelegate.getContentSession().getLatestRoot();
    Tree tree = root.getTree(path);
    if (!tree.exists()) {
        throw new ItemNotFoundException("Node " + path + " does not exist");
    } else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
        throw new LockException("Node " + path + " is not lockable");
    } else if (!tree.hasProperty(JCR_LOCKISDEEP)) {
        throw new LockException("Node " + path + " is not locked");
    }
    try {
        tree.removeProperty(JCR_LOCKISDEEP);
        tree.removeProperty(JCR_LOCKOWNER);
        sessionDelegate.commit(root);
    } catch (CommitFailedException e) {
        if (e.isAccessViolation()) {
            throw new AccessControlException("Access denied to unlock node " + path, e);
        } else {
            throw new RepositoryException("Unable to unlock node " + path, e);
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) LockException(javax.jcr.lock.LockException) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 70 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit-oak by apache.

the class NodeDelegate method lock.

public void lock(boolean isDeep) throws RepositoryException {
    String path = getPath();
    Root root = sessionDelegate.getContentSession().getLatestRoot();
    Tree tree = root.getTree(path);
    if (!tree.exists()) {
        throw new ItemNotFoundException("Node " + path + " does not exist");
    } else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
        throw new LockException("Node " + path + " is not lockable");
    } else if (tree.hasProperty(JCR_LOCKISDEEP)) {
        throw new LockException("Node " + path + " is already locked");
    }
    // look for locked ancestor
    Tree inheritedLock = findLock(tree, true);
    if (inheritedLock != null) {
        throw new LockException("Node already indirectly locked by " + inheritedLock.getPath());
    }
    // scan for locked descendant
    if (isDeep) {
        Tree descendantLock = findDescendantLock(tree);
        if (descendantLock != null) {
            throw new LockException("Lock conflicts with lock hold by " + descendantLock.getPath());
        }
    }
    try {
        String owner = sessionDelegate.getAuthInfo().getUserID();
        if (owner == null) {
            owner = "";
        }
        tree.setProperty(JCR_LOCKISDEEP, isDeep);
        tree.setProperty(JCR_LOCKOWNER, owner);
        sessionDelegate.commit(root);
    } catch (CommitFailedException e) {
        if (e.isAccessViolation()) {
            throw new AccessControlException("Access denied to lock node " + path, e);
        } else {
            throw new RepositoryException("Unable to lock node " + path, e);
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) LockException(javax.jcr.lock.LockException) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)139 RepositoryException (javax.jcr.RepositoryException)61 Node (javax.jcr.Node)44 Path (org.apache.jackrabbit.spi.Path)25 PathNotFoundException (javax.jcr.PathNotFoundException)23 NodeId (org.apache.jackrabbit.core.id.NodeId)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)16 IOException (java.io.IOException)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodeState (org.apache.jackrabbit.core.state.NodeState)14 Name (org.apache.jackrabbit.spi.Name)14 AccessDeniedException (javax.jcr.AccessDeniedException)13 HttpResponse (org.apache.http.HttpResponse)13 DavException (org.apache.jackrabbit.webdav.DavException)13 ItemExistsException (javax.jcr.ItemExistsException)12 Session (javax.jcr.Session)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)10