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);
}
}
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());
}
}
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;
}
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);
}
}
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);
}
Aggregations