Apache Jackrabbit : WebDAV

The intent of this document is to show how to use Jackrabbit through the WebDAV interface. This document has primarly been designed to help migrate Jakarta Slide users who mainly used WebDAV for interfacing and would like to migrate their repositories to Jackrabbit – but should be useful for migration from any WebDAV-enabled repository to Jackrabbit.

Please note that Jackrabbit's WebDAV is mainly targeted at exposing a JCR repository over WebDAV. If you want a general purpose WebDAV server framework in Java (such as the old Apache Slide), there are other choices, which might be better: Sardine or Milton.

Configuration oriented setup

  • Setting up jackrabbit for properties.
  • Indexing properties for faster searching.

Process oriented examples

  • Injecting a binary file.
  • Adding properties about the file.
  • Searching the properties for your file.

WebDAV programming

  • Jackrabbit WebDAV API

Migrating existing data

  • TODO

Security Considerations

  • General SSL access examples - with keystore, ignoring keystores.

Setting up jackrabbit for properties


Indexing properties for faster searching


Injecting a binary file

If you have existing code or implementation for injecting WebDAV binary file, that will work without change on Jackrabbit. The only difference is the webdav resource you should use would be something like:

Adding properties about the file

If you have existing code or implementation for applying properties to your binary file (PROPPATCH), this will work with work with the default setup provided with Jackrabbit. To restrict the properties or specifically modify the overall import/export behavior of properties, please refer to the configuration options (see resource-config init-param within the web.xml and the related config.xml).

Unlike Jakarta Slide that allowed arbitrary properties, Jackrabbit requires specified nodeType and nodeProperties. See NodeTypeRegistry for some pre-existing nodeType definitions and http://jackrabbit.apache.org/doc/nodetype/index.html on defining your own.

Searching the properties for your file

The default DASL <basicsearch> mechanisms will not work with Jackrabbit. Instead, XPATH-style searches and SQL searches within the <searchrequest> tag must be used.

In addition, the webdav libraries from the Jakarta Slide project for the SearchMethod class do not seem to work correctly with Jackrabbit (not sure if the libs or Jackrabbit), instead you need to use org.apache.jackrabbit.webdav.client.methods.SearchMethod where you need/should use javax.jcr.query.Query.SQL and javax.jcr.query.Query.XPATH constants as parameters to define the query type.

Please update with examples.


Jackrabbit WebDAV API


Using the WebDAV-Client API linked with standard WebDAV-Server

  • Init the Client
            hostConfig = new HostConfiguration();
    	HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    	HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    	int maxHostConnections = 20;
    	params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    	client = new HttpClient(connectionManager);
    	Credentials creds = new UsernamePasswordCredentials("userId", "pw");
            client.getState().setCredentials(AuthScope.ANY, creds);
  • Copy a File
            //source, dest, overwrite
            DavMethod copy=new CopyMethod("http://www.somehost.com/duff/test3.txt", "http://www.somehost.com/duff/test4.txt", true);
    	System.out.println(copy.getStatusCode() + " "+ copy.getStatusText());

  • Reading all properties of a resource
        DavMethod pFind = new PropFindMethod("http://www.somehost.com/duff/test3.txt", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_INFINITY);
        MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();	 
        //Not quite nice, but for a example ok
        DavPropertySet props = multiStatus.getResponses()[0].getProperties(200);
        Collection<DefaultDavProperty> propertyColl=props.getContent(); 
        for(Iterator<DefaultDavProperty> iterator = propertyColl.iterator(); iterator.hasNext();){
    	DefaultDavProperty tmpProp=iterator.next();
    	System.out.println(tmpProp.getName() +"  "+ tmpProp.getValue());

  • Getting a list of subresources of a resource
        String host = "http://www.somehost.com";
        String resourcePath = "/duff";
        DavMethod pFind = new PropFindMethod(host + resourcePath, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
        MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();
        MultiStatusResponse[] responses = multiStatus.getResponses();
        MultiStatusResponse currResponse;
        ArrayList files = new ArrayList();
        System.out.println("Folders and files in " + resourcePath + ":");
        for (int i=0; i<responses.length; i++) {
            currResponse = responses[i];
            if (!(currResponse.getHref().equals(path) || currResponse.getHref().equals(path + "/"))) {
    * Setting a property of a resource
            DavPropertySet newProps=new DavPropertySet();	
    	DavPropertyNameSet removeProperties=new DavPropertyNameSet();
            DavProperty testProp=new DefaultDavProperty("TheAnswer", "42", DavConstants.NAMESPACE);
    	PropPatchMethod proPatch=new PropPatchMethod("http://www.somehost.com/duff/test4.txt", newProps, removeProperties);
    	System.out.println(proPatch.getStatusCode() + " "+ proPatch.getStatusText());

General SSL access examples


History of Page:
Started: 2006-11-28