Search in sources :

Example 6 with ReportInfo

use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method getRepositoryDescriptors.

@Override
public Map<String, QValue[]> getRepositoryDescriptors() throws RepositoryException {
    if (descriptors.isEmpty()) {
        ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REPOSITORY_DESCRIPTORS, ItemResourceConstants.NAMESPACE);
        HttpReport request = null;
        try {
            request = new HttpReport(uriResolver.getRepositoryUri(), info);
            HttpResponse response = executeRequest(null, request);
            int sc = response.getStatusLine().getStatusCode();
            if (sc == HttpStatus.SC_UNAUTHORIZED || sc == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
                // JCR-3076: Mandatory authentication prevents us from
                // accessing the descriptors on the server, so instead
                // of failing with an exception we simply return an empty
                // set of descriptors
                log.warn("Authentication required to access repository descriptors");
                return descriptors;
            }
            request.checkSuccess(response);
            Document doc = request.getResponseBodyAsDocument(response.getEntity());
            if (doc != null) {
                Element rootElement = doc.getDocumentElement();
                ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
                while (nsElems.hasNext()) {
                    Element elem = nsElems.nextElement();
                    String key = DomUtil.getChildText(elem, JcrRemotingConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
                    ElementIterator it = DomUtil.getChildren(elem, JcrRemotingConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
                    List<QValue> vs = new ArrayList<QValue>();
                    while (it.hasNext()) {
                        Element dv = it.nextElement();
                        String descriptor = DomUtil.getText(dv);
                        if (key != null && descriptor != null) {
                            String typeStr = (DomUtil.getAttribute(dv, JcrRemotingConstants.ATTR_VALUE_TYPE, null));
                            int type = (typeStr == null) ? PropertyType.STRING : PropertyType.valueFromName(typeStr);
                            vs.add(getQValueFactory().create(descriptor, type));
                        } else {
                            log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
                        }
                    }
                    descriptors.put(key, vs.toArray(new QValue[vs.size()]));
                }
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        } catch (DavException e) {
            throw ExceptionConverter.generate(e);
        } finally {
            if (request != null) {
                request.releaseConnection();
            }
        }
    }
    return descriptors;
}
Also used : HttpReport(org.apache.jackrabbit.webdav.client.methods.HttpReport) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ReportInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 7 with ReportInfo

use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

@Override
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
    HttpReport request = null;
    try {
        ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_NODETYPES, ItemResourceConstants.NAMESPACE);
        info.setContentElement(DomUtil.createElement(DomUtil.createDocument(), NodeTypeConstants.XML_REPORT_ALLNODETYPES, ItemResourceConstants.NAMESPACE));
        String workspaceUri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
        request = new HttpReport(workspaceUri, info);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        Document reportDoc = request.getResponseBodyAsDocument(response.getEntity());
        return retrieveQNodeTypeDefinitions(sessionInfo, reportDoc);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : 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) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Aggregations

ReportInfo (org.apache.jackrabbit.webdav.version.report.ReportInfo)7 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5 HttpResponse (org.apache.http.HttpResponse)5 DavException (org.apache.jackrabbit.webdav.DavException)5 HttpReport (org.apache.jackrabbit.webdav.client.methods.HttpReport)5 Document (org.w3c.dom.Document)4 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ItemId (org.apache.jackrabbit.spi.ItemId)1 Path (org.apache.jackrabbit.spi.Path)1 QValue (org.apache.jackrabbit.spi.QValue)1 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1