0

I'm trying to setup a JNDI resource for a Jackrabbit repository factory in Jetty. The problem is that I seem to be getting thhe JNDI as webapp scoped. I need it to be JVM scoped. As far as I understood from the docs, you need to specify a null arg as shown below (<Arg></Arg>) in order to do so (explained here).

I have two webapps deployed to Jetty and I need them to be sharing the same JNDI. If they're not sharing it, Jackrabbit tries to get initialized twice and fails which breaks my whole app.

I ran the code through a debugger and I can see that the first webapp that gets accessed and needs a JNDI lookup for the Jackrabbit repository, gets an instance of the BindableRepositoryFactory and correctly adds records to the cache object. However, a completely different object is created for the cache upon JNDI lookup. That is obviously still empty and thus a new instance gets created, which screws things up.

I am using Jetty 7.6.2.v20120308. Here's my jetty-jndi.xml:

<New class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jndi:comp/env/jcr/repository</Arg>
    <Arg>
        <New class="javax.naming.Reference" id="reference">
            <Arg>javax.jcr.Repository</Arg>
            <Arg>org.apache.jackrabbit.core.jndi.BindableRepositoryFactory</Arg>
            <Arg>null</Arg>
            <Call name="add" id="reference">
                <Arg>
                    <New class="javax.naming.StringRefAddr">
                        <Arg>configFilePath</Arg>
                        <Arg><SystemProperty name="jetty.home" default="."/>/jackrabbit/repository.xml</Arg>
                    </New>
                </Arg>
            </Call>
            <Call name="add" id="reference">
                <Arg>
                    <New class="javax.naming.StringRefAddr">
                        <Arg>repHomeDir</Arg>
                        <Arg><SystemProperty name="jetty.home" default="."/>/jackrabbit</Arg>
                    </New>
                </Arg>
            </Call>
        </New>
    </Arg>
</New>

In the pom file where I'm invoking jetty from, I have the following relevant settings that tell Jetty to use the JNDI and Plus settings xml-s:

<jettyConfig>${project.build.directory}/jetty/etc/jetty-plus.xml,${project.build.directory}/jetty/etc/jetty-jndi.xml</jettyConfig>

In the jetty-plus.xml I have:

<!-- =========================================================== -->
<!-- Sequence of configurations to defining Plus features.       -->
<!-- =========================================================== -->
<Array id="plusConfig" type="java.lang.String">
    <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
    <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>        <!-- Add for JNDI -->
    <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>       <!-- Add for JNDI -->
    <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>          <!-- Not needed for Jetty-8 -->
</Array>


<!-- =========================================================== -->
<!-- Apply plusConfig to all webapps for this Server             -->
<!-- =========================================================== -->
<Call name="setAttribute">
    <Arg>org.eclipse.jetty.webapp.configuration</Arg>
    <Arg>
        <Ref id="plusConfig"/>
    </Arg>
</Call>

Any ideas what I might be doing wrong?

Many thanks in advance! :)

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • Does it work correctly when you deploy to jetty normally in a distribution? I can see how this is potentially an issue with the jetty-maven-plugin. – jesse mcconnell Apr 13 '12 at 15:02
  • @jessemcconnell: Could you please elaborate on the suspected "potential issue"? No, I haven't yet tried it in a standalone Jetty. I will do so now. However, I don't expect it to be much different. After all the Maven plugin is invoking the Jetty server's code. – carlspring Apr 13 '12 at 15:22
  • Partially yes, but the jetty-maven-plugin deals with classloaders a bit different then the traditional distribution. Its been ages since I worked on it but I know it has a number of special cases for pulling dependencies from the maven project and I can see how it might treat jndi goop a bit differently. If this works on the distribution then open a bug at codehaus jira for it and we'll take a look. If it doesn't work as expected on the distribution then open a bug in eclipse bugzilla under RT->Jetty – jesse mcconnell Apr 13 '12 at 15:41
  • I am afraid this fails the same way under the standalone Jetty. – carlspring Apr 13 '12 at 16:17

1 Answers1

0

This appears to be a bug in Jetty's global JNDI resource configuration.

I have filed a bug in Jetty's bugzilla and will accept this answer as correct, despite the fact it is no solution.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • As a followup to this for anybody who stumbles on this page, that was not actually a bug in jetty but a misconfiguration of the webapp. The reference to the bug has a full explanation of what was wrong with the webapp setup. – Jan Feb 21 '13 at 01:40