jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jain.sudhan...@indiatimes.com
Subject Re: How to unlock jcr repository or to access repository through JNDI
Date Thu, 13 Mar 2008 12:27:27 GMT
Hi,

I have deployed jackrabbit-webapp-1.4.war"  jar in tomcat.it create repository at tomcat/bin
directory with the name of jackrabbit and create repository.xml file.

I have to scenrio to access this repository through my java client program.

Scenerio 1:-

Through RMI

String repoUrl = "//localhost:1099/jackrabbit-webapp-1.4/rmi"; //This set in the web.xml of
the repository

Repository repository = factory.getRepository(repoUrl);

It will return the repository Object .

work fine

Scenerio 2:-

when i access through JNDI and Register this repositoy it cause an error 

org.apache.jackrabbit.core.config.ConfigurationException: Configuration file could not be
read.: Connection timed out: connect: Connection timed out: connect



sample program:-


package com.hcl.test;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Hashtable;

import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.jackrabbit.core.jndi.RegistryHelper;

public class TestTomcatRepository {

private static Repository getRepository() throws Exception {

		
		
		
		
		String configFile = "C:/Tomcat/bin/jackrabbit/repository.xml";
		String repHomeDir = "C:/Tomcat/bin/jackrabbit";
			
		System.out.println("get Rep");
		Hashtable env = new Hashtable();
		env.put(Context.INITIAL_CONTEXT_FACTORY,
						"org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
		env.put(Context.PROVIDER_URL, "localhost");

		InitialContext ctx = new InitialContext(env);

		RegistryHelper.registerRepository(ctx, "jackrabbit.repository", configFile, repHomeDir,true);
		return (Repository) ctx.lookup("jackrabbit.repository");

	}
	
	


	
	public static void main(String[] args) {
	try {
		Repository repository = getRepository();
		System.out.println("Test1.main() repository "+repository);
		SimpleCredentials creds = new SimpleCredentials("admin",
				"admin".toCharArray());
		Session session = repository.login(creds);
		Node root = session.getRootNode();
		Node test1 = root.addNode("delhi");
	        Node test2 = test1.addNode("bombay");
	        test2.setProperty("message", "bangalore");
	        
	        session.exportDocumentView("/", new FileOutputStream(new File("C://xyz.xml")), false,
false);

		
	} catch (Exception e) {
		e.printStackTrace();
	}
	}
	
	
	

		
}

Can you please guide me where i am wrong !.......






Mime
View raw message