java 如何访问远程jackrabbit存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5857212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access remote Hymanrabbit repository?
提问by Abhishek Dhote
I need to work with remote Hymanrabbit repository. I use following code to connect to the local repository:
我需要使用远程 Hymanrabbit 存储库。我使用以下代码连接到本地存储库:
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 Hymanrabbit?
这适用于本地存储库,但是如果遇到远程长耳兔,我该怎么办?
回答by abahgat
Have you tried using this?
你试过用这个吗?
import javax.jcr.Repository;
import org.apache.Hymanrabbit.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.
如果远程存储库公开 RMI 服务,那应该可行。请注意,RMI 访问通常被认为很慢。
You'll find more info about accessing remote repositories here.
您可以在此处找到有关访问远程存储库的更多信息。
回答by Dan
Another option is WebDav, which is supposed to be somewhat faster than RMI, though not as fast as the native interface:
另一种选择是 WebDav,它应该比 RMI 快一些,但不如本机界面快:
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.Hymanrabbit.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());