Search in sources :

Example 1 with RequestData

use of org.apache.jackrabbit.server.util.RequestData in project jackrabbit by apache.

the class JcrRemotingServlet method doPost.

@Override
protected void doPost(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_POST, webdavRequest, davResource)) {
        // special remoting request: the defined parameters are exclusive
        // and cannot be combined.
        Session session = getRepositorySession(webdavRequest);
        RequestData data = new RequestData(webdavRequest, getTempDirectory(getServletContext()));
        String loc = null;
        try {
            String[] pValues;
            // multi-read over POST
            String[] includes = null;
            if ((pValues = data.getParameterValues(PARAM_CLONE)) != null) {
                loc = clone(session, pValues, davResource.getLocator());
            } else if ((pValues = data.getParameterValues(PARAM_COPY)) != null) {
                loc = copy(session, pValues, davResource.getLocator());
            } else if (data.getParameterValues(PARAM_DIFF) != null) {
                String targetPath = davResource.getLocator().getRepositoryPath();
                processDiff(session, targetPath, data, protectedRemoveManager);
            } else if ((pValues = data.getParameterValues(PARAM_INCLUDE)) != null && canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
                includes = pValues;
            } else {
                String targetPath = davResource.getLocator().getRepositoryPath();
                loc = modifyContent(session, targetPath, data, protectedRemoveManager);
            }
            // TODO: append entity
            if (loc == null) {
                webdavResponse.setStatus(HttpServletResponse.SC_OK);
                if (includes != null) {
                    webdavResponse.setContentType("text/plain;charset=utf-8");
                    JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
                    DavResourceLocator locator = davResource.getLocator();
                    String path = locator.getRepositoryPath();
                    Node node = session.getNode(path);
                    int depth = ((WrappingLocator) locator).getDepth();
                    writeMultiple(writer, node, includes, depth);
                }
            } else {
                webdavResponse.setHeader(DeltaVConstants.HEADER_LOCATION, loc);
                webdavResponse.setStatus(HttpServletResponse.SC_CREATED);
            }
        } catch (RepositoryException e) {
            log.warn(e.getMessage(), e);
            throw new JcrDavException(e);
        } catch (DiffException e) {
            log.warn(e.getMessage());
            Throwable cause = e.getCause();
            if (cause instanceof RepositoryException) {
                throw new JcrDavException((RepositoryException) cause);
            } else {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid diff format.");
            }
        } finally {
            data.dispose();
        }
    } else {
        super.doPost(webdavRequest, webdavResponse, davResource);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RequestData(org.apache.jackrabbit.server.util.RequestData) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 RequestData (org.apache.jackrabbit.server.util.RequestData)1 DavException (org.apache.jackrabbit.webdav.DavException)1 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)1 DavSession (org.apache.jackrabbit.webdav.DavSession)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1 JcrDavSession (org.apache.jackrabbit.webdav.jcr.JcrDavSession)1