13 Replies Latest reply on Aug 11, 2015 5:22 AM by christian.beikov

    JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)

    hr.stoyanov

      Hi. I am getting a JNDI look-up failure:

      ...

      Caused by: javax.naming.NameNotFoundException: infinispan/container/S4GCacheContainer -- service jboss.naming.context.java.jboss.infinispan.container.S4GCacheContainer

      ...

      when I try to use the WF's built-in cache. Moreover, when I look at the WF admin console (Runtime-->Sybsystems-->JNDI View), I do not see any of the cache names I expected to have registered under "java:jboss/infinispan/container/" node. There is no failure during the deployment of the WAR file either, just the runtime exception when I access the EJB shown below.

       

      What am I doing wrong?

       

      Details:

       

      1. Here is how I configured the cache in my standalone.xml:

      <subsystem xmlns="urn:jboss:domain:infinispan:2.0">

                 

                  <!-- S4G cache -->

                  <cache-container name="S4GCacheContainer" default-cache="S4GLocalCache" jndi-name="S4GCacheContainer">

                      <local-cache name="S4GLocalCache" jndi-name="S4GLocalCache" batching="true">

                          <file-store passivation="true" purge="false"/>

                      </local-cache>

                  </cache-container>

                  ...

      </subsystem>

       

      2. Here is how I reference the cache container via CDI producer and JNDI:

       

      /** A tag annotation */

      @Qualifier

      @Retention(RUNTIME)

      @Target({METHOD, PARAMETER, FIELD, TYPE})

      public @interface S4G {}

       

      ...

       

      /**A CDI-based type-safe factory.*/

      public class DatabaseProducer {

          ...

         

          @Produces @S4G

          @Resource(lookup="java:jboss/infinispan/container/S4GCacheContainer")

          private CacheContainer cacheContainer;

      }

       

      3. Here is how I try to use it (and getting the above JNDI exception):

       

      @Stateless

      public class ScreensManagerImpl implements ScreensManager {

       

          @Inject @S4G

          private CacheContainer cacheContainer;

          private org.infinispan.Cache<String, String> cache;

       

          @PostConstruct

          public void initCache() {

              this.cache = cacheContainer.getCache();

          }

      ...

      }

        • 1. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
          pferraro

          The value specified by jndi-name="S4GCacheContainer" is resolved relative to the "java:jboss" namespace (if it is not already an absolute name), so the resulting jndi name will be "java:jboss/S4GCacheContainer".

           

          However, it looks like your source code expects the default jndi name, so you can omit the jndi-name attribute altogether.

          • 2. Re: Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
            pferraro

            FYI, you can also inject the Cache directly.  That way your ScreensManagerImpl bean doesn't need to manage the lifecycle of the cache.

            e.g.

            @Resource(lookup = "java:jboss/infinispan/cache/S4GCacheContainer/default")
            private Cache<String, String> cache;
            
            • 3. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
              hr.stoyanov

              Paul,

              I tried your suggestions, but I got the same results:

              Caused by: javax.naming.NameNotFoundException: infinispan/container/S4GCacheContainer [Root exception is java.lang.IllegalStateException]

                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:140)

                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:81)

                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)

                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)

                at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)

                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:188)

                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)

                at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_25]

                at javax.naming.InitialContext.lookup(InitialContext.java:417) [rt.jar:1.8.0_25]

                at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:186) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]

                ... 142 more

              Caused by: java.lang.IllegalStateException

                at org.jboss.msc.value.InjectedValue.getValue(InjectedValue.java:47)

                at org.jboss.as.naming.service.BinderService.getValue(BinderService.java:138)

                at org.jboss.as.naming.service.BinderService.getValue(BinderService.java:46)

                at org.jboss.msc.service.ServiceControllerImpl.getValue(ServiceControllerImpl.java:1158)

                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:129)

              ...

               

              Here is the only change I made to the configuration:

              1. standalone.xml

              ....

              <subsystem xmlns="urn:jboss:domain:infinispan:2.0">

                        

                         <!-- S4G cache -->

                          <cache-container name="S4GCacheContainer" default-cache="S4GLocalCache" >

                              <local-cache name="S4GLocalCache" batching="true">

                                  <file-store passivation="true" purge="false"/>

                              </local-cache>

                          </cache-container>

                        

                          <cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">

                              <local-cache name="passivation" batching="true">

                                  <file-store passivation="true" purge="false"/>

                              </local-cache>

                              <local-cache name="persistent" batching="true">

                                  <file-store passivation="false" purge="false"/>

                              </local-cache>

                          </cache-container>

                         ....

              </subsystem>

               

              2. My java code is the same as before (see earlier post)

               

              One thing I want to mention is that I did the "patch upgrade" from WF 8.1 --->WF 8.2. Could this be breaking things?

              • 4. Re: Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                pferraro

                Let me attempt to reproduce the issue.  In the meantime, I want to rule out the possibility that CDI is attempting to resolve the field too early.  Can you try using a producer method instead?

                e.g.

                @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer")
                private CacheContainer container;
                
                @Produces @S4G
                public void getCacheContainer() {
                     return this.container;
                }
                
                • 5. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                  hr.stoyanov

                  Paul,

                  You latest suggestion of using a getter method does not change the outcome - still the same IllegalStateException.

                  Just for completeness, here is what my jboss-deployment-structure.xml looks like:

                   

                  <jboss-deployment-structure>

                    <deployment>

                      <!-- This allows you to define additional dependencies, it is the same as using the Dependencies: manifest attribute -->

                      <dependencies>

                        <module name="org.hibernate"/>

                        <module name="org.infinispan" services="import"/>

                        <module name="org.infinispan.commons"/>

                      </dependencies>

                    </deployment>

                  </jboss-deployment-structure>

                   

                  With really no documentation on the subject, I included only 2 infinispan modules. Note that servoces="import" does not make any difference..

                  As I mentioned before, I do not see the container registred in JNDI View in the admin console or the browsing JNDI with jboss-cli.

                  • 6. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                    hr.stoyanov

                    Paul,

                    Here is what worked for me - I eliminated the Producer CDI bean and now inject the cache container (but notthe cache) directly in my EJBs and Servlets:

                    ...

                    @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer")    private CacheContainer cacheContainer;


                    Essentially, this article's instructions work:

                    http://www.mastertheboss.com/jboss-frameworks/infinispan/using-infinispan-with-wildfly-8


                    Here is what did not work so far:


                    1. Trying to use CDI producer pattern (which works well for JDBC data sources and JPA entity mangers otherwise). Field or getter - same story/exception as shown earlier.


                    2. Trying to look up the Cache directly, rather the container:

                    ...

                    @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer/default")    private Cache<String,String> cache;

                    ...

                    @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer/S4GLocalCache")    private Cache<String,String> cache;


                    I am getting this deployment exception:


                    09:49:52,045 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "draft.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.draft.draft.env.\"com.peruncs.s4g.web.gwt.server.ScreensManagerImpl\".cache is missing [jboss.naming.context.java.jboss.infinispan.container.S4GCacheContainer.default]"]}

                    09:49:52,046 ERROR [org.jboss.as.server] (management-handler-thread - 1) JBAS015870: Deploy of deployment "draft.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.draft.draft.env.\"com.peruncs.s4g.web.gwt.server.ScreensManagerImpl\".cache is missing [jboss.naming.context.java.jboss.infinispan.container.S4GCacheContainer.default]"]}

                     

                    Please, try the same setup and let us know if this is a Wildfly bug or something else? I provided all relevant code in this email thread, but will provide more if necessary. if you succeed, it'd be really nice to post some documented steps or expand the Wildfly docs.

                     

                    Thanks.

                    • 7. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                      pferraro
                      1. I'll try to reproduce this.
                      2. Your cache jndi names are wrong.  Use: @Resource(lookup = "java:jboss/infinispan/cache/S4GCacheContainer/default")
                      • 8. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                        hr.stoyanov

                        Paul,

                        I am getting the Cache Manager,  not any particular chaches underneath. The

                        JNDI works just fine.

                         

                        /Hristo Stoyanov

                        • 9. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                          pferraro

                          I'm not sure if you realize that my numbered responses were meant to address the 2 items that "did not work so far" in your previous message.  Specifically:

                          Hristo Stoyanov wrote:

                          2. Trying to look up the Cache directly, rather the container:

                          ...

                          @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer/default")    private Cache<String,String> cache;

                          ...

                          @Resource(lookup = "java:jboss/infinispan/container/S4GCacheContainer/S4GLocalCache")    private Cache<String,String> cache;


                          I am getting this deployment exception:


                          09:49:52,045 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "draft.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.draft.draft.env.\"com.peruncs.s4g.web.gwt.server.ScreensManagerImpl\".cache is missing [jboss.naming.context.java.jboss.infinispan.container.S4GCacheContainer.default]"]}

                          09:49:52,046 ERROR [org.jboss.as.server] (management-handler-thread - 1) JBAS015870: Deploy of deployment "draft.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.draft.draft.env.\"com.peruncs.s4g.web.gwt.server.ScreensManagerImpl\".cache is missing [jboss.naming.context.java.jboss.infinispan.container.S4GCacheContainer.default]"]}

                           

                          So, yes, in this case you were indeed trying to reference particular caches via jndi name.  The reason this throws the exception above is because the jndi names are incorrect.  Please see my previous post for the correct names.

                           

                          As for item #1, I'm still looking into this.

                          • 10. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                            hr.stoyanov

                            Paul,

                            Yes, i figured out the error with the incorrect JNDI references.

                             

                            What will be very nice is if we can inject caches with CDI producers as per

                            my earlier attempts.

                             

                            Thanks

                             

                            On Thu, Jan 8, 2015 at 11:31 AM, Paul Ferraro <do-not-reply@jboss.com>

                            • 11. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                              christian.beikov

                              I am experiencing the same or similar problem in Wildfly 9 and have done some further research.

                              When I try to get my hands on a cache container via the following, then I get the IllegalStateException

                              InitialContext.doLookup("java:jboss/infinispan/container/hibernate")
                              

                               

                              Interestingly, the code works as soon as I have an EJB on the classpath that references the same JNDI name statically like this

                              
                              
                              @Singleton
                              public class TestBean {
                              
                              
                                  @Resource(lookup="java:jboss/infinispan/container/hibernate")
                                  private CacheContainer container;
                              
                              
                              }
                              

                               

                              Any ideas what is going there?

                              • 12. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                                pferraro

                                Infinispan resources in WildFly are only created on demand (i.e. they are dynamically started).  Referencing an infinispan resource via JEE annotation forces the required resource to start.  A static jndi lookup does not.  If you want to use a static lookup for a dynamically started resource, you need to first add a <resource-ref> in your deployment descriptor.

                                • 13. Re: JNDI issues with wildfly 8.2.0 and Infinispan 6.0.2 (built-in)
                                  christian.beikov

                                  Makes sense, thanks for the info!