Skip to content
Ben Fortuna edited this page Mar 6, 2017 · 1 revision

Mstor now support persistent storage in a Java Content Repository (JCR).

Intra-JVM repository

Using the Apache Jackrabbit reference implementation, you can easily initialise a repository as follows:

  • Create a jndi.properties file in your classpath containing the following:
java.naming.factory.initial=org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory
java.naming.provider.url=localhost
  • Register the repository:
Context context = new InitialContext();
RegistryHelper.registerRepository(context, "my/repository", "repository.xml", "/some/path/to/repo", false);
  • Connect using mstor:
Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "mstor");
properties.setProperty("mstor.repository.name", "my/repository");

// this is the root node in your repository to use as the default folder..
properties.setProperty("mstor.repository.path", "mail");

// create the default folder node if it doesn't exist..
properties.setProperty("mstor.repository.create", "true");

Session session = Session.getInstance(defaultProps, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("username", "password");
    }
});

Store store = session.getStore();
store.connect();

// further store operations..
  • Explicitly shutdown the repository when finished:
RegistryHelper.unregisterRepository(context, "my/repository");

Inter-JVM repository (RMI)

Using Apache Jackrabbit you can also access repositories running in separate JVMs (Model 3). Connect to such a repository as follows:

Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "mstor");
properties.setProperty("mstor.repository.provider.url", "rmi://myrepo.example.com:1099");
properties.setProperty("mstor.repository.name", "my/repository");

// this is the root node in your repository to use as the default folder..
properties.setProperty("mstor.repository.path", "mail");

// create the default folder node if it doesn't exist..
properties.setProperty("mstor.repository.create", "true");

Session session = Session.getInstance(defaultProps, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("username", "password");
    }
});

Store store = session.getStore();
store.connect();

// further store operations..
Clone this wiki locally