Search in sources :

Example 91 with PathNotFoundException

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

the class ItemStateHierarchyManagerDeadlockTest method clearInvRootNode.

public void clearInvRootNode() {
    System.out.println("Clear test repository InventoryTest.");
    Session session = null;
    try {
        session = login();
        Node root = session.getRootNode();
        try {
            Node inv = root.getNode("InventoryTest");
            inv.remove();
            session.save();
        } catch (PathNotFoundException pnfx) {
            System.err.println(" The root node <InventoryTest> is not available.");
        }
    } catch (Exception e) {
        System.err.println("Exception in clear test repository:" + e.getMessage());
        e.printStackTrace();
    } finally {
        if (session != null)
            session.logout();
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) IOException(java.io.IOException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 92 with PathNotFoundException

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

the class ItemStateHierarchyManagerDeadlockTest method getInvRootNode.

private Node getInvRootNode(Session session) throws RepositoryException {
    Node root = session.getRootNode();
    Node inventoryRoot;
    try {
        inventoryRoot = root.getNode("InventoryTest");
    } catch (PathNotFoundException pnfx) {
        System.err.println(" The root node <InventoryTest> is not available. So creating new root Node.");
        inventoryRoot = root.addNode("InventoryTest");
        session.save();
    }
    return inventoryRoot;
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 93 with PathNotFoundException

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

the class AbstractWriteTest method testDeniedPermission.

public void testDeniedPermission() throws RepositoryException, NotExecutableException, InterruptedException {
    /* precondition:
           testuser must have READ-only permission on test-node and below
         */
    checkReadOnly(path);
    // withdraw READ privilege to 'testUser' at 'path'
    Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
    withdrawPrivileges(childNPath, privileges, getRestrictions(superuser, childNPath));
    /*
         testuser must now have
         - READ-only permission at path
         - READ-only permission for the child-props of path

         testuser must not have
         - any permission on child-node and all its subtree
        */
    // must still have read-access to path, ...
    Session testSession = getTestSession();
    assertTrue(testSession.hasPermission(path, "read"));
    Node n = testSession.getNode(path);
    // ... siblings of childN
    testSession.getNode(childNPath2);
    // ... and props of path
    assertTrue(n.getProperties().hasNext());
    //testSession must not have access to 'childNPath'
    assertFalse(testSession.itemExists(childNPath));
    try {
        testSession.getNode(childNPath);
        fail("Read access has been denied -> cannot retrieve child node.");
    } catch (PathNotFoundException e) {
    // ok.
    }
    /*
        -> must not have access to subtree below 'childNPath'
        */
    assertFalse(testSession.itemExists(childchildPPath));
    try {
        testSession.getItem(childchildPPath);
        fail("Read access has been denied -> cannot retrieve prop below child node.");
    } catch (PathNotFoundException e) {
    // ok.
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session)

Example 94 with PathNotFoundException

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

the class DavResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the specified locator and request
     * objects. Note, that in contrast to
     * {@link #createResource(DavResourceLocator, DavSession)} the locator may
     * point to a non-existing resource.
     * <p>
     * If the request contains a {@link org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getLabel()
     * Label header}, the resource is build from the indicated
     * {@link org.apache.jackrabbit.webdav.version.VersionResource version} instead.
     *
     * @param locator
     * @param request
     * @param response
     * @return
     * @see DavResourceFactory#createResource(org.apache.jackrabbit.webdav.DavResourceLocator, org.apache.jackrabbit.webdav.DavServletRequest, org.apache.jackrabbit.webdav.DavServletResponse)
     */
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
    JcrDavSession.checkImplementation(request.getDavSession());
    JcrDavSession session = (JcrDavSession) request.getDavSession();
    DavResource resource;
    String type = request.getParameter("type");
    if (locator.isRootLocation()) {
        // root
        resource = new RootCollection(locator, session, this);
    } else if ("journal".equals(type) && locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // feed/event journal resource
        try {
            EventJournal ej = session.getRepositorySession().getWorkspace().getObservationManager().getEventJournal();
            if (ej == null) {
                throw new DavException(HttpServletResponse.SC_NOT_IMPLEMENTED, "event journal not supported");
            }
            resource = new EventJournalResourceImpl(ej, locator, session, request, this);
        } catch (AccessDeniedException ex) {
            // EventJournal only allowed for admin?
            throw new DavException(HttpServletResponse.SC_UNAUTHORIZED, ex);
        } catch (RepositoryException ex) {
            throw new DavException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
    } else if (locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // workspace resource
        resource = new WorkspaceResourceImpl(locator, session, this);
    } else {
        // resource corresponds to a repository item
        try {
            resource = createResourceForItem(locator, session);
            Item item = getItem(session, locator);
            boolean versionable = item.isNode() && ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);
            /* if the created resource is version-controlled and the request
                contains a Label header, the corresponding Version must be used
                instead.*/
            if (request instanceof DeltaVServletRequest && versionable) {
                String labelHeader = ((DeltaVServletRequest) request).getLabel();
                if (labelHeader != null && DavMethods.isMethodAffectedByLabel(request) && isVersionControlled(resource)) {
                    Version v = ((Node) item).getVersionHistory().getVersionByLabel(labelHeader);
                    DavResourceLocator vloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), v.getPath(), false);
                    resource = new VersionItemCollection(vloc, session, this, v);
                }
            }
        } catch (PathNotFoundException e) {
            /* item does not exist yet: create the default resources
                Note: MKCOL request forces a collection-resource even if there already
                exists a repository-property with the given path. the MKCOL will
                in that particular case fail with a 405 (method not allowed).*/
            if (DavMethods.getMethodCode(request.getMethod()) == DavMethods.DAV_MKCOL) {
                resource = new VersionControlledItemCollection(locator, session, this, null);
            } else {
                resource = new DefaultItemResource(locator, session, this, null);
            }
        } catch (RepositoryException e) {
            log.error("Failed to build resource from item '" + locator.getRepositoryPath() + "'");
            throw new JcrDavException(e);
        }
    }
    if (request instanceof TransactionDavServletRequest && resource instanceof TransactionResource) {
        ((TransactionResource) resource).init(txMgr, ((TransactionDavServletRequest) request).getTransactionId());
    }
    if (resource instanceof ObservationResource) {
        ((ObservationResource) resource).init(subsMgr);
    }
    return resource;
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) TransactionResource(org.apache.jackrabbit.webdav.transaction.TransactionResource) EventJournal(javax.jcr.observation.EventJournal) Item(javax.jcr.Item) Version(javax.jcr.version.Version) TransactionDavServletRequest(org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource) DeltaVServletRequest(org.apache.jackrabbit.webdav.version.DeltaVServletRequest) VersionItemCollection(org.apache.jackrabbit.webdav.jcr.version.VersionItemCollection) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 95 with PathNotFoundException

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

the class AbstractItemResource method copy.

/**
     * Copies the underlying repository item to the indicated destination. If
     * the locator of the specified destination resource indicates a different
     * workspace, {@link Workspace#copy(String, String, String)} is used to perform
     * the copy operation, {@link Workspace#copy(String, String)} otherwise.
     * <p>
     * Note, that this implementation does not support shallow copy.
     *
     * @param destination
     * @param shallow
     * @throws DavException
     * @see DavResource#copy(DavResource, boolean)
     * @see Workspace#copy(String, String)
     * @see Workspace#copy(String, String, String)
     */
@Override
public void copy(DavResource destination, boolean shallow) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    // TODO: support shallow and deep copy is required by RFC 2518
    if (shallow) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");
    }
    try {
        String itemPath = getLocator().getRepositoryPath();
        String destItemPath = destination.getLocator().getRepositoryPath();
        Workspace workspace = getRepositorySession().getWorkspace();
        if (getLocator().isSameWorkspace(destination.getLocator())) {
            workspace.copy(itemPath, destItemPath);
        } else {
            log.error("Copy between workspaces is not yet implemented (src: '" + getHref() + "', dest: '" + destination.getHref() + "')");
            throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
        }
    } catch (PathNotFoundException e) {
        // according to RFC 2518, should not occur
        throw new DavException(DavServletResponse.SC_NOT_FOUND, e.getMessage());
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Workspace(javax.jcr.Workspace)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6