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;
}
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);
}
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());
}
}
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;
}
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);
}
Aggregations