Search in sources :

Example 1 with CodedUrlHeader

use of org.apache.jackrabbit.webdav.header.CodedUrlHeader in project jackrabbit by apache.

the class AbstractWebdavServlet method doLock.

/**
 * The LOCK method
 *
 * @param request
 * @param response
 * @param resource
 * @throws IOException
 * @throws DavException
 */
protected void doLock(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    LockInfo lockInfo = request.getLockInfo();
    if (lockInfo.isRefreshLock()) {
        // refresh any matching existing locks
        ActiveLock[] activeLocks = resource.getLocks();
        List<ActiveLock> lList = new ArrayList<ActiveLock>();
        for (ActiveLock activeLock : activeLocks) {
            // adjust lockinfo with type/scope retrieved from the lock.
            lockInfo.setType(activeLock.getType());
            lockInfo.setScope(activeLock.getScope());
            DavProperty<?> etagProp = resource.getProperty(DavPropertyName.GETETAG);
            String etag = etagProp != null ? String.valueOf(etagProp.getValue()) : "";
            if (request.matchesIfHeader(resource.getHref(), activeLock.getToken(), etag)) {
                lList.add(resource.refreshLock(lockInfo, activeLock.getToken()));
            }
        }
        if (lList.isEmpty()) {
            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
        }
        ActiveLock[] refreshedLocks = lList.toArray(new ActiveLock[lList.size()]);
        response.sendRefreshLockResponse(refreshedLocks);
    } else {
        int status = HttpServletResponse.SC_OK;
        if (!resource.exists()) {
            // lock-empty requires status code 201 (Created)
            status = HttpServletResponse.SC_CREATED;
        }
        // create a new lock
        ActiveLock lock = resource.lock(lockInfo);
        CodedUrlHeader header = new CodedUrlHeader(DavConstants.HEADER_LOCK_TOKEN, lock.getToken());
        response.setHeader(header.getHeaderName(), header.getHeaderValue());
        DavPropertySet propSet = new DavPropertySet();
        propSet.add(new LockDiscovery(lock));
        response.sendXmlResponse(propSet, status);
    }
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery)

Example 2 with CodedUrlHeader

use of org.apache.jackrabbit.webdav.header.CodedUrlHeader 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)

Example 3 with CodedUrlHeader

use of org.apache.jackrabbit.webdav.header.CodedUrlHeader in project jackrabbit by apache.

the class RepositoryServiceImpl method initMethod.

private static void initMethod(HttpUriRequest request, BatchImpl batchImpl, boolean addIfHeader) throws RepositoryException {
    initMethod(request, batchImpl.sessionInfo, addIfHeader);
    // add batchId as separate header, TODO: could probably re-use session id Link relation
    CodedUrlHeader ch = new CodedUrlHeader(TransactionConstants.HEADER_TRANSACTIONID, batchImpl.batchId);
    request.setHeader(ch.getHeaderName(), ch.getHeaderValue());
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader)

Example 4 with CodedUrlHeader

use of org.apache.jackrabbit.webdav.header.CodedUrlHeader in project jackrabbit by apache.

the class WebdavResponseImpl method sendSubscriptionResponse.

// ----------------------------< ObservationDavServletResponse Interface >---
/**
 * @param subscription
 * @throws IOException
 * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletResponse#sendSubscriptionResponse(org.apache.jackrabbit.webdav.observation.Subscription)
 */
public void sendSubscriptionResponse(Subscription subscription) throws IOException {
    String id = subscription.getSubscriptionId();
    if (id != null) {
        Header h = new CodedUrlHeader(ObservationConstants.HEADER_SUBSCRIPTIONID, id);
        httpResponse.setHeader(h.getHeaderName(), h.getHeaderValue());
    }
    DavPropertySet propSet = new DavPropertySet();
    propSet.add(new SubscriptionDiscovery(subscription));
    sendXmlResponse(propSet, SC_OK);
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) Header(org.apache.jackrabbit.webdav.header.Header) SubscriptionDiscovery(org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery)

Aggregations

CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)4 DavException (org.apache.jackrabbit.webdav.DavException)2 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 HttpResponse (org.apache.http.HttpResponse)1 Subscription (org.apache.jackrabbit.spi.Subscription)1 HttpSubscribe (org.apache.jackrabbit.webdav.client.methods.HttpSubscribe)1 Header (org.apache.jackrabbit.webdav.header.Header)1 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1 SubscriptionDiscovery (org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery)1