Search in sources :

Example 1 with DavSession

use of org.apache.jackrabbit.webdav.DavSession in project jackrabbit by apache.

the class ResourceFactoryImpl method getNode.

/**
     * Returns the <code>Node</code> corresponding to the given locator or
     * <code>null</code> if it does not exist or if the existing item represents
     * a <code>Property</code>.
     *
     * @param sessionImpl
     * @param locator
     * @return
     * @throws RepositoryException
     */
private Node getNode(DavSession sessionImpl, DavResourceLocator locator) throws RepositoryException {
    Node node = null;
    try {
        String repoPath = locator.getRepositoryPath();
        if (repoPath != null) {
            Session session = ((JcrDavSession) sessionImpl).getRepositorySession();
            Item item = session.getItem(repoPath);
            if (item instanceof Node) {
                node = (Node) item;
            }
        // else: item is a property -> return null
        }
    } catch (PathNotFoundException e) {
    // item does not exist (yet). return null -> create null-resource
    }
    return node;
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) PathNotFoundException(javax.jcr.PathNotFoundException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 2 with DavSession

use of org.apache.jackrabbit.webdav.DavSession in project jackrabbit by apache.

the class DavSessionProviderImpl method releaseSession.

/**
     * Only removes the <code>DavSession</code> object from the given request object.
     * and remove all the lock tokens from the underlying repository session
     * in order make sure they can be reset when attaching a session to the
     * next request. Finally the session provider is informed, that the
     * session is no longer used.
     *
     * @param request
     * @see DavSessionProvider#releaseSession(org.apache.jackrabbit.webdav.WebdavRequest)
     */
public void releaseSession(WebdavRequest request) {
    DavSession ds = request.getDavSession();
    if (ds != null && ds instanceof DavSessionImpl) {
        Session repSession = ((DavSessionImpl) ds).getRepositorySession();
        for (String lockToken : repSession.getLockTokens()) {
            repSession.removeLockToken(lockToken);
        }
        sesProvider.releaseSession(repSession);
        log.debug("Releasing session '" + ds + "' from request '" + request + "'");
    }
    // else : session is null. nothing to be done.
    request.setDavSession(null);
}
Also used : DavSession(org.apache.jackrabbit.webdav.DavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 3 with DavSession

use of org.apache.jackrabbit.webdav.DavSession in project jackrabbit by apache.

the class DavSessionProviderImpl method attachSession.

/**
     * Acquires a DavSession. Upon success, the WebdavRequest will
     * reference that session.
     *
     * A session will not be available if an exception is thrown.
     *
     * @param request
     * @throws org.apache.jackrabbit.webdav.DavException if a problem occurred while obtaining the session
     * @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
     */
public boolean attachSession(WebdavRequest request) throws DavException {
    try {
        // retrieve the workspace name
        String workspaceName = request.getRequestLocator().getWorkspaceName();
        // empty workspaceName rather means default -> must be 'null'
        if (workspaceName != null && "".equals(workspaceName)) {
            workspaceName = null;
        }
        // login to repository
        Session repSession = sesProvider.getSession(request, repository, workspaceName);
        if (repSession == null) {
            log.debug("Could not to retrieve a repository session.");
            return false;
        }
        DavSession ds = new DavSessionImpl(repSession);
        log.debug("Attaching session '" + ds + "' to request '" + request + "'");
        request.setDavSession(ds);
        return true;
    } catch (NoSuchWorkspaceException e) {
        // which seems not appropriate here
        throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    } catch (ServletException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ServletException(javax.servlet.ServletException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RepositoryException(javax.jcr.RepositoryException) DavSession(org.apache.jackrabbit.webdav.DavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 4 with DavSession

use of org.apache.jackrabbit.webdav.DavSession in project jackrabbit by apache.

the class AbstractJcrReport method init.

/**
     * Performs basic validation checks common to all JCR specific reports.
     *
     * @param resource
     * @param info
     * @throws DavException
     * @see Report#init(DavResource, ReportInfo)
     */
public void init(DavResource resource, ReportInfo info) throws DavException {
    if (resource == null || info == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Unable to run report: WebDAV Resource and ReportInfo must not be null.");
    }
    if (!getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Expected report type: '" + getType().getReportName() + "', found: '" + info.getReportName() + ";" + "'.");
    }
    if (info.getDepth() > DavConstants.DEPTH_0) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid Depth header: " + info.getDepth());
    }
    DavSession davSession = resource.getSession();
    if (davSession == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The resource must provide a non-null session object in order to create '" + getType().getReportName() + "' report.");
    }
    session = JcrDavSession.getRepositorySession(resource.getSession());
    if (session == null) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal error: Unable to access repository session.");
    }
    reportInfo = info;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 5 with DavSession

use of org.apache.jackrabbit.webdav.DavSession in project jackrabbit by apache.

the class JCRWebdavServer method releaseSession.

/**
     * Releases the reference from the request to the session. If no further
     * references to the session exist, the session will be removed from the
     * cache.
     *
     * @param request
     * @see DavSessionProvider#releaseSession(org.apache.jackrabbit.webdav.WebdavRequest)
     */
public void releaseSession(WebdavRequest request) {
    DavSession session = request.getDavSession();
    if (session != null) {
        session.removeReference(request);
    }
    // remove the session from the request
    request.setDavSession(null);
}
Also used : JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) DavSession(org.apache.jackrabbit.webdav.DavSession)

Aggregations

DavSession (org.apache.jackrabbit.webdav.DavSession)6 JcrDavSession (org.apache.jackrabbit.webdav.jcr.JcrDavSession)4 Session (javax.jcr.Session)3 DavException (org.apache.jackrabbit.webdav.DavException)2 Item (javax.jcr.Item)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 Node (javax.jcr.Node)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 RepositoryException (javax.jcr.RepositoryException)1 ServletException (javax.servlet.ServletException)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1