Apache Jackrabbit : HowtoSpi2Dav

Context

The image below is a good picture of where spi2dav fits in. It was taken from the jackrabbit-spi link below.

http://jackrabbit.apache.org/jackrabbit-spi.data/jackrabbit-spi-overview.gif

I could not find much documentation on getting it setup.
Here is what I've found so far:

Warning: this is only partially working for me, so there might be errors in the documentation.

Get jcr-server running

Instructions

To use spi2dav you need to have the "jcr server component" running.

  • Add the jcr-1.0.jar to your servlet containers global library folder. For example: cp ~/.m2/repository/javax/jcr/jcr/1.0/jcr-1.0.jar lib/ext/
  • Download the jcr-server war
  • create a folder in your servlet container's (tomcat, jetty, ...) webapps folder. I used jackrabbit.
  • uncompress the war into that folder
  • Based on the README.txt referenced above, the following configuration needs to be changed in the web.xml for the webapp:
    <init-param>
      <param-name>missing-auth-mapping</param-name>
      <param-value></param-value>
    </init-param>

Automated Script

This is a bash script for installing it into jetty. If you want to use it for tomcat you should change the lib/ext to common/endorsed
Here is what it does:

  • download the jcr-1.0.jar from ibiblio maven repo into the lib/ext folder
  • download the latest jackrabbit-webapp war
  • unzip this war into a jackrabbit-1.5 inside of webapps
  • run a xslt file over the web.xml file of the jackrabbit-webapp to set the missing-auth-mapping init-param
# start in the toplevel jetty folder
curl http://mirrors.ibiblio.org/pub/mirrors/maven2/javax/jcr/jcr/1.0/jcr-1.0.jar > lib/ext/jcr-1.0.jar
curl -O  http://people.apache.org/maven-snapshot-repository/org/apache/jackrabbit/jackrabbit-webapp/1.5-SNAPSHOT/jackrabbit-webapp-1.5-SNAPSHOT.war
mkdir webapps/jackrabbit-1.5
cd webapps/jackrabbit-1.5
unzip ../../jackrabbit-webapp-1.5-SNAPSHOT.war
curl http://wiki.apache.org/jackrabbit-data/attachments/HowtoSpi2Dav/attachments/dav-fixer.xslt | xsltproc - WEB-INF/web.xml > fixed-web.xml
mv fixed-web.xml WEB-INF/web.xml

Access the remote server from a client

get the jars needed

The jars do not seem to be available for download in binary form, so they must be built:

add the dependencies to your maven pom.xml

    <dependency>
      <groupId>javax.jcr</groupId>
      <artifactId>jcr</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.jackrabbit</groupId>
    	<artifactId>jackrabbit-core</artifactId>
    	<version>1.5-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.3.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-spi-spi2dav</artifactId>
      <version>1.5-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-jcr2spi</artifactId>
      <version>1.5-SNAPSHOT</version>
    </dependency>    

write the code to access the repository

This code was figured out based on

 org.apache.jackrabbit.jcr2spi.JCR2SPIRepositoryStub 

located in

 svn.apache.org/repos/asf/jackrabbit/sandbox/spi/client 
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.jcr2spi.RepositoryImpl;
import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
import org.apache.jackrabbit.spi.IdFactory;
import org.apache.jackrabbit.spi.NameFactory;
import org.apache.jackrabbit.spi.PathFactory;
import org.apache.jackrabbit.spi.QValueFactory;
import org.apache.jackrabbit.spi.RepositoryService;
import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
import org.apache.jackrabbit.spi2dav.RepositoryServiceImpl;

...

  String url = "http://localhost:8080/jackrabbit/server";

  final IdFactory idFactory = IdFactoryImpl.getInstance();
  final NameFactory nFactory = NameFactoryImpl.getInstance();
  final PathFactory pFactory = PathFactoryImpl.getInstance();
  final QValueFactory vFactory = QValueFactoryImpl.getInstance();
  final RepositoryServiceImpl webdavRepoService = 
     new RepositoryServiceImpl(url, idFactory, nFactory, pFactory, vFactory);

  RepositoryConfig config = new RepositoryConfig() {
    public RepositoryService getRepositoryService() {
      return webdavRepoService;
    }

    public String getDefaultWorkspaceName() {
      return "default";
    }

    public CacheBehaviour getCacheBehaviour() {
      return CacheBehaviour.INVALIDATE;
    }
  };

  Repository repository = RepositoryImpl.create(config);
  Session session = repository.login(new SimpleCredentials("user", "password".toCharArray()));

<<AttachInfo>>