Thanks Felix.
That mostly worked- I can now look up the repo in Sling, but it is found at java:repository instead of java:comp/env/repository. For now I just hacked my custom naming context impl to look in java: in case java:comp/env fails.
Thanks
Tyson

On Feb 10, 2009, at 12:05 AM, "Felix Meschberger" <[email protected]> wrote:

Hi Tyson,

Tyson Norris schrieb:
First, thanks for sling!

You are welcome - Glad you like it ;-)

Next, I have a question about using sling - I'd like to access my JCR
repository via JNDI within Tomcat.

I have to admit, that both Tomcat and JNDI are almost a book with seven
seals to me ... But I give it a try ...


I believe that I have tomcat properly configured, because I can deploy jackrabbit org.apache.jackrabbit.j2ee.RepositoryAccessServlet within a
webapp that does NOT deploy an embedded repository, and I can access
the repository without a problem.



However, when I deploy a similar config with sling, I believe I am
running into classloader problems, because the JNDI context does NOT
have anything bound to it.

It looks like you might really have a class loading issue. Since the
InitialContext might not be correclty set up. What you might try is to
set the Thread context ClassLoader before instantiating the
InitialContext in your SimpleInitialContextFactory class, someting like:

   ClassLoader old = Thread.currentThread.getContextClassLoader();
   try {
       Thread.currentThread.setContextClassLoader(
              getClass().getClassLoader());

        Context initCtx = new InitialContext();
        Context ctx = (Context) initCtx.lookup("java:comp/env");
        ....
   finally {
       Thread.currentThread.setContextClassLoader(old);
   }

Regards
Felix




Exception stack is below; basically I get
javax.naming.NameNotFoundException: Name java:comp is not bound in this Context when my (custom) jndi context impl lookup method is executing:

Context initCtx = new InitialContext();

Context ctx = (Context) initCtx.lookup("java:comp/env");

(note that this works fine with jackrabbit webapp).



I am deploying the prepacked sling webapp from
http://incubator.apache.org/sling/site/downloads.cgi
<http://incubator.apache.org/sling/site/downloads.cgi>



I downloaded the src from same site, and built the
org.apache.sling.jcr.jackrabbit.client-2.0.2-incubator.jar, and added to
sling\WEB-INF\resources\bundles.



In WEB-INF/sling.properties I added:

sling.repository.url=jndi:// magnoliaAuthor22:java.naming.factory.initial =org. myo.jndi.simple.SimpleInitialContextFactory,java.naming.provider.ur
l=localhost



I also added to both sling.properties AND jcr-client.properties:



sling. bootdelegation.class.org.myo.jndi.simple.SimpleInitialContextFacto
ry = \

org.myo.jndi.simple,javax.naming,org.apache.naming



sling.bootdelegation.class.javax.naming.InitialContext = \

javax.naming



sling.bootdelegation.class.org.apache.naming.NamingContext = \

org.apache.naming



sling.bootdelegation.simple = org.myo.jndi.simple



I will try a few more things like, newer codebase of sling (I know some
minor changes have been made to processing of sling.repository.url
property) as well as deployment in jboss.



Any ideas how to make this work in tomcat?



Thanks for any help.

Tyson







09.02.2009 15:00:54.157 *INFO* [Repository Pinger]
org.apache.sling.jcr.base.util.RepositoryAccessor Unable to acquire R

epository 'magnoliaAuthor22' via JNDI,
context={java.naming.provider.url=localhost,
java.naming.factory.initial=org.myo.

jndi.simple.SimpleInitialContextFactory}
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context



       at
org.apache.naming.NamingContext.lookup(NamingContext.java:770)

       at
org.apache.naming.NamingContext.lookup(NamingContext.java:153)

       at javax.naming.InitialContext.lookup(InitialContext.java:392)

       at
org.myo.jndi.simple.SimpleContext.lookup(SimpleContext.java:270)

       at
org.myo.jndi.simple.SimpleContext.lookup(SimpleContext.java:287)

       at javax.naming.InitialContext.lookup(InitialContext.java:392)

       at
org. apache.sling.jcr.base.util.RepositoryAccessor.getRepository(Reposito
ryAccessor.java:76)

       at
org. apache.sling.jcr.base.util.RepositoryAccessor.getRepositoryFromURL(R
epositoryAccessor.java:171)

       at
org. apache.sling.jcr.base.AbstractSlingRepository.acquireRepository(Abst
ractSlingRepository.java:408)

       at
org. apache.sling.jcr.jackrabbit.client.SlingClientRepository.acquireRepo
sitory(SlingClientRepository.java:57)



       at
org. apache.sling.jcr.base.AbstractSlingRepository.startRepository(Abstra
ctSlingRepository.java:795)

       at
org. apache.sling.jcr.base.AbstractSlingRepository.run(AbstractSlingRepos
itory.java:913)

       at java.lang.Thread.run(Thread.java:619)



--------------------------------------------------------------------
This email is intended only for the person or entity to which it is addressed 
and may contain information that is privileged, confidential or otherwise 
protected from disclosure. Dissemination, distribution or copying of this email 
or the information herein by anyone other than the intended recipient, or an 
employee or agent responsible for delivering the message to the intended 
recipient, is prohibited.  If you have received this email in error, please 
immediately notify us by calling our Help Desk at (415) 581-5552 or by 
e-mailing us at [email protected].

Reply via email to