Search in sources :

Example 1 with MultiStatusResponse

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

the class RepositoryServiceImpl method getPropertyInfo.

/**
     * @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
     */
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
    Path p = getPath(propertyId, sessionInfo);
    String uri = getURI(p, sessionInfo);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, LAZY_PROPERTY_NAME_SET, DavConstants.DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length != 1) {
            throw new ItemNotFoundException("Unable to retrieve the PropertyInfo. No such property " + uri);
        }
        MultiStatusResponse mresponse = mresponses[0];
        DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
        int propertyType = PropertyType.valueFromName(props.get(JCR_TYPE).getValue().toString());
        if (propertyType == PropertyType.BINARY) {
            DavProperty<?> lengthsProp = props.get(JCR_LENGTHS);
            if (lengthsProp != null) {
                // multivalued binary property
                long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
                QValue[] qValues = new QValue[lengths.length];
                for (int i = 0; i < lengths.length; i++) {
                    qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], uri, i);
                }
                return new PropertyInfoImpl(propertyId, p, propertyType, qValues);
            } else {
                // single valued binary property
                long length = Long.parseLong(props.get(JCR_LENGTH).getValue().toString());
                QValue qValue = getQValueFactory(sessionInfo).create(length, uri, QValueFactoryImpl.NO_INDEX);
                return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
            }
        } else if (props.contains(JCR_GET_STRING)) {
            // single valued non-binary property
            Object v = props.get(JCR_GET_STRING).getValue();
            String str = (v == null) ? "" : v.toString();
            QValue qValue = ValueFormat.getQValue(str, propertyType, getNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
            return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
        } else {
            // didn't expose the JCR_GET_STRING dav property.
            return super.getPropertyInfo(sessionInfo, propertyId);
        }
    } catch (IOException e) {
        log.error("Internal error while retrieving ItemInfo.", e);
        throw new RepositoryException(e.getMessage());
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with MultiStatusResponse

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

the class ValueLoader method loadType.

int loadType(String uri) throws RepositoryException, IOException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
        HttpResponse response = client.execute(request, context);
        request.checkSuccess(response);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length == 1) {
            DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
            DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
            if (type != null) {
                return PropertyType.valueFromName(type.getValue().toString());
            } else {
                throw new RepositoryException("Internal error. Cannot retrieve property type at " + uri);
            }
        } else {
            throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
        }
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavException(org.apache.jackrabbit.webdav.DavException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with MultiStatusResponse

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

the class URIResolverImpl method getNodeId.

private NodeId getNodeId(String uri, SessionInfo sessionInfo, boolean nodeIsGone) throws RepositoryException {
    IdURICache cache = getCache(sessionInfo.getWorkspaceName());
    if (cache.containsUri(uri)) {
        // id has been accessed before and is cached
        ItemId id = cache.getItemId(uri);
        if (id.denotesNode()) {
            return (NodeId) id;
        }
    }
    if (nodeIsGone) {
        throw new RepositoryException("Can't reconstruct nodeId from URI when the remote node is gone.");
    }
    // retrieve parentId from cache or by recursive calls
    NodeId parentId;
    if (isSameURI(uri, getRootItemUri(sessionInfo.getWorkspaceName()))) {
        parentId = null;
    } else {
        String parentUri = Text.getRelativeParent(uri, 1, true);
        parentId = getNodeId(parentUri, sessionInfo, false);
    }
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
        HttpResponse response = service.executeRequest(sessionInfo, request);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length != 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + uri);
        }
        return buildNodeId(parentId, uri, responses[0], sessionInfo.getWorkspaceName(), service.getNamePathResolver(sessionInfo));
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemId(org.apache.jackrabbit.spi.ItemId) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) NodeId(org.apache.jackrabbit.spi.NodeId) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 4 with MultiStatusResponse

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

the class RepositoryServiceImpl method getReferences.

@Override
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    String refType = weakReferences ? JcrRemotingConstants.JCR_WEAK_REFERENCES_LN : JcrRemotingConstants.JCR_REFERENCES_LN;
    nameSet.add(refType, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(nodeId, sessionInfo));
        }
        List<PropertyId> refIds = Collections.emptyList();
        for (MultiStatusResponse mresponse : mresponses) {
            if (isSameResource(uri, mresponse)) {
                DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
                DavProperty<?> p = props.get(refType, ItemResourceConstants.NAMESPACE);
                if (p != null) {
                    refIds = new ArrayList<PropertyId>();
                    HrefProperty hp = new HrefProperty(p);
                    for (String propHref : hp.getHrefs()) {
                        PropertyId propId = uriResolver.getPropertyId(resolve(uri, propHref), sessionInfo);
                        if (propertyName == null || propertyName.equals(propId.getName())) {
                            refIds.add(propId);
                        }
                    }
                }
            }
        }
        return refIds.iterator();
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 5 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse 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)

Aggregations

MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)27 RepositoryException (javax.jcr.RepositoryException)18 HttpResponse (org.apache.http.HttpResponse)18 DavException (org.apache.jackrabbit.webdav.DavException)17 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 IOException (java.io.IOException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)11 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 ArrayList (java.util.ArrayList)5 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)5 NodeId (org.apache.jackrabbit.spi.NodeId)4 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)4 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)4 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)4 Element (org.w3c.dom.Element)4 HashSet (java.util.HashSet)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 CurrentUserPrivilegeSetProperty (org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty)3 Privilege (org.apache.jackrabbit.webdav.security.Privilege)3