7 Replies Latest reply on Nov 3, 2010 6:54 AM by auth.gabor

    EJB call from 4.2.3 to 5.1.0?

    auth.gabor

      Hi,

       

        I have got a JBoss 4.2.3.GA cluster and a JBoss 5.1.0.GA cluster and I migrating services from 4.2.3 to 5.1.0... but I can't call remote EJB3 from JBoss 4.2.3 to JBoss 5.1.0, it is possible?

       

        What did I do:

            String className = "name of the Remote interface";

            String providerUrl = BIND_ADDRESS + ":1100";

            Properties properties = new Properties();

            properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

            properties.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

            properties.put(Context.PROVIDER_URL, providerUrl);

            InitialContext ic = new InitialContext(properties);

            ServiceRemoteInterface service = (ServiceRemoteInterface) ic.lookup(className);

       

        The last line throws an exception:

      java.lang.ClassCastException: javax.naming.Reference cannot be cast to hu.package.ServiceRemoteInterface

       

        What did I do wrong? What can I do? Any idea?

      --

      Gábor Auth

        • 1. Re: EJB call from 4.2.3 to 5.1.0?
          auth.gabor

          Hm... any idea?

          • 2. Re: EJB call from 4.2.3 to 5.1.0?
            wdfink

            I have a lot of problems to call SLSB's between JBoss 4.x and JBoss5.x.

            You might add jbossall-client.jar add to your JB4.x application and use a loader-repository to separate the class loading.

            But we decide due to transaction problems to use one server.

            Our application is EJB2.x (JBoss4) and EJB3 in JBoss5.

            • 3. Re: EJB call from 4.2.3 to 5.1.0?
              f_marchioni

              Have a look at this, from Carlo's blog :http://wolf-71.blogspot.com/2010/02/et-phone-home.html

              Hope it helps,

              Francesco

               

              JBoss tutorials

              • 4. Re: EJB call from 4.2.3 to 5.1.0?
                auth.gabor

                I've tried it, but:

                java.lang.ClassCastException: $Proxy139 cannot be cast to hu.package.ServiceRemoteInterface

                 

                The code was:

                URL[] urls = new URL[2];
                urls[0] = Thread.currentThread().getContextClassLoader().getResource("lib/ServiceRemote-interfaces.jar");
                urls[1] = new URL("file:///opt/jboss-5.1.0.GA/client/jbossall-client.jar");

                 

                URLClassLoader urlCl = new URLClassLoader(urls, null);
                ClassLoader cl = new AluniteClassLoader(urlCl, ClassLoader.getSystemClassLoader());
                ClassLoader previous = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(cl);
                try
                {
                  String providerUrl = "remote_ip:1099";
                  Properties properties = new Properties();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                  properties.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
                  properties.put(Context.PROVIDER_URL, providerUrl);
                  InitialContext ic = new InitialContext(properties);

                 

                  ServiceRemoteInterface service = (ServiceRemoteInterface) ic.lookup(className);

                } finally

                {
                  Thread.currentThread().setContextClassLoader(previous);
                }

                 

                But... Wolf has called JBoss 4 from JBoss 5, I've tried to call JBoss 5 from JBoss 4...

                • 5. Re: EJB call from 4.2.3 to 5.1.0?
                  auth.gabor

                  I've tried a 'loader-repository', but it not works...

                  • 6. Re: EJB call from 4.2.3 to 5.1.0?
                    wolfc

                    It can not be cast because if you're calling from within AS your interface is not on the system class loader.

                     

                    Maybe:

                    ClassLoader previous = Thread.currentThread().getContextClassLoader();

                    ClassLoader cl = new AluniteClassLoader(urlCl, previous);

                     

                    Would do the trick. Only put the jbossall-client.jar URL into the urlCl (isolated class loader). I believe Alunite will then pick your interface from the deployed class loader.

                     

                    At the end of the day it's all a bit tricky and you won't get transaction or security propegation.

                    • 7. Re: EJB call from 4.2.3 to 5.1.0?
                      auth.gabor

                      It works, thank you very much!