Fork me on GitHub

How to Use Remote Repository

Add Dependencies in Web Application

Add the following dependencies into your Web Application (e.g., '/site') where you want a remote repository.


    <!-- SNIP -->

    <!--
      Infer jackrabbit.version from hippo.jackrabbit.version in your project.
      For example, you can take "2.16.1" for jackrabbit.version, from "2.16.1-h2" of hippo.jackrabbit.version property here.
    -->
    <dependency>
      <groupId>org.apache.jackrabbit</groupId>
      <artifactId>jackrabbit-jcr2dav</artifactId>
      <version>${jackrabbit.version}</version>
    </dependency>

    <dependency>
      <groupId>org.onehippo.forge.hipporepojcrdav</groupId>
      <artifactId>hipporepojcrdav-connector</artifactId>
      <version>${forge.hipporepojcrdav.version}</version>
    </dependency>

    <!-- SNIP -->

          

Configuring JNDI Resource of HippoRepository

In order to use a remote Hippo Repository in your web application, you have to configure JNDI Resource. As an example, in Tomcat, you can add the following JNDI Resource in the context configuration like the following example:

<Context crossContext="true">

  <!-- SNIP -->

  <Resource name="jcr/davexRepository" auth="Container"
            type="org.onehippo.forge.repository.connector.remoting.davex.HippoJcrRepository"
            factory="org.onehippo.forge.repository.connector.remoting.davex.DavExHippoRepositoryBasedHippoJcrRepositoryFactory"
            repositoryAddress="http://localhost:8080/cms/server" />

  <!-- SNIP -->

</Context>
          

Add JNDI Resource Reference in web.xml

In order to use a remote Hippo Repository in your web application, you also have to add JNDI Resource Reference element in web.xml like the following example:


  <resource-ref>
    <description>JCR Repository</description>
    <res-ref-name>jcr/davexRepository</res-ref-name>
    <res-type>org.onehippo.forge.repository.connector.remoting.davex.HippoJcrRepository</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

          

Getting/Using JCR Repository directly from JNDI Resource

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Repository repository = (Repository) envCtx.lookup("jcr/davexRepository");
          

Getting/Using Hippo Repository directly through HippoRepositoryFactory with 'java:...' repository address

HippoRepository hippoRepository = HippoRepositoryFactory.getHippoRepository("java:comp/env/jcr/davexRepository");
          

Creating/Using Hippo Repository directly through DavExHippoRepository#create(..)

HippoRepository hippoRepository = org.onehippo.forge.repository.connector.remoting.davex.DavExHippoRepository.create("http://localhost:8080/cms/server");