Search in sources :

Example 41 with DavException

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

the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.

private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
    HttpPropfind request = null;
    try {
        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 PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new PrivilegeDefinition[0];
        } else {
            // build PrivilegeDefinition(s) from the supported-privileges dav property
            Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
            fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
            List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
            for (Name privilegeName : spMap.keySet()) {
                SupportedPrivilege sp = spMap.get(privilegeName);
                Set<Name> aggrnames = null;
                SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
                if (aggregates != null && aggregates.length > 0) {
                    aggrnames = new HashSet<Name>();
                    for (SupportedPrivilege aggregate : aggregates) {
                        Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
                        aggrnames.add(aggregateName);
                    }
                }
                PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
                pDefs.add(def);
            }
            return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege)

Example 42 with DavException

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

the class RepositoryServiceImpl method move.

@Override
public void move(SessionInfo sessionInfo, NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws RepositoryException {
    String uri = getItemUri(srcNodeId, sessionInfo);
    String destUri = getItemUri(destParentNodeId, destName, sessionInfo);
    if (isDavClass3(sessionInfo)) {
        destUri = obtainAbsolutePathFromUri(destUri);
    }
    HttpMove request = new HttpMove(uri, destUri, false);
    try {
        initMethod(request, sessionInfo);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        // need to clear the cache as the move may have affected nodes with
        // uuid.
        clearItemUriCache(sessionInfo);
    } catch (IOException ex) {
        throw new RepositoryException(ex);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e, request);
    } finally {
        request.releaseConnection();
    }
}
Also used : HttpMove(org.apache.jackrabbit.webdav.client.methods.HttpMove) DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 43 with DavException

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

the class RepositoryServiceImpl method internalSetNamespaces.

/**
 * @param sessionInfo
 * @param namespaces
 * @throws NamespaceException
 * @throws UnsupportedRepositoryOperationException
 * @throws AccessDeniedException
 * @throws RepositoryException
 */
private void internalSetNamespaces(SessionInfo sessionInfo, Map<String, String> namespaces) throws RepositoryException {
    DavPropertySet setProperties = new DavPropertySet();
    setProperties.add(createNamespaceProperty(namespaces));
    HttpProppatch request = null;
    try {
        String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
        request = new HttpProppatch(uri, setProperties, new DavPropertyNameSet());
        initMethod(request, sessionInfo, true);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpProppatch(org.apache.jackrabbit.webdav.client.methods.HttpProppatch) DavException(org.apache.jackrabbit.webdav.DavException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 44 with DavException

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

the class RepositoryServiceImpl method removeVersionLabel.

@Override
public void removeVersionLabel(SessionInfo sessionInfo, NodeId versionHistoryId, NodeId versionId, Name label) throws RepositoryException {
    HttpLabel request = null;
    try {
        String uri = getItemUri(versionId, sessionInfo);
        String strLabel = getNamePathResolver(sessionInfo).getJCRName(label);
        request = new HttpLabel(uri, new LabelInfo(strLabel, LabelInfo.TYPE_REMOVE));
        initMethod(request, sessionInfo, !isUnLockMethod(request));
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException ex) {
        throw ExceptionConverter.generate(ex);
    } finally {
        request.releaseConnection();
    }
}
Also used : LabelInfo(org.apache.jackrabbit.webdav.version.LabelInfo) DavException(org.apache.jackrabbit.webdav.DavException) HttpLabel(org.apache.jackrabbit.webdav.client.methods.HttpLabel) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 45 with DavException

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

the class RepositoryServiceImpl method subscribe.

private String subscribe(String uri, SubscriptionInfo subscriptionInfo, String subscriptionId, SessionInfo sessionInfo, String batchId) throws RepositoryException {
    HttpSubscribe request = null;
    try {
        request = new HttpSubscribe(uri, subscriptionInfo, subscriptionId);
        initMethod(request, sessionInfo);
        if (batchId != null) {
            // add batchId as separate header
            CodedUrlHeader ch = new CodedUrlHeader(TransactionConstants.HEADER_TRANSACTIONID, batchId);
            request.setHeader(ch.getHeaderName(), ch.getHeaderValue());
        }
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        org.apache.jackrabbit.webdav.observation.Subscription[] subs = request.getResponseBodyAsSubscriptionDiscovery(response).getValue();
        if (subs.length == 1) {
            this.remoteServerProvidesNodeTypes = subs[0].eventsProvideNodeTypeInformation();
            this.remoteServerProvidesNoLocalFlag = subs[0].eventsProvideNoLocalFlag();
        }
        return request.getSubscriptionId(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Subscription(org.apache.jackrabbit.spi.Subscription) HttpSubscribe(org.apache.jackrabbit.webdav.client.methods.HttpSubscribe)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)157 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)61 HttpResponse (org.apache.http.HttpResponse)47 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavResource (org.apache.jackrabbit.webdav.DavResource)30 Element (org.w3c.dom.Element)29 ArrayList (java.util.ArrayList)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)18 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)14 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)10 Test (org.junit.Test)9 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8