use of org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery 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.SubscriptionDiscovery 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);
}
Aggregations