8 Replies Latest reply on Mar 1, 2011 2:07 AM by jaikiran pai

    Problem with environment entries in application.xml

    Marcus Portmann Newbie

      Hello,

       

      I am using JBoss-6.0.0.Final.

       

      I have a JEE 6 application where I am attempting to retrieve a java.lang.String environment entry (env-entry) specified in the EAR's application.xml file using the @Resource(lookup("...")) mechanism in a servlet.

       

      I have tried all the different naming conventions shown below in the application.xml file but all of them result in a "NOT FOUND Depends on" error when instantiating the servlet with the @Resource annotated variable.

       

      I have also tried to remove the annotations and dump the application's JNDI tree recursively but the environment entries are not present.

       

      My question is: Should environment entries declared in the application.xml file be accessible to all WARs and EJB JARs that are contained in the EAR when using JEE 6?

       

        <env-entry>

          <env-entry-name>TestValue</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>Hello World!</env-entry-value>

        </env-entry>

        <env-entry>

          <env-entry-name>java:app/TestValueApp</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>Hello World!</env-entry-value>

        </env-entry>

        <env-entry>

          <env-entry-name>java:app/env/TestValueAppEnv</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>Hello World!</env-entry-value>

        </env-entry>

        <env-entry>

          <env-entry-name>java:global/TestValueGlobal</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>Hello World!</env-entry-value>

        </env-entry>

        <env-entry>

          <env-entry-name>java:global/env/TestValueGlobalEnv</env-entry-name>

          <env-entry-type>java.lang.String</env-entry-type>

          <env-entry-value>Hello World!</env-entry-value>

        </env-entry>


      Regards,

       

      Marcus

        • 1. Problem with environment entries in application.xml
          Benjamin Seyinbour Expert

          Hi Marcus,

           

          Use of "<env-entry>" in application.xml is rare to find, but are you not missing the "lookup-name" entry?

           

          Cheers.

          • 2. Problem with environment entries in application.xml
            Marcus Portmann Newbie

            Hi Benjamin,

             

            I have tried again with the following but none of the entries are being added to the JNDI.

             

              <env-entry>

                <env-entry-name>java:app/TestValueApp</env-entry-name>

                <env-entry-type>java.lang.String</env-entry-type>

                <env-entry-value>Hello World!</env-entry-value>

                <lookup-name>java:app/TestValueApp</lookup-name>

              </env-entry>

              <env-entry>

                <env-entry-name>java:app/env/TestValueAppEnv</env-entry-name>

                <env-entry-type>java.lang.String</env-entry-type>

                <env-entry-value>Hello World!</env-entry-value>

                <lookup-name>java:app/env/TestValueAppEnv</lookup-name>

              </env-entry>

              <env-entry>

                <env-entry-name>java:global/TestValueGlobal</env-entry-name>

                <env-entry-type>java.lang.String</env-entry-type>

                <env-entry-value>Hello World!</env-entry-value>

                <lookup-name>java:global/TestValueGlobal</lookup-name>

              </env-entry>

              <env-entry>

                <env-entry-name>java:global/env/TestValueGlobalEnv</env-entry-name>

                <env-entry-type>java.lang.String</env-entry-type>

                <env-entry-value>Hello World!</env-entry-value>

                <lookup-name>java:global/env/TestValueGlobalEnv</lookup-name>

              </env-entry>


             

             

            Regards,

             

            Marcus

            • 3. Re: Problem with environment entries in application.xml
              Benjamin Seyinbour Expert

              Hi Marcus,

               

               

              Have you tried either [A] or [B] below:

               

              <env-entry>

                  <env-entry-name>java:app/env/TestValueApp</env-entry-name>

                  <env-entry-type>java.lang.String</env-entry-type>

                  <env-entry-value>Hello World!</env-entry-value>

                </env-entry>

               

               

              [A]

              String valueApp = (String)InitialContext.doLookup("java:app/env/TestValueApp");

               

              [B]

              @Resource(name="java:app/env/TestValueApp")

              private String valueApp;

               

              Cheers

              • 4. Problem with environment entries in application.xml
                Mark Paluch Master

                Hi Marcus,

                according to Sun/Oracle specs following Example should create an Entry that can be looked up with "java:comp/env/greetings"

                 

                <env-entry>

                <description>welcome message</description>

                <env-entry-name>greetings</env-entry-name>

                <env-entry-type>java.lang.String</env-entry-type>

                <env-entry-value>Welcome to the Inventory Control

                                           System</env-entry-value>

                </env-entry>

                 

                In case that JBoss really does not add any Entries, check whether JBoss' processes/ignores your application.xml

                See http://java.sun.com/developer/technicalArticles/xml/WebAppDev4/ for further Information.

                 

                Best regards,

                Mark

                • 5. Re: Problem with environment entries in application.xml
                  Marcus Portmann Newbie

                  Hi Benjamin,

                   

                  When trying option [A] I get a NameNotFoundException on the (env) component of the name.

                   

                   

                  When trying option [B] the value for the valueApp variable is null. This occurs when I use option [B] in a ServletContextListener and in a HttpServlet.

                   

                  If I move the env-entry declaration to the web.xml file then option [A] works both in a ServletContextListener and in a HttpServlet but option [B] is still null in both instances.

                   

                  Regards,

                   

                  Marcus

                  • 6. Re: Problem with environment entries in application.xml
                    Marcus Portmann Newbie

                    Hi Mark,

                     

                    I have tested your example, i.e. dropping the java:app prefix (using greetings as the env-entry-name), and what I found is that I get a NameNotFoundException when the env-entry is in the application.xml file but if I move it to the web.xml file then the InitialContext.doLookup approach works perfectly using the name (java:comp/env/greetings).

                     

                    It appears as if the env-entry entries in the application.xml file are being ignored.

                     

                    Regards,

                     

                    Marcus

                    • 7. Re: Problem with environment entries in application.xml
                      Marcus Portmann Newbie

                      Hi Benjamin,

                       

                      I have done a bit more testing and I think I have discovered the reason why the @Resource annotation is not being correctly processed for my ServletContextListener and HttpServlet.

                       

                      It is not related to whether the env-entry is declared in the application.xml or web.xml. Instead it seems to be as a result of my context listener and servlet being declared in another JAR which is included in my WAR. The servlets that form part of my WAR (under WEB-INF/classes) are being injected correctly when using the @Resource annotation. By correctly I mean that the injection works when then env-entry is declared in the web.xml file but I get a "NOT FOUND Depends" error when the env-entry is declared in the application.xml file.

                       

                      Not sure whether I should open another discussion related to injection not working on web resources included from other JARs but referenced from the web.xml in a WAR.

                       

                      Regards,

                       

                      Marcus

                      • 8. Problem with environment entries in application.xml
                        jaikiran pai Master

                        Resource references and environment entries processing in application.xml isn't handled correctly in AS6. So yes this is a bug. I think there was a JIRA for this issue somewhere but I can't seem to locate it. Can you please create a JIRA here https://issues.jboss.org/browse/JBAS?