Search in sources :

Example 1 with ObservationResource

use of org.apache.jackrabbit.webdav.observation.ObservationResource in project jackrabbit by apache.

the class DavResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the given locator and session.
     *
     * @param locator
     * @param session
     * @return DavResource representing either a repository item or the {@link RootCollection}.
     * @throws DavException if the given locator does neither refer to a repository item
     * nor does represent the {@link org.apache.jackrabbit.webdav.DavResourceLocator#isRootLocation()
     * root location}.
     */
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
    JcrDavSession.checkImplementation(session);
    JcrDavSession sessionImpl = (JcrDavSession) session;
    DavResource resource;
    if (locator.isRootLocation()) {
        resource = new RootCollection(locator, sessionImpl, this);
    } else if (locator.getResourcePath().equals(locator.getWorkspacePath())) {
        resource = new WorkspaceResourceImpl(locator, sessionImpl, this);
    } else {
        try {
            resource = createResourceForItem(locator, sessionImpl);
        } catch (RepositoryException e) {
            log.debug("Creating resource for non-existing repository item: " + locator.getRepositoryPath());
            // todo: is this correct?
            resource = new VersionControlledItemCollection(locator, sessionImpl, this, null);
        }
    }
    // todo: currently transactionId is set manually after creation > to be improved.
    resource.addLockManager(txMgr);
    if (resource instanceof ObservationResource) {
        ((ObservationResource) resource).init(subsMgr);
    }
    return resource;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource) RepositoryException(javax.jcr.RepositoryException)

Example 2 with ObservationResource

use of org.apache.jackrabbit.webdav.observation.ObservationResource in project jackrabbit by apache.

the class DavResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the specified locator and request
     * objects. Note, that in contrast to
     * {@link #createResource(DavResourceLocator, DavSession)} the locator may
     * point to a non-existing resource.
     * <p>
     * If the request contains a {@link org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getLabel()
     * Label header}, the resource is build from the indicated
     * {@link org.apache.jackrabbit.webdav.version.VersionResource version} instead.
     *
     * @param locator
     * @param request
     * @param response
     * @return
     * @see DavResourceFactory#createResource(org.apache.jackrabbit.webdav.DavResourceLocator, org.apache.jackrabbit.webdav.DavServletRequest, org.apache.jackrabbit.webdav.DavServletResponse)
     */
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
    JcrDavSession.checkImplementation(request.getDavSession());
    JcrDavSession session = (JcrDavSession) request.getDavSession();
    DavResource resource;
    String type = request.getParameter("type");
    if (locator.isRootLocation()) {
        // root
        resource = new RootCollection(locator, session, this);
    } else if ("journal".equals(type) && locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // feed/event journal resource
        try {
            EventJournal ej = session.getRepositorySession().getWorkspace().getObservationManager().getEventJournal();
            if (ej == null) {
                throw new DavException(HttpServletResponse.SC_NOT_IMPLEMENTED, "event journal not supported");
            }
            resource = new EventJournalResourceImpl(ej, locator, session, request, this);
        } catch (AccessDeniedException ex) {
            // EventJournal only allowed for admin?
            throw new DavException(HttpServletResponse.SC_UNAUTHORIZED, ex);
        } catch (RepositoryException ex) {
            throw new DavException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
    } else if (locator.getResourcePath().equals(locator.getWorkspacePath())) {
        // workspace resource
        resource = new WorkspaceResourceImpl(locator, session, this);
    } else {
        // resource corresponds to a repository item
        try {
            resource = createResourceForItem(locator, session);
            Item item = getItem(session, locator);
            boolean versionable = item.isNode() && ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);
            /* if the created resource is version-controlled and the request
                contains a Label header, the corresponding Version must be used
                instead.*/
            if (request instanceof DeltaVServletRequest && versionable) {
                String labelHeader = ((DeltaVServletRequest) request).getLabel();
                if (labelHeader != null && DavMethods.isMethodAffectedByLabel(request) && isVersionControlled(resource)) {
                    Version v = ((Node) item).getVersionHistory().getVersionByLabel(labelHeader);
                    DavResourceLocator vloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), v.getPath(), false);
                    resource = new VersionItemCollection(vloc, session, this, v);
                }
            }
        } catch (PathNotFoundException e) {
            /* item does not exist yet: create the default resources
                Note: MKCOL request forces a collection-resource even if there already
                exists a repository-property with the given path. the MKCOL will
                in that particular case fail with a 405 (method not allowed).*/
            if (DavMethods.getMethodCode(request.getMethod()) == DavMethods.DAV_MKCOL) {
                resource = new VersionControlledItemCollection(locator, session, this, null);
            } else {
                resource = new DefaultItemResource(locator, session, this, null);
            }
        } catch (RepositoryException e) {
            log.error("Failed to build resource from item '" + locator.getRepositoryPath() + "'");
            throw new JcrDavException(e);
        }
    }
    if (request instanceof TransactionDavServletRequest && resource instanceof TransactionResource) {
        ((TransactionResource) resource).init(txMgr, ((TransactionDavServletRequest) request).getTransactionId());
    }
    if (resource instanceof ObservationResource) {
        ((ObservationResource) resource).init(subsMgr);
    }
    return resource;
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) TransactionResource(org.apache.jackrabbit.webdav.transaction.TransactionResource) EventJournal(javax.jcr.observation.EventJournal) Item(javax.jcr.Item) Version(javax.jcr.version.Version) TransactionDavServletRequest(org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource) DeltaVServletRequest(org.apache.jackrabbit.webdav.version.DeltaVServletRequest) VersionItemCollection(org.apache.jackrabbit.webdav.jcr.version.VersionItemCollection) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 3 with ObservationResource

use of org.apache.jackrabbit.webdav.observation.ObservationResource in project jackrabbit by apache.

the class AbstractWebdavServlet method doPoll.

/**
     * The POLL method
     *
     * @param request
     * @param response
     * @param resource
     * @throws IOException
     * @throws DavException
     */
protected void doPoll(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!(resource instanceof ObservationResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    EventDiscovery ed = ((ObservationResource) resource).poll(request.getSubscriptionId(), request.getPollTimeout());
    response.sendPollResponse(ed);
}
Also used : EventDiscovery(org.apache.jackrabbit.webdav.observation.EventDiscovery) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource)

Example 4 with ObservationResource

use of org.apache.jackrabbit.webdav.observation.ObservationResource in project jackrabbit by apache.

the class AbstractWebdavServlet method doSubscribe.

/**
     * The SUBSCRIBE method
     *
     * @param request
     * @param response
     * @param resource
     * @throws IOException
     * @throws DavException
     */
protected void doSubscribe(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!(resource instanceof ObservationResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    SubscriptionInfo info = request.getSubscriptionInfo();
    if (info == null) {
        response.sendError(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;
    }
    Subscription subs = ((ObservationResource) resource).subscribe(info, request.getSubscriptionId());
    response.sendSubscriptionResponse(subs);
}
Also used : ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource) SubscriptionInfo(org.apache.jackrabbit.webdav.observation.SubscriptionInfo) Subscription(org.apache.jackrabbit.webdav.observation.Subscription)

Aggregations

ObservationResource (org.apache.jackrabbit.webdav.observation.ObservationResource)4 RepositoryException (javax.jcr.RepositoryException)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 Item (javax.jcr.Item)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 EventJournal (javax.jcr.observation.EventJournal)1 Version (javax.jcr.version.Version)1 DavException (org.apache.jackrabbit.webdav.DavException)1 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)1 VersionItemCollection (org.apache.jackrabbit.webdav.jcr.version.VersionItemCollection)1 EventDiscovery (org.apache.jackrabbit.webdav.observation.EventDiscovery)1 Subscription (org.apache.jackrabbit.webdav.observation.Subscription)1 SubscriptionInfo (org.apache.jackrabbit.webdav.observation.SubscriptionInfo)1 TransactionDavServletRequest (org.apache.jackrabbit.webdav.transaction.TransactionDavServletRequest)1 TransactionResource (org.apache.jackrabbit.webdav.transaction.TransactionResource)1 DeltaVServletRequest (org.apache.jackrabbit.webdav.version.DeltaVServletRequest)1