3 Replies Latest reply on May 14, 2012 1:17 PM by michel.strogoff

    Remote JMS connection from JBoss AS 5.1 to JBoss AS 7.1

    michel.strogoff

      Hi,

       

      I am trying to send a message to a remote queue deployed on a JBoss as 7.1.1.Final / HornetQ server from a stateless EJB3 on JBoss AS 5.1.

       

      I have tried to use the Alunite class loader as described in this message and here. in order to load jboss-client.jar (from as 7) in an isolated class loader :

       

          

                  // Loads as 7 client jar with Alunite
                  this.loadAS7ClientJar();
      
                    Hashtable< String, String > env = new Hashtable< String, String >();
                    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
                    env.put(Context.PROVIDER_URL, url);
      
                    // UserName & Password for the Initial Context for JNDI lookup
                    // This user should have been created in the JBoss realm
                    env.put(Context.SECURITY_PRINCIPAL, user);
                    env.put(Context.SECURITY_CREDENTIALS, password);
      
                    as7InitialContext = new InitialContext(env);
      
                    // Lookup the JMS connection factory
                    connectionFactory = (ConnectionFactory) as7InitialContext.lookup(JBossAs7JNDIClient.JMS_REMOTE_CONNECTION_FACTORY);
      

       

      and for class loading :

       

       

      public void loadAS7ClientJar() throws MalformedURLException
      {
      
      String jbossHome = System.getenv("JBOSS_HOME");
        
              if (jbossHome == null)
              {
                     jbossHome = System.getProperty("jboss.home");
              }
      
              if (jbossHome == null)
              {
                    throw new IllegalStateException("Neither JBOSS_HOME (env) nor jboss.home (property) is set");
              }
      
                File as7ClientJar = new File(jbossHome, AS7_CLIENT_JAR);
      
                LOG.info("Loading {} {}", as7ClientJar.getAbsolutePath(), as7ClientJar.exists());
      
                URL clientUrl = as7ClientJar.toURI().toURL();
      
                URL urls[] = { clientUrl };
      
                // Don't set a parent, so we run in complete isolation.
                URLClassLoader urlCl = new URLClassLoader(urls, null);
                ClassLoader cl = new AluniteClassLoader(urlCl, ClassLoader.getSystemClassLoader());
      
                Thread.currentThread().setContextClassLoader(cl); 
      
        }
      

       

       

      I get a class cast exception : HornetQJMSConnectionFactory cannot be cast in javax.jms.ConnectionFactory.

       

      What is the proper way to lookup a remote connection factory from AS 5 to AS 7 ?

       

      Why do I get a ClassCastException since the current thread class loader is isolated and having the jboss-client.jar in his path ?

       

      Thanks for your help,

      Best regards,

      Eric

        • 1. Re: Remote JMS connection from JBoss AS 5.1 to JBoss AS 7.1
          michel.strogoff

          I have found a workaround solution which might be useful to others, so I post it here :

           

          I use direct instantiation of connection factory, a feature of HornetQ.

           

          This way I don't need to cast the ConnectionFactory proxy returned by the JNDI lookup and I don't experience any client library version conflict neither. Alunite class loader is not necessary in that case.

           

          Best regards,

          Eric

          1 of 1 people found this helpful
          • 2. Re: Remote JMS connection from JBoss AS 5.1 to JBoss AS 7.1
            jbertram

            Have you tried not using the special classloader for the AS7 client library? 

             

            The two links you cited were discussing calls from AS 4.x to AS 5.x.  In this case, a special classloader was needed because both AS 4.x and 5.x shared classes with the same name even though enough changes were made between the versions to render them incompatible.  For calls from AS 5.x to AS 7 I don't think the special classloader would be needed because AS 7 is essentially 100% new.

            • 3. Re: Remote JMS connection from JBoss AS 5.1 to JBoss AS 7.1
              michel.strogoff

              Hi Justin,

               

              Thank you for your interest :-).

               

              That"s what I tried first : I have added the jboss-client.jar (from AS 7) to the application classpath. But I had some ClassNotFound exceptions. I have not dug much into it. I thought immediately that it would be a conflicting situation between the AS 5 and the AS 7 client JNDI libraries that would be difficult to manage : sometimes the AS 5 classes should take precedence (for local JNDI calls), and sometimes the AS 7 libraries (for remoting).

               

              If 100% of the classes involved have new qualified names, it may be possible, but It doesn't seems to.

               

              Best regards,

              Eric