9 Replies Latest reply on Mar 11, 2015 7:53 AM by pferraro

    Lookup CommandDispatcherFactory

    skull

      Paul said to me to use

      @Resource(lookup = "java:jboss/clustering/dispatcher/web")
      private CommandDispatcherFactory factory = null;
      
      
      
      
      
      
      
      

       

      But i need to do manual lookup because i will run the APP in STANDALONE and HA too.

      if i run with @Resource in a standlone it does not start app with error at @Resource

      in standalone-ha it works fine and lookup manual works just if have @Resource, but without it no lookup (Exception naming not found)

       

      how I can manual lookup it? for standalone and standlone-ha work fine

       

      Its very simple what I want.

        Properties p = new Properties();
        p.put(Context.URL_PKG_PREFIXES, "org.jboss.as.naming.interfaces:org.jboss.ejb.client.naming");
        CommandDispatcherFactory factory = (CommandDispatcherFactory) new InitialContext(p).lookup("java:jboss/clustering/dispatcher/web");
      
      

       

      But

      Why dont work without @Resource?

        • 1. Re: Lookup CommandDispatcherFactory
          rsteeghs

          Hi Juliano,

           

          Did you already find a solution to your problem? I am wondering because we face the same issue.

          • 2. Re: Lookup CommandDispatcherFactory
            skull

            I didnt find. Have you a success?

            But I have 2 builds, one for standalone and another for cluster

             

            • 3. Re: Lookup CommandDispatcherFactory
              pferraro

              Which version of WildFly are you using?  The local CommandDispatcherFactory implementation was added in 8.2.

              • 4. Re: Lookup CommandDispatcherFactory
                pferraro

                To use a vanilla JNDI lookup you will need to define a resource-ref in your deployment descriptor and lookup the entry from the resulting java:comp/env namespace.  This will ensure the proper dependency is created between your deployment and the CommandDispatcherFactory.

                • 5. Re: Lookup CommandDispatcherFactory
                  rsteeghs

                  Thnx...

                  We are using 8.0.0.Final. For now we were able to get it working by changing our standalone server to standalone-ha server with only one node. With this it works just as on our other environment with two nodes started as standalone-ha. Will the resource-ref solution work with 8.0.0.Final?

                  If so then we try this.

                  • 6. Re: Lookup CommandDispatcherFactory
                    skull

                    I am using 8.2.0-Final

                    • 7. Re: Lookup CommandDispatcherFactory
                      skull

                      If i create at web.xml

                       

                      <resource-env-ref>
                          <resource-env-ref-name>dispatcher</resource-env-ref-name>
                          <resource-env-ref-type>org.wildfly.clustering.dispatcher.CommandDispatcherFactory</resource-env-ref-type>
                      </resource-env-ref>
                      
                      

                       

                      then use a Lookup

                       

                      Properties p = new Properties();
                      p.put(Context.URL_PKG_PREFIXES, "org.jboss.as.naming.interfaces:org.jboss.ejb.client.naming");
                      factory = (CommandDispatcherFactory) new InitialContext(p).lookup("java:comp/env/dispatcher");
                      
                      

                       

                      But before the breakpoint stop at Properties p = new Properties();

                      I got an error: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.myapp.myapp.env.dispatcher is missing [jboss.naming.context.java.jboss.resources.dispatcher]"]}

                       

                      I try this at 8.2.0-Final standalone.xml and standalone-ha.xml

                      • 8. Re: Lookup CommandDispatcherFactory
                        pferraro

                        My mistake.  I had intended initially backported the local implementations of the clustering API from WF9 to 8.x, but the change was reverted because of some testsuite regressions.  Thus, non-HA support for the clustering API can be found only in 9.0.0.Alpha1 and later.

                        • 9. Re: Lookup CommandDispatcherFactory
                          pferraro

                          You'd want something like this in web.xml:

                          <resource-ref>
                           <res-ref-name>dispatcher</res-ref-name>
                           <res-type>org.wildfly.clustering.dispatcher.CommandDispatcherFactory</res-type>
                           <res-auth>Container</res-auth>
                           <lookup-name>java:jboss/clustering/dispatcher/web</lookup-name>
                          </resource-ref>