/** * Create a new <code>Subscription</code> with the given {@link SubscriptionInfo} * and {@link org.apache.jackrabbit.webdav.observation.ObservationResource resource}. * * @param info * @param resource * @throws DavException if resource is not based on a JCR repository or * the repository does not support observation. */ public SubscriptionImpl(SubscriptionInfo info, ObservationResource resource) throws DavException { setInfo(info); locator = resource.getLocator(); session = JcrDavSession.getRepositorySession(resource.getSession()); try { obsMgr = session.getWorkspace().getObservationManager(); } catch (RepositoryException e) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e); } }
/** * Returns true if this <code>Subscription</code> matches the given * resource. * * @param resource * @return true if this <code>Subscription</code> matches the given * resource. */ boolean isSubscribedToResource(ObservationResource resource) { return locator.getResourcePath().equals(resource.getResourcePath()); }
/** * @param resource * @return JCR session */ private static Session getRepositorySession(ObservationResource resource) throws DavException { return JcrDavSession.getRepositorySession(resource.getSession()); }
/** * The UNSUBSCRIBE method * * @param request * @param response * @param resource * @throws IOException * @throws DavException */ protected void doUnsubscribe(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { if (!(resource instanceof ObservationResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } ((ObservationResource) resource).unsubscribe(request.getSubscriptionId()); response.setStatus(DavServletResponse.SC_NO_CONTENT); }
/** * 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); }
/** * 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); }
((ObservationResource)resource).init(subsMgr);
/** * Retrieve the {@link org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery} * object for the given resource. Note, that the discovery object will be empty * if there are no subscriptions present.<br> * Note that all subscriptions present on the given resource are returned. * However, the subscription id will not be visible in order to avoid abuse * by clients not having registered the subscription originally. * * @param resource */ public SubscriptionDiscovery getSubscriptionDiscovery(ObservationResource resource) { Subscription[] subsForResource = subscriptions.getByPath(resource.getLocator()); return new SubscriptionDiscovery(subsForResource); }
/** * Remove the event listener defined by the specified subscription from * the repository's observation manager and clean up the references present * on the <code>DavSession</code>. * * @param subscription * @param resource * @throws DavException */ private void unregisterSubscription(SubscriptionImpl subscription, ObservationResource resource) throws DavException { try { Session session = getRepositorySession(resource); session.getWorkspace().getObservationManager().removeEventListener(subscription); String sId = subscription.getSubscriptionId(); // clean up any references subscriptions.remove(sId); resource.getSession().removeReference(sId); } catch (RepositoryException e) { log.error("Unable to remove eventlistener: "+e.getMessage()); throw new JcrDavException(e); } }
/** * The UNSUBSCRIBE method * * @param request * @param response * @param resource * @throws IOException * @throws DavException */ protected void doUnsubscribe(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException { if (!(resource instanceof ObservationResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } ((ObservationResource) resource).unsubscribe(request.getSubscriptionId()); response.setStatus(DavServletResponse.SC_NO_CONTENT); }
/** * 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); }
/** * 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); }
((ObservationResource)resource).init(subsMgr);
resource.getSession().addReference(newSubs.getSubscriptionId()); subscription = newSubs; } else {