2 Replies Latest reply on Jan 19, 2006 3:41 PM by yantriki

    How to access Stateless Session bean from within MBean Servi

      Statement of Problem
      ==============
      How to use to EJB 3.0 Stateless Session Bean from within a JBoss Service.

      Scenario
      =======
      1. I have created a LoginModule which I am packaging as a SAR DynamicConfig MBean. The LoginModule internally calls Stateless Session bean to authenticate userid and password.

      2. The EJB is configured to use this Login Module. The LoginModule is called when the web-tier tries to access a restricted resource. However within this login Module, I am unable to obtain reference to Stateless Session Bean.

      Errors I am getting in JBoss
      ==================
      When I do not package the Remote interface of the Session bean, I get the

      NoClassDefFound Exception


      else when I package the Stateless Session Bean Remote interface class file into the SAR. I get ClassCastException:

      java.lang.ClassCastException: $Proxy187

      I have tried all combinations of lookups and @EJB injection, nothing seems to work. I would appreciate any help.

        • 1. Re: How to access Stateless Session bean from within MBean S
          jgc195

          Hi,

          You shouldn't need the Remote interface if your classes operate in the same JVM.

          Not sure if this will help, but I had the same problem as you (java.lang.ClassCastException: $ProxyXXX) when I was trying to use a Stateless Session Bean from within a second Stateless Session Bean.

          Basically, my problem was that I was using the Session Bean's implementation class as the destination for my lookup - what I needed to use was the Local interface.

          For example:
          MySession -> Local interface for the MySession Stateless Session Bean
          MySessionBean -> Contains the session bean's implementation code

          I was doing:

          InitialContext ctx = new InitialContext();
          MySessionBean mySess = (MySessionBean)ctx.lookup(MySessionBean.class.getName());
          


          which generated the ClassCastException. I changed this to
          InitialContext ctx = new InitialContext();
          MySession mySess = (MySession)ctx.lookup(MySession.class.getName());
          


          Its worth checking....

          Cheers,

          Jason

          • 2. Re: How to access Stateless Session bean from within MBean S

            I am using the appropriate class to typecast.