You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by kbar <wh...@gmail.com> on 2009/08/23 11:47:36 UTC

JNDI and Jackrabbit

Can someone tell me if the following is actually possible, and if it is then
perhaps someone could point me to some code that explains how to do it, if
possible in really simple baby steps. Assume i have next to no knowledge of
tomcat or developing in the java platform at all (the reason being I am new
to this but have over 15 years of development experience and can usually
pick up this stuff very quickly with a few sample files, but it seems
jackrabbit is ever evolving and there is simply not enough sample projects
for people like myself to look at).

I have jackrabbit setup and running. I can access it via
http://localhost:8080/jackrabbit,  so far so good.

Now I have another application written in java on the same machine that
jackrabbit is running on. I would like to talk to jackrabbit from that
machine. I believe this is possible using JNDI. Is this possible? 

There is sample code on the jackrabbit site that states the following...

========================
import javax.jcr.Repository;
import javax.naming.Context;
import javax.naming.InitialContext;

Context context = new InitialContext(...);
Repository repository = (Repository) context.lookup(...);
========================

What goes in the place of the "..."?

I tried the following...

 InitialContext ctx = new InitialContext() ;
 Context environment = (Context) ctx.lookup("java:comp/env");
 Repository repo = (Repository) environment.lookup("jackrabbit.repository");

And also this...

   InitialContext ctx = new InitialContext() ;
   Repository repo = (Repository) ctx.lookup("jackrabbit.repository");

No luck there either. The reason I am trying "jackrabbit.repository" is
because in my "Tomcat6/jackrabbit" folder is a file called
"bootstrap.properties" that says the "repository.home=jackrabbit.repository"
and also because in my "Tomcat/webapps/jackrabbit/WEB-INF/web.xml" is the
following...


 <init-param>
            <param-name>repository-name</param-name>
            <param-value>jackrabbit.repository</param-value>
            <description>Repository Name under which the repository is
registered via JNDI/RMI</description>
        </init-param>


Here is my bootstrap.properties file...

java.naming.factory.initial=org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory
repository.home=jackrabbitrepo
rmi.enabled=true
repository.config=jackrabbitrepo/repository.xml
repository.name=jackrabbit.repository
rmi.host=localhost
java.naming.provider.url=http\://www.apache.org/jackrabbit
jndi.enabled=true
rmi.port=0


I hope someone can help me. Its been 8 days of solid crunching around with
Jackrabbit and I know it can do what I want, its just a matter of trying to
keep digging at it with my blunt spoon (or at the moment its more like
trying to break into a bank vault full of nice yummy gold by smashing my
head against the safe door). I will persist though since I think it is great
technology and just needs a bit more documentation.

Cheers,
Kent.


     
-- 
View this message in context: http://www.nabble.com/JNDI-and-Jackrabbit-tp25101779p25101779.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: JNDI and Jackrabbit

Posted by kbar <wh...@gmail.com>.
OK so I have given up on trying to access it using JNDI like all these other
examples seem to do and I am now going to use RMI.

The following like just works... even though I think its doing more work
under the hood that is probably required?  I think from what I a have read
is that if I could have gotten the JDNI thing to work then it would send
less messages to jackrabbit than if I am using RMI. Is am correct?

            Repository repo = new
URLRemoteRepository("http://localhost:8080/jackrabbit/rmi");

Cheers,
Kent.
-- 
View this message in context: http://www.nabble.com/JNDI-and-Jackrabbit-tp25101779p25102476.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: JNDI and Jackrabbit

Posted by kbar <wh...@gmail.com>.
One last attempt... still does not work though, but this is what I tried.

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi" +
".provider.DummyInitialContextFactory");
env.put(Context.PROVIDER_URL, "localhost:8080/jackrabbit");
InitialContext ctx = new InitialContext(env);
//repo = (Repository) ctx.lookup("java:jcr/local");
Context envContext =(Context) ctx.lookup("java:comp/env");
repo = (Repository) envContext.lookup("jcr/repository");


This results in the following exception...

Repo Exception: javax.naming.InvalidNameException: java:comp/env has more
components than namespace can handle

Note I also tried java:jcr/local but I get the same exception for that also.





kbar wrote:
> 
> I have also tried the following but they also did not work...
> 
>      String configFile =
> "/Library/Tomcat/Home/jackrabbitrepo/repository.xml";
>             String repHomeDir = "/Library/Tomcat/Home/jackrabbitrepo";
>             Hashtable env = new Hashtable();
>             env.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.jackrabbit.core.jndi" +
> ".provider.DummyInitialContextFactory");
>             env.put(Context.PROVIDER_URL, "localhost"); //Also tried
> localhost:8080/jackrabbit
>             InitialContext ctx = new InitialContext(env);
>             repo = (Repository) ctx.lookup("jackrabbit.repository");
> 
> 
> 
> Here I also tried to register a new name to use but that doesn't work for
> me since I do not have permission to create a .lock file in the repHomeDir
> and I don't want to run NetBeans as root to allow this (and I am not even
> sure it will work anyway).
> 
> 
>      String configFile =
> "/Library/Tomcat/Home/jackrabbitrepo/repository.xml";
>             String repHomeDir = "/Library/Tomcat/Home/jackrabbitrepo";
>             Hashtable env = new Hashtable();
>             env.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.jackrabbit.core.jndi" +
> ".provider.DummyInitialContextFactory");
>             env.put(Context.PROVIDER_URL, "localhost"); //Also tried
> localhost:8080/jackrabbit
>             InitialContext ctx = new InitialContext(env);
>             RegistryHelper.registerRepository(ctx,
>                                                  "repo",
>                                                    configFile,
>                                                      repHomeDir,
>                                                             true);
>             repo = (Repository) ctx.lookup("repo");
> 
> 

-- 
View this message in context: http://www.nabble.com/JNDI-and-Jackrabbit-tp25101779p25102366.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: JNDI and Jackrabbit

Posted by kbar <wh...@gmail.com>.
I have also tried the following but they also did not work...

     String configFile =
"/Library/Tomcat/Home/jackrabbitrepo/repository.xml";
            String repHomeDir = "/Library/Tomcat/Home/jackrabbitrepo";
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.jackrabbit.core.jndi" + ".provider.DummyInitialContextFactory");
            env.put(Context.PROVIDER_URL, "localhost"); //Also tried
localhost:8080/jackrabbit
            InitialContext ctx = new InitialContext(env);
            repo = (Repository) ctx.lookup("jackrabbit.repository");



Here I also tried to register a new name to use but that doesn't work for me
since I do not have permission to create a .lock file in the repHomeDir and
I don't want to run NetBeans as root to allow this (and I am not even sure
it will work anyway).


     String configFile =
"/Library/Tomcat/Home/jackrabbitrepo/repository.xml";
            String repHomeDir = "/Library/Tomcat/Home/jackrabbitrepo";
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.jackrabbit.core.jndi" + ".provider.DummyInitialContextFactory");
            env.put(Context.PROVIDER_URL, "localhost"); //Also tried
localhost:8080/jackrabbit
            InitialContext ctx = new InitialContext(env);
            RegistryHelper.registerRepository(ctx,
                                                 "repo",
                                                   configFile,
                                                     repHomeDir,
                                                            true);
            repo = (Repository) ctx.lookup("repo");

-- 
View this message in context: http://www.nabble.com/JNDI-and-Jackrabbit-tp25101779p25102296.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: JNDI and Jackrabbit

Posted by kbar <wh...@gmail.com>.
I thought I should also make sure to say that my second app is a completely
separate application, NOT a webapp. Its a stand alone application that is
running on the server. 


kbar wrote:
> 
> 
> Now I have another application written in java on the same machine that
> jackrabbit is running on. I would like to talk to jackrabbit from that
> machine. I believe this is possible using JNDI. Is this possible? 
>      
> 

-- 
View this message in context: http://www.nabble.com/JNDI-and-Jackrabbit-tp25101779p25101812.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: JNDI and Jackrabbit

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Sun, Aug 23, 2009 at 11:47 AM, kbar<wh...@gmail.com> wrote:
> Now I have another application written in java on the same machine that
> jackrabbit is running on. I would like to talk to jackrabbit from that
> machine. I believe this is possible using JNDI. Is this possible?

Not the way you try to do it. Instead of trying to configure JNDI, use
the JCR-RMI layer directly.

The easiest way to do that is to add the jackrabbit-jcr-rmi jar to
your client application and use the URLRemoteRepository class, like
this:

    import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;

    Repository repository = new
URLRemoteRepository("http://localhost:8080/jackrabbit/rmi");

If you really like, you can also configure the RMI endpoint as a JNDI
resource, but IMHO that's only useful in complex container
environments.

BR,

Jukka Zitting