Search in sources :

Example 6 with DavException

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!");
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Example 7 with DavException

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);
    }
}
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 8 with DavException

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;
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) DavPropertyIterator(org.apache.jackrabbit.webdav.property.DavPropertyIterator)

Example 9 with DavException

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);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException)

Example 10 with DavException

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();
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) TxActiveLock(org.apache.jackrabbit.webdav.transaction.TxActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException)

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