2 Replies Latest reply on Sep 15, 2008 3:30 PM by wecucho

    ClassLoader Mess Up

    wecucho

      Hi everyone, im having problems calling Bean from diferent projects, first of all, im using JBoss 4.2.2, i have prepared a simple project to test this particular issue.

      The problem: i have 2 EARs (like most people... :P ), in each EAR i have configure a simple project with only one bean an one method, in project1.ear i have one bean named Saluted with this code:

      package org.gilthanas.project1.bean;
      
      import javax.ejb.Stateless;
      import javax.naming.InitialContext;
      
      import org.jboss.ejb3.JBossProxy;
      
      /**
       * Author: cucho
       * Created on: Sep 15, 2008
       **/
      @Stateless
      public class SaluteBean implements Salute {
      
       public void getSalute() {
      
       System.out.println("Salute from project 1");
      
       }
      
       public void callProject2() {
      
       try {
      
       InitialContext ctx = new InitialContext();
       JBossProxy proxy = (JBossProxy) ctx.lookup("project2/SaluteBean/remote");
       proxy.getAsynchronousProxy();
      
       } catch (Exception e) {
       e.printStackTrace();
       }
      
       }
      
      }
      


      in project 2 i have this bean:
      package org.gilthanas.project2.bean;
      
      import javax.ejb.Stateless;
      
      /**
       * Author: cucho
       * Created on: Sep 15, 2008
       **/
      @Stateless
      public class SaluteBean implements Salute {
      
       public void getSalute() {
       System.out.println("Salute from project 2");
       }
      
      }
      


      note the diference of the packages!!

      so, inside my projet1.ear and project2.ear i have a jar file with only two classes Salute and SaluteBean (from package project1 for the project1 and package project2 for project2, don get confused! all its very carefull ordered), and the following application.xml:

      <?xml version="1.0" ?>
      <application>
      
       <display-name>Some Name</display-name>
      
       <module>
       <ejb>project.jar</ejb>
       </module>
      
       <library-directory>lib</library-directory>
      
      </application>
      


      So, when i run my jboss and i deploy the two EARs (i lost my listen capability :P ...) all deploy goes just fine, and i can call my beans from a client like this running in my eclipse outside the jboss:

      package org.gilthanas.project1.test;
      
      import javax.naming.InitialContext;
      
      import org.gilthanas.project1.bean.Salute;
      
      /**
       * Author: cucho
       * Created on: Sep 15, 2008
       **/
      public class TestP1 {
      
       public TestP1() {
       run();
       }
      
       private void run() {
      
       try {
      
       InitialContext ctx = new InitialContext();
       Salute salute = (Salute) ctx.lookup("project1/SaluteBean/remote");
       salute.getSalute();
      
      
       } catch (Exception e) {
       e.printStackTrace();
       }
      
       }
      
       public static void main(String[] args) {
       new TestP1();
       }
      
      }
      


      and when i call the two projects (calling the getSalute methods of each one) i get an output like this:


      2008-09-15 10:04:55,961 INFO [STDOUT] Salute from project 1
      2008-09-15 10:05:00,645 INFO [STDOUT] Salute from project 2


      But, what happend when i try to call the method ' callProjet2 ' from project1 ? ERROR..

      when i try to reach the project2 from project1 i get an error like this:

      2008-09-15 10:05:13,079 ERROR [STDERR] java.lang.IllegalArgumentException: interface org.gilthanas.project2.bean.Salute is not visible from class loader
      2008-09-15 10:05:13,079 ERROR [STDERR] at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
      2008-09-15 10:05:13,079 ERROR [STDERR] at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
      2008-09-15 10:05:13,079 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessRemoteProxy.getAsynchronousProxy(StatelessRemoteProxy.java:119)
      2008-09-15 10:05:13,079 ERROR [STDERR] at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:148)
      2008-09-15 10:05:13,079 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:83)
      2008-09-15 10:05:13,079 ERROR [STDERR] at $Proxy104.getAsynchronousProxy(Unknown Source)
      2008-09-15 10:05:13,079 ERROR [STDERR] at org.gilthanas.project1.bean.SaluteBean.callProject2(SaluteBean.java:27)
      2008-09-15 10:05:13,079 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2008-09-15 10:05:13,080 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2008-09-15 10:05:13,080 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2008-09-15 10:05:13,080 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,080 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
      2008-09-15 10:05:13,081 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)


      That correspond to the line in org.gilthanas.project1.SaluteBean:


      proxy.getAsynchronousProxy();


      So, until i know... when i perform the lookup from project1 to reach project2 i get a instance of JBossProxy who has inside my real object (SaluteBean from project2) but when i try to reah the object apparently the class loader dont have the interface to perfom the cast...

      i dont understand why, each EAR have a lib directory and is specified in the application.xml, so, the project1.ear have a lib with project2-client.jar (who has the remote class) and the project2.ear has a lib directory woth project1-client.jar..

      i also do a test, copying the clients files (project1-client.jar and project2-client.jar) inside the client folder of the jboss and the lib folder of the server mode im using:


      Into:
      /opt/jboss-4.2.2.GA/client
      /opt/jboss-4.2.2.GA/server/all/lib



      And is the same, he still saying that he does not have the classes... Anyone knows why or have some ideas ?

      NOTE: im using:
      <attribute name="Isolated">true</attribute>
      

      in my ear-deployer.xml because in the future im gonna have a lot of EARs (i will listen again :) ) with independent beans but the same classes, i dont want instances getting mixed.

      Thanks in advance!

        • 1. Re: ClassLoader Mess Up
          wecucho

          Hi everyone, i think my problem is related to this:


          http://wiki.jboss.org/wiki/CommonHurdlesAndDifficultiesYouMayEncounterDuringEJB3Development

          Q: I'am getting a ClassCastException? when I try to cast a Session Bean to it's interface after I successfully obtained the Session Bean over InitialContext? lookup. Whats going on?

          A: You are probably dealing with scoped Beans, remote interfaces and trying to run everything in the same VM while package multiple copies of your interface classes into the different parts of your application(s). Solve this by either:

          * eliminate multiple copies of interfaces, package everything into the same ear
          * run your application in different VMs
          * if required to let different EARs interact with one another in the same VM:
          o enable CallByValue for JNDI in server/xxx/conf/jboss-service.xml or server/xxx/deploy/naming-service.xml
          o upgrade to EJB 3.0 RC4-PFD -- CallByValue is broken in RC3

          A: Maybe you forgot that as of RC4 - the default jndi naming convention is changed (its in the migration notes) - if a quick getClass().getName() on your ic.lookup() says org.jnp.interfaces.NamingContext? and not $Proxy0 - you need to think: APP/BeanName/remote or APP/BeanName/local have a look in the jndi tree with http://localhost:8080 at your global jndi namespace.


          But im not really sure about two things:
          1.- Which version of EJB3 comes with JBoss 4.2.2GA Vanilla.
          2.- The information on the QUOTE seems old.

          Please i appreciate any help, im really stuck here, thx.

          • 2. Re: ClassLoader Mess Up
            wecucho

            Hi everyone, i found my solution i hope this help to others, the only thing you have to do if you are facing the problem in this post is change the CallByValue from FALSE to TRUE in:


            /opt/jboss/server/all/conf/jboss-service.xml


            And thats was all... :)

            See you around!