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

TODO


Indexing properties for faster searching

TODO


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.

TODO


Jackrabbit WebDAV API

Javadocs:

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

  • Init the Client
            hostConfig = new HostConfiguration();
    	hostConfig.setHost("www.somehost.com");	
    	HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    	HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    	int maxHostConnections = 20;
    	params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
    	connectionManager.setParams(params);	
    	client = new HttpClient(connectionManager);
    	Credentials creds = new UsernamePasswordCredentials("userId", "pw");
            client.getState().setCredentials(AuthScope.ANY, creds);
    	client.setHostConfiguration(hostConfig);
      
  • 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);
    	client.executeMethod(copy);
    	
    	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);
        client.executeMethod(pFind);
    
        MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();	 
    	 
        //Not quite nice, but for a example ok
        DavPropertySet props = multiStatus.getResponses()[0].getProperties(200);
    	  
        Collection<DefaultDavProperty> propertyColl=props.getContent(); 
        propertyColl.iterator();
        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);
        client.executeMethod(pFind);
    
        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 + "/"))) {
                System.out.println(currResponse.getHref());
            }
        }  
      
    * Setting a property of a resource
            DavPropertySet newProps=new DavPropertySet();	
    	DavPropertyNameSet removeProperties=new DavPropertyNameSet();
    	
            DavProperty testProp=new DefaultDavProperty("TheAnswer", "42", DavConstants.NAMESPACE);
    	newProps.add(testProp);
    	PropPatchMethod proPatch=new PropPatchMethod("http://www.somehost.com/duff/test4.txt", newProps, removeProperties);
    	
    	client.executeMethod(proPatch);
    	System.out.println(proPatch.getStatusCode() + " "+ proPatch.getStatusText());
      

General SSL access examples

TODO


History of Page:
Started: 2006-11-28