简体   繁体   中英

How to access remote jackrabbit repository?

I need to work with remote jackrabbit repository. I use following code to connect to the local repository:

Repository repository = new TransientRepository();
Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));

and this works for the local repository but what do I do incase of the remote jackrabbit?

Have you tried using this?

import javax.jcr.Repository;
import org.apache.jackrabbit.commons.JcrUtils;

Repository repository = JcrUtils.getRepository("http://$SERVER_ADDRESS:$PORT/$CONTEXT");

That should work if the remote repository is exposing RMI services. Please note that RMI access is in general considered to be quite slow.

You'll find more info about accessing remote repositories here .

Another option is WebDav, which is supposed to be somewhat faster than RMI, though not as fast as the native interface:

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.commons.JcrUtils;

public class main {

/**
 * @param args
 */
public static void main(String[] args) throws Throwable{
    String url = "http://localhost:8080/server";
    System.out.println("Connecting to " + url);
    Repository repository = JcrUtils.getRepository(url);
    SimpleCredentials creds = new SimpleCredentials("admin",
            "admin".toCharArray());
    Session jcrSession = repository.login(creds, "default");
    System.out.println("Login successful, workspace: " + jcrSession.getWorkspace());

We're using the REST interface provided by Sling to remotely access our repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM