use of org.apache.jackrabbit.webdav.DavException in project archiva by apache.
the class ArchivaDavResourceFactoryTest method testRequestArtifactMetadataThreePartsRepoHasDefaultLayout.
// MRM-1239
@Test
public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout() throws Exception {
// should fetch metadata
DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml", INTERNAL_REPO, new ArchivaDavLocatorFactory());
ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
// use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
RepositoryRequest repoRequest = new RepositoryRequest();
resourceFactory.setRepositoryRequest(repoRequest);
try {
archivaConfigurationControl.reset();
expect(archivaConfiguration.getConfiguration()).andReturn(config).times(1);
expect(request.getMethod()).andReturn("GET").times(4);
expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
expect(request.getContextPath()).andReturn("").times(1);
expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
expect(request.getRequestURI()).andReturn("http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml");
response.setHeader("Pragma", "no-cache");
expectLastCall();
response.setHeader("Cache-Control", "no-cache");
expectLastCall();
response.setDateHeader(eq("Last-Modified"), anyLong());
expectLastCall();
archivaConfigurationControl.replay();
repoContentFactoryControl.replay();
requestControl.replay();
responseControl.replay();
resourceFactory.createResource(locator, request, response);
archivaConfigurationControl.verify();
repoContentFactoryControl.verify();
requestControl.verify();
responseControl.verify();
} catch (DavException e) {
fail("A DavException should not have been thrown!");
}
}
use of org.apache.jackrabbit.webdav.DavException 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.DavException in project lobcder by skoulouzis.
the class Utils method resourceExists.
boolean resourceExists(String resource) throws IOException, DavException {
try {
MultiStatus multiStatus = this.getProperty(resource, DavPropertyName.DISPLAYNAME, false);
MultiStatusResponse[] responses = multiStatus.getResponses();
String value = null;
// for (MultiStatusResponse r : responses) {
DavPropertySet allProp = getProperties(responses[0]);
DavPropertyIterator iter = allProp.iterator();
while (iter.hasNext()) {
DavProperty<?> p = iter.nextProperty();
assertNotNull(p.getValue());
value = (String) p.getValue();
System.err.println(p.getName() + ":" + p.getValue());
break;
}
if (value != null) {
return true;
} else {
return false;
}
} catch (DavException ex) {
if (ex.getMessage().contains("Not Found")) {
return false;
} else {
throw ex;
}
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class TxLockManagerImpl method releaseLock.
/**
* Release the lock identified by the given lock token.
*
* @param lockInfo
* @param lockToken
* @param resource
* @throws DavException
*/
public synchronized void releaseLock(TransactionInfo lockInfo, String lockToken, TransactionResource resource) throws DavException {
if (resource == null) {
throw new IllegalArgumentException("Resource must not be null.");
}
TransactionMap responsibleMap = getMap(resource);
Transaction tx = responsibleMap.get(lockToken);
if (tx == null) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No transaction lock found for resource '" + resource.getResourcePath() + "'");
} else if (tx.getLock().isExpired()) {
removeExpired(tx, responsibleMap, resource);
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction lock for resource '" + resource.getResourcePath() + "' was already expired.");
} else {
if (lockInfo.isCommit()) {
TransactionListener[] txListeners;
synchronized (listeners) {
txListeners = listeners.values().toArray(new TransactionListener[listeners.values().size()]);
}
for (TransactionListener txListener : txListeners) {
txListener.beforeCommit(resource, lockToken);
}
DavException ex = null;
try {
tx.commit(resource);
} catch (DavException e) {
ex = e;
}
for (TransactionListener txListener : txListeners) {
txListener.afterCommit(resource, lockToken, ex == null);
}
if (ex != null) {
throw ex;
}
} else {
tx.rollback(resource);
}
removeReferences(tx, responsibleMap, resource);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class TxLockManagerImpl method createLock.
/**
* Create a new lock.
*
* @param lockInfo
* @param resource
* @return the lock
* @throws DavException if the request lock has the wrong lock type or if
* the lock could not be obtained for any reason.
*/
private synchronized ActiveLock createLock(LockInfo lockInfo, TransactionResource resource) throws DavException {
if (!lockInfo.isDeep() || !TransactionConstants.TRANSACTION.equals(lockInfo.getType())) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
ActiveLock existing = getLock(lockInfo.getType(), lockInfo.getScope(), resource);
if (existing != null) {
throw new DavException(DavServletResponse.SC_LOCKED);
}
// TODO: check for locks on member resources is required as well for lock is always deep!
Transaction tx = createTransaction(resource.getLocator(), lockInfo);
tx.start(resource);
// keep references to this lock
addReferences(tx, getMap(resource), resource);
return tx.getLock();
}
Aggregations