ical4j / ical4j-connector

Connectivity with persistent store implementations
http://www.ical4j.org/connector/
Other
9 stars 18 forks source link

carddav filter for addressbook-query #13

Closed fredgi closed 7 years ago

fredgi commented 7 years ago

Hi,

I'm trying to use ical4j-connector to acccess a synology carddav server.

This does not work with the following error :

HTTP/1.1 400 Bad Request
DEBUG [httpclient.wire.content] << "<html><head><title>Bad Request</title></head><body><h1>Bad Request</h1><p>CARDDAV:filter required</p></body></html>"

Which is the response to the following request :

DEBUG [httpclient.wire.content] >> "<?xml version="1.0" encoding="UTF-8" standalone="no"?><C:addressbook-query xmlns:C="urn:ietf:params:xml:ns:carddav"><D:prop xmlns:D="DAV:"><D:getetag/><C:filter/><C:address-data/></D:prop></C:addressbook-query>"

I already tryed to add an empty filter (response is the same without this empty filter).

How can I add some filter ? Error is seen in CardDavCollection class

public VCard[] getComponents() throws ObjectStoreException I don't know how to add a Filter node to the DavPropertyNameSet.

For information, Synology PathResolver is following

public class SynologyPathResolver extends PathResolver {
    public String getPrincipalPath(String username) {
        return "/principals/users/" + username + "/";
    }

    public String getUserPath(String username) {
        return "/addressbooks/users/" + username + "/"; 
    }
}

I'm using ical4j 2.0.0 with ical4j-connector trunk

Thanks for any help.

Fred

fredgi commented 7 years ago

Finally made it work after updating the CardDavCollection class :

public VCard[] getComponents() throws ObjectStoreException {
        try {
            DavPropertyNameSet properties = new DavPropertyNameSet();
            properties.add(DavPropertyName.GETETAG);
            properties.add(CardDavPropertyName.ADDRESS_DATA);

Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            Element filter = DomUtil.createElement(document, CalDavConstants.PROPERTY_FILTER,
                    CalDavConstants.CARDDAV_NAMESPACE);
            ReportInfo info = new ReportInfo(ReportMethod.ADDRESSBOOK_QUERY, 1, properties);
info.setContentElement(filter);
            ReportMethod method = new ReportMethod(getPath(), info);
            getStore().getClient().execute(method);

            if (method.getStatusCode() == DavServletResponse.SC_MULTI_STATUS) {
                return method.getVCards();
            } else if (method.getStatusCode() == DavServletResponse.SC_NOT_FOUND) {
                return new VCard[0];
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DOMException e) {
            e.printStackTrace();
        } catch (DavException e) {
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } /* catch (ParserException e) {
            e.printStackTrace();
        } */
        return new VCard[0];
    }

Not found yet how to make a Query by fn, phone, nor any vcard property.

Regards, Fred