3 Replies Latest reply on May 14, 2012 1:17 PM by Eric Manuguerra

    Remote JMS connection from JBoss AS 5.1 to JBoss AS 7.1

    Eric Manuguerra Newbie



      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
                    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());



      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,