Jetty
  1. Jetty
  2. JETTY-768

JNDI lookup doesn't work - NameNotFoundException

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 7.0.0pre4
    • Fix Version/s: 7.0.0.pre5
    • Component/s: None
    • Labels:
      None
    • Environment:
      Maven version: 2.0.9
      Java version: 1.6.0_04
      OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
    • Number of attachments :
      0

      Description

      Updated from 7.0.0.pre3 to 7.0.0.pre4 (jetty-maven-plugin). JNDI lookup doesn't work anymore.

      jetty-env.xml:
      <?xml version="1.0"?>
      <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

      <Configure class="org.mortbay.jetty.webapp.WebAppContext">

      <New id="MyConfigArg" class="org.mortbay.jetty.plus.naming.EnvEntry">
      <Arg>MyConfigArg</Arg>
      <Arg type="java.lang.String">content</Arg>
      <Arg type="boolean">true</Arg>
      </New>

      </Configure>

      The file is referenced in the pom.xml of my project:
      <plugin>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <configuration>
      <jettyEnvXml>$

      {project.build.directory}

      /filteredconfig/jetty-env.xml</jettyEnvXml>

      Performing a lookup with:
      Context ctx = new InitialContext();
      Context envCtx = (javax.naming.Context) ctx.lookup("java:comp/env");
      String configArg = (String) envCtx.lookup("MyConfigArg");

      Causes:
      javax.naming.NameNotFoundException; remaining name 'MyConfigArg'
      at org.mortbay.naming.NamingContext.lookup(NamingContext.java:578)
      at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)

      Switched back to 7.0.0.pre3 and everything is fine.

        Issue Links

          Activity

          Hide
          Jan Bartel added a comment -

          Hi Dennis,

          jetty-7.0.0.pre4 has modified the jndi entries api a little. You can now bind a jndi entry at one of 3 scopes - jvm, server or webapp. The scoping was a little flaky in previous releases, and putting something in a context.xml file might have been interpreted as being scoped to the webapp, but it actually wasnt. So the scopes have been made explicit as the first argument of a NamingEntry.

          So now, for example, to scope your binding to only your webapp you do:

          <Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
          <New id="MyConfigArg" class="org.mortbay.jetty.plus.naming.EnvEntry">
          <Arg><Ref id='wac'/></Arg>
          <Arg>MyConfigArg</Arg>
          <Arg type="java.lang.String">content</Arg>
          <Arg type="boolean">true</Arg>
          </New>

          I was sure I documented this on the wiki, but I can't find the page, so I'll have to do it all over again.

          There might also be a bug lurking, as if you leave out the scope argument, your NamingEntry should be bound to the jvm scope by default, so I would have expected your existing config to still be working in pre4. I'll take a look at that.

          I'll leave this issue open until I fix up the wiki and finish investigating the possible bug.

          cheers
          Jan

          Show
          Jan Bartel added a comment - Hi Dennis, jetty-7.0.0.pre4 has modified the jndi entries api a little. You can now bind a jndi entry at one of 3 scopes - jvm, server or webapp. The scoping was a little flaky in previous releases, and putting something in a context.xml file might have been interpreted as being scoped to the webapp, but it actually wasnt. So the scopes have been made explicit as the first argument of a NamingEntry. So now, for example, to scope your binding to only your webapp you do: <Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext"> <New id="MyConfigArg" class="org.mortbay.jetty.plus.naming.EnvEntry"> <Arg><Ref id='wac'/></Arg> <Arg>MyConfigArg</Arg> <Arg type="java.lang.String">content</Arg> <Arg type="boolean">true</Arg> </New> I was sure I documented this on the wiki, but I can't find the page, so I'll have to do it all over again. There might also be a bug lurking, as if you leave out the scope argument, your NamingEntry should be bound to the jvm scope by default, so I would have expected your existing config to still be working in pre4. I'll take a look at that. I'll leave this issue open until I fix up the wiki and finish investigating the possible bug. cheers Jan
          Hide
          Jan Bartel added a comment -

          Hi Dennis,

          I discovered what the problem was. There are new overloaded constructors for EnvEntry to try and maintain backward compatibility (ie without needing the new scope 1st argument), and this was confusing the xml-> java converter, so it was picking the wrong constructor. All you need to do is to provide a null scope argument to make it pick the correct constructor like so:

          <New id="MyConfigArg" class="org.mortbay.jetty.plus.naming.EnvEntry">
          <Arg></Arg>
          <Arg type="java.lang.String">MyConfigArg</Arg>
          <Arg type="java.lang.String">content</Arg>
          <Arg type="boolean">true</Arg>
          </New>

          cheers
          Jan

          Show
          Jan Bartel added a comment - Hi Dennis, I discovered what the problem was. There are new overloaded constructors for EnvEntry to try and maintain backward compatibility (ie without needing the new scope 1st argument), and this was confusing the xml-> java converter, so it was picking the wrong constructor. All you need to do is to provide a null scope argument to make it pick the correct constructor like so: <New id="MyConfigArg" class="org.mortbay.jetty.plus.naming.EnvEntry"> <Arg></Arg> <Arg type="java.lang.String">MyConfigArg</Arg> <Arg type="java.lang.String">content</Arg> <Arg type="boolean">true</Arg> </New> cheers Jan
          Hide
          Jan Bartel added a comment -

          Took out the overloaded constructors. See svn rev 3956 (jetty-7) and 3957 (jetty-6).
          Jan

          Show
          Jan Bartel added a comment - Took out the overloaded constructors. See svn rev 3956 (jetty-7) and 3957 (jetty-6). Jan
          Hide
          Dennis Kieselhorst added a comment -

          Thank you, I'm sucessful with 7.0.0.pre5.

          Show
          Dennis Kieselhorst added a comment - Thank you, I'm sucessful with 7.0.0.pre5.

            People

            • Assignee:
              Jan Bartel
              Reporter:
              Dennis Kieselhorst
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: