2 Replies Latest reply on Jul 26, 2006 8:40 AM by Richard Gruet

    Calling an EJB method from a servlet via its Local interface

    Richard Gruet Newbie

      Hi all

      Is it possible to call an EJB3 Stateless Session Bean method from a servlet via its Local interface ? I'm using the Tomcat embedded in JBoss 4.0.4, and it's not clear to me whether Tomcat and JBoss are in the same JVM (thus making the call theorically possible).

      I have no problem calling my EJB method via its Remote interface.
      I get the bean ref from JNDI without problem, but that's the actual call that fails with an IllegalArgumentException: Wrong target. class theBeanClass . I'm calling the method via the reflexion API:

      method.invoke(ejb, params)


      Any help would be greatly appreciated

      Richard

        • 1. Re: Calling an EJB method from a servlet via its Local inter
          Peter Johnson Master

          Tomcat and the app server (actually, EJB container) are runnign in the same JVM so you can use the local interface.

          However, if you use the remote interface, JBoss is smart enough to know that the session bean is local and use a local connection anyway.

          I've never tried using the relfection API to make ejb method calls. I always either cast the ejb to the local interface, or use PortableRemoteObject.narrow for the remote interface, and then make the calls directly on the resulting proxy.

          • 2. Re: Calling an EJB method from a servlet via its Local inter
            Richard Gruet Newbie

            Thanks for the info.

            I'm using reflection because my servlet is an XFire one which dispatches SOAP requests to my EJB via an invoker, which uses the reflection API.

            I ran some tests an found that in my case local calls from the servlet work with one example EJB, but unfortunately not with my target one, which implements the Service Endpoint Interface (SEI) of my WS. The only difference I can think of so far is that this SEI has been generated by the XFire wsdl to Java utility (wsgen), which might have made it somewhat special in some way (annotations ?). I'm still investigating the issue...

            Richard