3 Replies Latest reply on Sep 27, 2007 6:33 AM by Frank Kemmer

    NameNotFoundException in Web-Application for 'java:comp/env'

    Frank Kemmer Newbie

      I am deploying a web application into JBoss 4.0.4GA with an embedded Tomcat 5.5 . The deployment descriptor (WEB-INF/web.xml) contains an <env-entry>:

      ...
       <!-- Setup ENC for this webapp -->
       <env-entry>
       <env-entry-name>ecms/configfile</env-entry-name>
       <env-entry-value>server.properties</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
       </env-entry>
      ...
      


      This entry I would like to access via JNDI:

      Context initial = new InitialContext();
      Context environment = (Context)initial.lookup("java:comp/env");
      


      This results in a NameNotFoundException for "env". The code works with a standalone Tomcat but not inside JBoss. The JNDI-View confirms that there is no "java:comp/env":

      java: Namespace
      
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
       +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
       +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
       +- comp (class: javax.naming.Context)
       +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
       +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- jaas (class: javax.naming.Context)
       | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
       +- timedCacheFactory (class: javax.naming.Context)
      Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy cannot be cast to javax.naming.NamingEnumeration
       +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
       +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
       +- Mail (class: javax.mail.Session)
       +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
       +- TransactionManager (class: org.jboss.tm.TxManager)
      


      My question: How can this happen? I thought the ENC has to exist for every application component, including webapps.

      How do I need to configure JBoss to make an ENC available for my web application?

      Any help really appreciated.

      Forgive me my spelling errors since english is not my native language.

        • 1. Re: NameNotFoundException in Web-Application for 'java:comp/
          Frank Kemmer Newbie

          I could isolate the problem a little more. I had the Web Application deployed through a context definition in jbossweb-tomcat55.sar/server.xml to a directory outside of the JBoss Installation. This way the web application was not deployed by [TomcatDeployer] and whenever an application does not get deployed by [TomcatDeployer] there will be no ENC [java:comp/env] for this web application, as it seems.

          Now I tried the following: I deployed my Web Application in deploy/mywebapp.war and put the following context.xml into the WEB-INF directory:

          <Context debug="0" reloadable="true" swallowOutput="true">
           <Parameter name="log4j" override="false" value="/usr/share/config/log4j.properties"/>
           <Environment name="ecms/configfile" override="false" type="java.lang.String" value="/usr/share/config/service.properties" />
          </Context>
          


          Now something really funny happens. The web application gets deployed by [TomcatDeployer], it can read the ServletContext Init-Parameter "log4j" as expected. it gets an ENC [java:comp/env], but the Environment parameter defined in the context.xml won't appear under [java:comp/env/ecms/configfile] as expected. In fact it doesn't appear anywhere.

          Can any of the JBoss Gurus enlighten me, why JBoss is unable to setup Environment Parameters defined in a context.xml file?

          My feelings are, that Tomcat uses a different JNDI Implementation then JBoss itself, so its Environment Definitions won't affect the JBoss JNDI Naming Contexts ...

          Eventually I need a way to setup this ENC entry outside of the web application war file. But even the inside context.xml does not work as expected.

          Any help would be really appreciated ...

          • 2. Re: NameNotFoundException in Web-Application for 'java:comp/
            wayne baylor Apprentice

            have you tried the <env-entry> tag in web.xml?

            • 3. Re: NameNotFoundException in Web-Application for 'java:comp/
              Frank Kemmer Newbie

              Yes, I have tried the <env-entry> tag in the web.xml and that works. But this does not really help me. Why? Our customer wants to receive the WAR archive and don't change anything inside the archive. The two parameters he wants to configure, should be configured outside of the archive. With the standalone tomcat this was not a problem, since you could define the environment entries in the container context (e.g. server.xml). But with the tomcat embedded in jboss this seems to be a really big problem.

              In my oppinion the problem has to do with JNDI in tomcat and the jboss bean for initializing the embedded tomcat. The embedded tomcat does not consider environment entries and standalone context.xml files in its conf directory. Only context.xml in the war file seems ok, but even there it won't consider environment entries, only servlet init parameters ... this is so frustrating ...

              I give up on this problem and will try to use something different than JNDI ENC contexts since this seems not to work with the tomcat embedded in jboss as expected ... you even cannot put global entries into the local servlet ENC ...

              I even tried the JNDIBindingServiceMgr. But you have no chance to import these global values into "java:comp/env", since it does not allow to set anything in the "java:" namespace. Link-References do not work, the same prob as with Environment Entries ...

              I am lost and I give up.