title: Lookup of JMS Connection Factory Pool on Glassfish cluster fails
body: <p>I have an application that works on a standalone domain but fails in the cluster setup.</p>
  
  <p>In my application I have a JCA Resource Adapter that needs to send a message over a JMS Message on a specific situation in the EIS, so in the Connection Implementation after the event I call <code>getJMSConnectionFactory</code>.</p>
  
  <pre><code>private Object lookup(String what) {
      try {
          // needs no environment
          Context jndiContext = new InitialContext();
          return jndiContext.lookup(what);
      } catch (NamingException ex) {
          throw MyProjectException.getInstance("lookup of " + what + " failed.", ex);
      }
  }
  
  public ConnectionFactory getJMSConnectionFactory() throws JMSException {
      return (ConnectionFactory)lookup("java:comp/DefaultJMSConnectionFactory");
  }
  </code></pre>
  
  <p>I also lookup the Destination that way and send the JMS message afterwards. Now that works as expected when I deploy to a single domain, but when I try to do that in a clustered setup, I get this exception (relevant details below):</p>
  
  <pre><code>javax.ejb.EJBException
  Caused by: myclasspath.MyProjectException: sayHelloyOverJMS
  Caused by: myclasspath.MyProjectException: lookup of java:comp/DefaultJMSConnectionFactory failed.
  Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/DefaultJMSConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Lookup failed for 'jms/__defaultConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]]]
  Caused by: javax.naming.NamingException: Lookup failed for 'jms/__defaultConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]]
  Caused by: javax.naming.NamingException: Unable to lookup resource : jms/__defaultConnectionFactory [Root exception is com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}]
  Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
  Caused by: javax.naming.NamingException: Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: jms]
  Caused by: javax.naming.NameNotFoundException: jms
  </code></pre>
  
  <p>I think the relevant details are:</p>
  
  <pre><code>Lookup failed for '__SYSTEM/pools/jms/__defaultConnectionFactory-Connection-Pool'.
  </code></pre>
  
  <p>That seems to find '__SYSTEM/pools' but then not 'jms'. I did look into the GUI of Glassfish to the configuration of the connection pool <code>
  jms/__defaultConnectionFactory-Connection-Pool</code>, but I did not find any information about 'targets' there, so I assume it should be available in the whole domain, including clusters. The Resources Tab of the cluster configuration does not list the connection pool (or any other '__SYSTEM' entries for that matter).</p>
  
  <p>When I ask glassfish what JNDI Resources are available:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ asadmin list-jms-resources cluster_name
  jms/DataFlowClusterCommunicationTopic
  jms/__defaultConnectionFactory
  Command list-jms-resources executed successfully.
  
  $ asadmin list-jms-resources domain-1-instance
  remote failure: The list-jms-resources command is not allowed on target domain-1-instance because it is part of cluster cluster_name
  Command list-jms-resources failed.
  
  $ asadmin list-jms-resources domain
  jms/DataFlowClusterCommunicationTopic
  jms/__defaultConnectionFactory
  Command list-jms-resources executed successfully.
  </code></pre>
  
  <p>So, as far as I understood it, the <code>jms/__defaultConnectionFactory</code> name is present, and should be found in the clustered setup as much as the domain setup.</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>AS: GlassFish Server Open Source Edition 4.1.1 (build 1)</li>
  <li><p>Java:</p>
  
  <ul>
  <li>openjdk version "1.8.0_111"</li>
  <li>OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2-b14)</li>
  <li>OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)</li>
  </ul></li>
  <li><p>OS: Linux fuchs-linux-pc 4.7.0-1-amd64 #1 SMP Debian 4.7.8-1 (2016-10-19) x86_64 GNU/Linux</p></li>
  <li>Build with maven 3</li>
  </ul>