Search in sources :

Example 1 with SubscriptionDiscovery

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);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) SubscriptionDiscovery(org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery) IOException(java.io.IOException) Document(org.w3c.dom.Document) Subscription(org.apache.jackrabbit.webdav.observation.Subscription)

Example 2 with SubscriptionDiscovery

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);
}
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

SubscriptionDiscovery (org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery)2 IOException (java.io.IOException)1 DavException (org.apache.jackrabbit.webdav.DavException)1 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)1 Header (org.apache.jackrabbit.webdav.header.Header)1 Subscription (org.apache.jackrabbit.webdav.observation.Subscription)1 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1