Search in sources :

Example 1 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project archiva by apache.

the class DavResourceTest method testDeleteCollection.

@Test
public void testDeleteCollection() throws Exception {
    Path dir = baseDir.resolve("testdir");
    try {
        assertNotNull(Files.createDirectories(dir));
        DavResource directoryResource = getDavResource("/testdir", dir);
        directoryResource.getCollection().removeMember(directoryResource);
        assertFalse(Files.exists(dir));
    } finally {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(dir);
    }
}
Also used : Path(java.nio.file.Path) DavResource(org.apache.jackrabbit.webdav.DavResource) Test(org.junit.Test)

Example 2 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project archiva by apache.

the class DavResourceTest method testDeleteNonExistantResourceShould404.

@Test
public void testDeleteNonExistantResourceShould404() throws Exception {
    Path dir = baseDir.resolve("testdir");
    try {
        DavResource directoryResource = getDavResource("/testdir", dir);
        directoryResource.getCollection().removeMember(directoryResource);
        fail("Did not throw DavException");
    } catch (DavException e) {
        assertEquals(DavServletResponse.SC_NOT_FOUND, e.getErrorCode());
    }
}
Also used : Path(java.nio.file.Path) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Test(org.junit.Test)

Example 3 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project archiva by apache.

the class ArchivaDavResourceFactory method processRepositoryGroup.

private DavResource processRepositoryGroup(final DavServletRequest request, ArchivaDavResourceLocator archivaLocator, List<String> repositories, String activePrincipal, List<String> resourcesInAbsolutePath, RepositoryGroupConfiguration repoGroupConfig) throws DavException {
    DavResource resource = null;
    List<DavException> storedExceptions = new ArrayList<>();
    String pathInfo = StringUtils.removeEnd(request.getPathInfo(), "/");
    String rootPath = StringUtils.substringBeforeLast(pathInfo, "/");
    if (StringUtils.endsWith(rootPath, repoGroupConfig.getMergedIndexPath())) {
        // we are in the case of index file request
        String requestedFileName = StringUtils.substringAfterLast(pathInfo, "/");
        Path temporaryIndexDirectory = buildMergedIndexDirectory(repositories, activePrincipal, request, repoGroupConfig);
        Path resourceFile = temporaryIndexDirectory.resolve(requestedFileName);
        resource = new ArchivaDavResource(resourceFile.toAbsolutePath().toString(), requestedFileName, null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
    } else {
        for (String repositoryId : repositories) {
            ManagedRepositoryContent managedRepositoryContent;
            ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(repositoryId);
            if (managedRepository == null) {
                throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find repository with id " + repositoryId);
            }
            managedRepositoryContent = managedRepository.getContent();
            if (managedRepositoryContent == null) {
                log.error("Inconsistency detected. Repository content not found for '{}'", repositoryId);
                throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find repository content with id " + repositoryId);
            }
            try {
                DavResource updatedResource = processRepository(request, archivaLocator, activePrincipal, managedRepositoryContent, managedRepository);
                if (resource == null) {
                    resource = updatedResource;
                }
                String logicalResource = getLogicalResource(archivaLocator, null, false);
                if (logicalResource.endsWith("/")) {
                    logicalResource = logicalResource.substring(1);
                }
                resourcesInAbsolutePath.add(Paths.get(managedRepositoryContent.getRepoRoot(), logicalResource).toAbsolutePath().toString());
            } catch (DavException e) {
                storedExceptions.add(e);
            }
        }
    }
    if (resource == null) {
        if (!storedExceptions.isEmpty()) {
            // MRM-1232
            for (DavException e : storedExceptions) {
                if (401 == e.getErrorCode()) {
                    throw e;
                }
            }
            throw new DavException(HttpServletResponse.SC_NOT_FOUND);
        } else {
            throw new DavException(HttpServletResponse.SC_NOT_FOUND);
        }
    }
    return resource;
}
Also used : Path(java.nio.file.Path) DavResource(org.apache.jackrabbit.webdav.DavResource) ManagedRepository(org.apache.archiva.repository.ManagedRepository) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent)

Example 4 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project archiva by apache.

the class RepositoryServlet method service.

/**
 * Service the given request. This method has been overridden and copy/pasted to allow better exception handling and
 * to support different realms
 *
 * @param request
 * @param response
 * @throws ServletException
 * @throws java.io.IOException
 */
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    WebdavRequest webdavRequest = new WebdavRequestImpl(request, getLocatorFactory());
    // DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'.
    int methodCode = DavMethods.getMethodCode(request.getMethod());
    boolean noCache = DavMethods.isDeltaVMethod(webdavRequest) && !(DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode);
    WebdavResponse webdavResponse = new WebdavResponseImpl(response, noCache);
    DavResource resource = null;
    try {
        // make sure there is a authenticated user
        if (!getDavSessionProvider().attachSession(webdavRequest)) {
            return;
        }
        // check matching if=header for lock-token relevant operations
        resource = getResourceFactory().createResource(webdavRequest.getRequestLocator(), webdavRequest, webdavResponse);
        if (!isPreconditionValid(webdavRequest, resource)) {
            webdavResponse.sendError(DavServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
        if (!execute(webdavRequest, webdavResponse, methodCode, resource)) {
            super.service(request, response);
        }
    } catch (UnauthorizedDavException e) {
        webdavResponse.setHeader("WWW-Authenticate", getAuthenticateHeaderValue(e.getRepositoryName()));
        webdavResponse.sendError(e.getErrorCode(), e.getStatusPhrase());
    } catch (BrowserRedirectException e) {
        response.sendRedirect(e.getLocation());
    } catch (DavException e) {
        if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
            final String msg = "Should throw " + UnauthorizedDavException.class.getName();
            log.error(msg);
            webdavResponse.sendError(e.getErrorCode(), msg);
        } else if (e.getCause() != null) {
            webdavResponse.sendError(e.getErrorCode(), e.getCause().getMessage());
        } else {
            webdavResponse.sendError(e.getErrorCode(), e.getMessage());
        }
    } finally {
        getDavSessionProvider().releaseSession(webdavRequest);
    }
}
Also used : WebdavRequest(org.apache.jackrabbit.webdav.WebdavRequest) DavResource(org.apache.jackrabbit.webdav.DavResource) WebdavResponseImpl(org.apache.jackrabbit.webdav.WebdavResponseImpl) DavException(org.apache.jackrabbit.webdav.DavException) WebdavRequestImpl(org.apache.jackrabbit.webdav.WebdavRequestImpl) WebdavResponse(org.apache.jackrabbit.webdav.WebdavResponse)

Example 5 with DavResource

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

the class VersionHistoryResourceImpl method getMembers.

// --------------------------------------------------------< DavResource >---
/**
 * Show all versions of this history as members.
 *
 * @return
 * @see DavResource#getMembers()
 */
@Override
public DavResourceIterator getMembers() {
    ArrayList<DavResource> list = new ArrayList<DavResource>();
    if (exists() && isCollection()) {
        try {
            // only display versions as members of the vh. the jcr:versionLabels
            // node is an internal structure.
            VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
            while (it.hasNext()) {
                // omit item filter here. if the version history is visible
                // its versions should be visible as well.
                Version v = it.nextVersion();
                DavResourceLocator vhLocator = getLocator();
                DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
                DavResource childRes = getFactory().createResource(resourceLocator, getSession());
                list.add(childRes);
            }
        } catch (RepositoryException e) {
            // should not occur
            log.error("Unexpected error", e);
        } catch (DavException e) {
            // should not occur
            log.error("Unexpected error", e);
        }
    }
    return new DavResourceIteratorImpl(list);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)50 DavException (org.apache.jackrabbit.webdav.DavException)30 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)22 RepositoryException (javax.jcr.RepositoryException)16 ArrayList (java.util.ArrayList)9 Path (java.nio.file.Path)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)6 IOException (java.io.IOException)5 Version (javax.jcr.version.Version)4 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Item (javax.jcr.Item)3 NodeIterator (javax.jcr.NodeIterator)3 Repository (javax.jcr.Repository)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)3