14 Replies Latest reply on Dec 9, 2011 2:59 AM by Ståle Pedersen

    Environment entry (<env-entry>) is not available under java:comp/env

    Will Reichert Newbie

      We are testing the latests 7.1.0.b1 "Tesla" release of jboss-as and are running into a startup issue when deploying part of the enterprise spec application. The application has an <env-entry> that defines an Integer in web.xml

       

            <env-entry>

                  <description>This env entry is to set the core thread pool size of the delivery scheduler</description>

                  <env-entry-name>supplier.deliveryhandler.poolsize</env-entry-name>

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

                  <env-entry-value>10</env-entry-value>

            </env-entry>

       

      The application initializes a private static variable by calling ic.lookup("java:comp/env/supplier.deliveryhandler.poolsize")).intValue();

       

      The result is the following exception.

       

      13:46:00,803 ERROR [stderr] (MSC service thread 1-1) javax.naming.NameNotFoundException: java:comp/env/supplier.deliveryhandler.poolsize

      13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:90)

      13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

      13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at javax.naming.InitialContext.lookup(InitialContext.java:411)

       

       

      The JBoss Management : JNDI Bindings screen shows the following:

       

      java:

      TransactionManager                                TransactionManagerDelegate@7041b32e

       

      java:jboss

      TransactionManager                                TransactionManagerDelegate@7041b32e

      TransactionSynchronizationRegistry      TransactionSynchronizationRegistryImple@7dc377b2

      UserTransaction                                       Transaction: unknown

       

      jaas:

      jboss-ejb-policy                                         JBossCachedAuthenticationManager@5ac0628d

      other                                                           JBossCachedAuthenticationManager@c864587

      jboss-web-policy                                       JBossCachedAuthenticationManager@433ea87d

       

      mail

      Default                                                       Session@1f76f752

       

      datasources

      ExampleDS                                              WrapperDataSource@17cfb961

       

      applications

      emulator.ear

      java:app

      AppName                                                   emulator

       

       

      Thanks for any guidance you may be able to provide so that we can start running the spec application once 7.1 is ready.

        • 1. Re: Environment entry (<env-entry>) is not available under java:comp/env
          jaikiran pai Master

          Will Reichert wrote:

           

           

          The application initializes a private static variable by calling ic.lookup("java:comp/env/supplier.deliveryhandler.poolsize")).intValue();

           

          Which class in the application does that and when?

           

           

          Will Reichert wrote:

          The result is the following exception.

           

          13:46:00,803 ERROR [stderr] (MSC service thread 1-1) javax.naming.NameNotFoundException: java:comp/env/supplier.deliveryhandler.poolsize

          13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:90)

          13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

          13:46:00,804 ERROR [stderr] (MSC service thread 1-1)           at javax.naming.InitialContext.lookup(InitialContext.java:411)

           

          Could you please post the entire exception stacktrace?

          • 2. Re: Environment entry (<env-entry>) is not available under java:comp/env
            Ståle Pedersen Newbie

            hi jaikiran, the class that does this is a "normal" pojo deployed in the same .war. the full stacktrace:

             

            22:11:29,515 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-1) register: jboss.ws:context=emulator,endpoint=org.spec.jent.supplier.emulator.SupplierService

            22:11:29,612 ERROR [stderr] (MSC service thread 1-1) javax.naming.NameNotFoundException: java:comp/env/supplier.deliveryhandler.poolsize

            22:11:29,612 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:90)

            22:11:29,612 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

            22:11:29,612 ERROR [stderr] (MSC service thread 1-1)           at javax.naming.InitialContext.lookup(InitialContext.java:411)

            22:11:29,612 ERROR [stderr] (MSC service thread 1-1)           at org.spec.jent.supplier.emulator.ThreadSchedulerFactory._getInstance(ThreadSchedulerFactory.java:36)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at org.spec.jent.supplier.emulator.ThreadSchedulerFactory.<clinit>(ThreadSchedulerFactory.java:19)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at org.spec.jent.supplier.emulator.SupplierService.<init>(SupplierService.java:42)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at java.lang.Class.newInstance0(Class.java:372)

            22:11:29,613 ERROR [stderr] (MSC service thread 1-1)           at java.lang.Class.newInstance(Class.java:325)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.newInstance(NonSpringBusHolder.java:169)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.configure(NonSpringBusHolder.java:96)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.startDeploymentBus(BusDeploymentAspect.java:109)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.start(BusDeploymentAspect.java:132)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.webservices.deployers.AspectDeploymentProcessor.deploy(AspectDeploymentProcessor.java:75)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

            22:11:29,614 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

            22:11:29,615 ERROR [stderr] (MSC service thread 1-1)           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

            22:11:29,615 ERROR [stderr] (MSC service thread 1-1)           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

            22:11:29,615 ERROR [stderr] (MSC service thread 1-1)           at java.lang.Thread.run(Thread.java:722)

            • 3. Re: Environment entry (<env-entry>) is not available under java:comp/env
              Will Reichert Newbie

              The process probably starts with the initialization of an @WebService...

              @WebService(serviceName = "SupplierService",

                      portName = "SupplierBinding",

                      endpointInterface = "org.spec.jent.ws.supplier.SupplierPortType",

                      targetNamespace = "org:spec:jent:ws:supplier",

                      wsdlLocation = "WEB-INF/wsdl/SupplierService/PurchaseOrder.wsdl")

              public class SupplierService implements SupplierPortType {

              ...

              ScheduledThreadPoolExecutor stpe = ThreadSchedulerFactory.getInstance();

              ...}

               

              ThreadSchedulerFactor.getInstance calls the following...

              InitialContext ic = new InitialContext();

              corePoolSize = ((Integer) ic.lookup("java:comp/env/supplier.deliveryhandler.poolsize")).intValue();

              • 4. Re: Environment entry (<env-entry>) is not available under java:comp/env
                jaikiran pai Master

                So it looks like this is a POJO webservice, running within the web context, which then instantiaties and invokes on a class which does the java:comp/env lookup. I'm not sure what the webservice spec has to say about access to java:comp/env from a POJO webservice. I'll ping Richard or Alessio to see what they have to say.

                • 5. Re: Environment entry (<env-entry>) is not available under java:comp/env
                  Stephen Coy Master

                  This is indeed possible according to the spec. In fact he should be able to inject the value (into the web service pojo) using

                   

                  @Resource("supplier.deliveryhandler.poolsize")

                   

                  This works even in JEE5 land.

                   

                  Does @Resource injection work into the web service component?

                   

                  Removed junk about threads after reading stack trace

                  • 6. Re: Environment entry (<env-entry>) is not available under java:comp/env
                    Stephen Coy Master

                    Actually, the stack trace suggests that you're doing this lookup from the SupplierService constructor, so your environment context is probably not set up yet.

                     

                    I think you need to do this initialisation from a @PostConstruct method instead.

                    • 7. Re: Environment entry (<env-entry>) is not available under java:comp/env
                      Ståle Pedersen Newbie

                      the problem is that this used to work on as5/6 and its not an option to change the code... - dont ask

                      • 8. Re: Environment entry (<env-entry>) is not available under java:comp/env
                        Jeremy Whiting Expert

                        Yes I agree the context has not been establised when the constructor is called.

                         

                        I have built a simple webservice recreating this issue. It fails to load the web service. Though a servlet in the same web app can access the env-entry during a GET request.

                         

                        Time to raise a JIRA ?

                         

                        Jeremy

                        • 9. Re: Environment entry (<env-entry>) is not available under java:comp/env
                          Stephen Coy Master

                          I don't believe it's a bug.

                           

                          It has never been safe/portable to access the environment context (such as security information or JNDI ENC lookups) from the constructor of any enterprise java component, whether it's a servlet, EJB, filter, web service, etc. These objects all have defined life cycles for just this reason.

                           

                          That said, it would be interesting to see if your test web service works as you expect in WebSphere and WebLogic. I know that WebSphere can be particularly narky about these things.

                          • 10. Re: Environment entry (<env-entry>) is not available under java:comp/env
                            Richard Opalka Master

                            The spec. doesn't guarantee you the access to JNDI in EE components constructors.

                            The portable solutions are:

                            * either use @Resource annotation

                            * or when using NamingContext directly, all initialization code have to be in @PostConstruct annotated method(s)

                             

                            Stephen Coy wrote:

                             

                            This is indeed possible according to the spec. In fact he should be able to inject the value (into the web service pojo) using

                             

                            @Resource("supplier.deliveryhandler.poolsize")

                             

                            This works even in JEE5 land.

                             

                            Does @Resource injection work into the web service component?

                             

                            Removed junk about threads after reading stack trace

                            • 11. Re: Environment entry (<env-entry>) is not available under java:comp/env
                              Richard Opalka Master

                              Hi Will,

                               

                              The JNDI isn't initialized completely yet when you're accesing it from EE component constructor.

                              The JNDI is completely initialized later in the deployers chain.

                              See my previous post for portable solutions.

                              Yes, we know it used to work in AS 5(6), but these days are over

                              Your usecase is not guaranteed by EE specs.

                              Will Reichert wrote:

                               

                              Thanks for any guidance you may be able to provide so that we can start running the spec application once 7.1 is ready.

                              • 12. Re: Environment entry (<env-entry>) is not available under java:comp/env
                                jaikiran pai Master

                                Jeremy Whiting wrote:

                                 

                                 

                                 

                                I have built a simple webservice recreating this issue.

                                Does that example too use the lookup in the constructor or does it do it in the @PostConstruct?

                                • 13. Re: Environment entry (<env-entry>) is not available under java:comp/env
                                  jaikiran pai Master

                                  jaikiran pai wrote:

                                  Does that example too use the lookup in the constructor or does it do it in the @PostConstruct?

                                  Nevermind, just noticed that you created https://issues.jboss.org/browse/AS7-2961 with the details. Like Richard and Stephen say, this isn't a bug in AS7 but instead is a bug in the application code which does that lookup in the constructor.