Search in sources :

Example 1 with MultiStatus

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

the class URIResolverImpl method getItemUri.

String getItemUri(ItemId itemId, String workspaceName, SessionInfo sessionInfo) throws RepositoryException {
    IdURICache cache = getCache(workspaceName);
    // check if uri is available from cache
    if (cache.containsItemId(itemId)) {
        return cache.getUri(itemId);
    } else {
        StringBuffer uriBuffer = new StringBuffer();
        Path path = itemId.getPath();
        String uniqueID = itemId.getUniqueID();
        // resolver uuid part
        if (uniqueID != null) {
            ItemId uuidId = (path == null) ? itemId : service.getIdFactory().createNodeId(uniqueID);
            if (path != null && cache.containsItemId(uuidId)) {
                // append uri of parent node, that is already cached
                uriBuffer.append(cache.getUri(uuidId));
            } else {
                // try to request locate-by-uuid report to build the uri
                ReportInfo rInfo = new ReportInfo(JcrRemotingConstants.REPORT_LOCATE_BY_UUID, ItemResourceConstants.NAMESPACE);
                rInfo.setContentElement(DomUtil.hrefToXml(uniqueID, domFactory));
                HttpReport request = null;
                try {
                    String wspUri = getWorkspaceUri(workspaceName);
                    request = new HttpReport(wspUri, rInfo);
                    HttpResponse response = service.executeRequest(sessionInfo, request);
                    request.checkSuccess(response);
                    MultiStatus ms = request.getResponseBodyAsMultiStatus(response);
                    if (ms.getResponses().length == 1) {
                        String absoluteUri = resolve(wspUri, ms.getResponses()[0].getHref());
                        uriBuffer.append(absoluteUri);
                        cache.add(absoluteUri, uuidId);
                    } else {
                        throw new ItemNotFoundException("Cannot identify item with uniqueID " + uniqueID);
                    }
                } catch (IOException e) {
                    throw new RepositoryException(e.getMessage());
                } catch (DavException e) {
                    throw ExceptionConverter.generate(e);
                } finally {
                    if (request != null) {
                        request.releaseConnection();
                    }
                }
            }
        } else {
            // start build uri from root-item
            uriBuffer.append(getRootItemUri(workspaceName));
        }
        // resolve relative-path part unless it denotes the root-item
        if (path != null && !path.denotesRoot()) {
            String jcrPath = service.getNamePathResolver(sessionInfo).getJCRPath(path);
            if (!path.isAbsolute() && !uriBuffer.toString().endsWith("/")) {
                uriBuffer.append("/");
            }
            uriBuffer.append(Text.escapePath(jcrPath));
        }
        String itemUri = uriBuffer.toString();
        if (!cache.containsItemId(itemId)) {
            cache.add(itemUri, itemId);
        }
        return itemUri;
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) HttpReport(org.apache.jackrabbit.webdav.client.methods.HttpReport) DavException(org.apache.jackrabbit.webdav.DavException) ReportInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemId(org.apache.jackrabbit.spi.ItemId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with MultiStatus

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

the class RFC4918PropfindTest method testPropfindInclude.

public void testPropfindInclude() throws IOException, DavException, URISyntaxException {
    String testuri = this.root + "iftest";
    int status;
    try {
        HttpPut put = new HttpPut(testuri);
        put.setEntity(new StringEntity("1"));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertEquals("status: " + status, 201, status);
        DavPropertyNameSet names = new DavPropertyNameSet();
        names.add(DeltaVConstants.COMMENT);
        HttpPropfind propfind = new HttpPropfind(testuri, DavConstants.PROPFIND_ALL_PROP_INCLUDE, names, 0);
        HttpResponse resp = this.client.execute(propfind, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(207, status);
        MultiStatus multistatus = propfind.getResponseBodyAsMultiStatus(resp);
        MultiStatusResponse[] responses = multistatus.getResponses();
        assertEquals(1, responses.length);
        MultiStatusResponse response = responses[0];
        DavPropertySet found = response.getProperties(200);
        DavPropertySet notfound = response.getProperties(404);
        assertTrue(found.contains(DeltaVConstants.COMMENT) || notfound.contains(DeltaVConstants.COMMENT));
    } finally {
        delete(testuri);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) HttpPut(org.apache.http.client.methods.HttpPut)

Example 3 with MultiStatus

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

the class ExpandPropertyReport method getMultiStatus.

/**
     * Retrieve the multistatus object that is returned in response to the
     * expand-property report request.
     *
     * @return
     * @throws NullPointerException if info and resource have not been set.
     */
private MultiStatus getMultiStatus() {
    MultiStatus ms = new MultiStatus();
    addResponses(resource, info.getDepth(), ms);
    return ms;
}
Also used : MultiStatus(org.apache.jackrabbit.webdav.MultiStatus)

Example 4 with MultiStatus

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

the class AbstractWebdavServlet method doUpdate.

/**
     * The UPDATE method
     *
     * @param request
     * @param response
     * @param resource
     * @throws DavException
     * @throws IOException
     */
protected void doUpdate(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
    if (!(resource instanceof VersionControlledResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    UpdateInfo info = request.getUpdateInfo();
    MultiStatus ms = ((VersionControlledResource) resource).update(info);
    response.sendMultiStatus(ms);
}
Also used : MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) VersionControlledResource(org.apache.jackrabbit.webdav.version.VersionControlledResource) UpdateInfo(org.apache.jackrabbit.webdav.version.UpdateInfo)

Example 5 with MultiStatus

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

the class AbstractWebdavServlet method doMerge.

/**
     * The MERGE method
     *
     * @param request
     * @param response
     * @param resource
     * @throws DavException
     * @throws IOException
     */
protected void doMerge(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
    if (!(resource instanceof VersionControlledResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    MergeInfo info = request.getMergeInfo();
    MultiStatus ms = ((VersionControlledResource) resource).merge(info);
    response.sendMultiStatus(ms);
}
Also used : MergeInfo(org.apache.jackrabbit.webdav.version.MergeInfo) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) VersionControlledResource(org.apache.jackrabbit.webdav.version.VersionControlledResource)

Aggregations

MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)20 HttpResponse (org.apache.http.HttpResponse)8 RepositoryException (javax.jcr.RepositoryException)7 DavException (org.apache.jackrabbit.webdav.DavException)6 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)6 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)5 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)4 Element (org.w3c.dom.Element)4 Node (javax.jcr.Node)3 HttpClient (org.apache.http.client.HttpClient)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 IOException (java.io.IOException)2 EventListener (javax.jcr.observation.EventListener)2 Version (javax.jcr.version.Version)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)2 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)2 VersionControlledResource (org.apache.jackrabbit.webdav.version.VersionControlledResource)2 URI (java.net.URI)1 Item (javax.jcr.Item)1