use of org.apache.jackrabbit.webdav.observation.Subscription in project jackrabbit by apache.
the class BaseDavRequest method getResponseBodyAsSubscriptionDiscovery.
/**
* Return response body as {@link SubscriptionDiscovery} object.
* @throws IllegalStateException when response does not represent a {@link SubscriptionDiscovery}
* @throws DavException for failures in obtaining/parsing the response body
*/
public SubscriptionDiscovery getResponseBodyAsSubscriptionDiscovery(HttpResponse response) throws DavException {
try {
Document doc = getResponseBodyAsDocument(response.getEntity());
if (doc == null) {
throw new DavException(response.getStatusLine().getStatusCode(), "no response body");
}
Element root = doc.getDocumentElement();
if (!DomUtil.matches(root, DavConstants.XML_PROP, DavConstants.NAMESPACE) && DomUtil.hasChildElement(root, ObservationConstants.SUBSCRIPTIONDISCOVERY.getName(), ObservationConstants.SUBSCRIPTIONDISCOVERY.getNamespace())) {
throw new DavException(response.getStatusLine().getStatusCode(), "Missing DAV:prop response body in SUBSCRIBE response.");
}
Element sde = DomUtil.getChildElement(root, ObservationConstants.SUBSCRIPTIONDISCOVERY.getName(), ObservationConstants.SUBSCRIPTIONDISCOVERY.getNamespace());
SubscriptionDiscovery sd = SubscriptionDiscovery.createFromXml(sde);
if (((Subscription[]) sd.getValue()).length > 0) {
return sd;
} else {
throw new DavException(response.getStatusLine().getStatusCode(), "Missing 'subscription' elements in SUBSCRIBE response body. At least a single subscription must be present if SUBSCRIBE was successful.");
}
} catch (IOException ex) {
throw new DavException(response.getStatusLine().getStatusCode(), ex);
}
}
use of org.apache.jackrabbit.webdav.observation.Subscription in project jackrabbit by apache.
the class SubscriptionManagerImpl method subscribe.
/**
* Create a new <code>Subscription</code> or update an existing <code>Subscription</code>
* and add it as eventlistener to the {@link javax.jcr.observation.ObservationManager}.
*
* @param info
* @param subscriptionId
* @param resource
* @return <code>Subscription</code> that has been added to the {@link javax.jcr.observation.ObservationManager}
* @throws DavException if the subscription fails
*/
public Subscription subscribe(SubscriptionInfo info, String subscriptionId, ObservationResource resource) throws DavException {
Subscription subscription;
if (subscriptionId == null) {
// new subscription
SubscriptionImpl newSubs = new SubscriptionImpl(info, resource);
registerSubscription(newSubs, resource);
// adjust references to this subscription
subscriptions.put(newSubs.getSubscriptionId(), newSubs);
resource.getSession().addReference(newSubs.getSubscriptionId());
subscription = newSubs;
} else {
// refresh/modify existing one
SubscriptionImpl existing = validate(subscriptionId, resource);
existing.setInfo(info);
registerSubscription(existing, resource);
subscription = new WrappedSubscription(existing);
}
return subscription;
}
use of org.apache.jackrabbit.webdav.observation.Subscription 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);
}
Aggregations