6 Replies Latest reply on Apr 14, 2004 3:47 AM by Raja

    calling an EJB from MBean

    Adrian Wilford Newbie

      Hello!

      I'm developing an MBean to be launched by dispatcher service, and I've a problem. I can't launch any EJB from here. Somebody knows how todo that? I'll thank any suggestion

        • 1. Re: calling an EJB from MBean
          Juha Lindfors Master

          Please clarify your question. What do you mean by "launching any EJB" ?

          • 2. Re: calling an EJB from MBean
            Adrian Wilford Newbie

            Well, I'll try to clarify my question.

            I've an MBean, launched by dispatcher, which every minute verifies the hour and, in some specific moments, calls an EJB.

            I've developed an Entity Bean to access the database, and this EJB is controlled by the corresponding Session Bean. My problem is that I don't know how to launch this Session Bean from the MBean, how to create a Session Bean object in the MBean to access, by the Entity Bean, to the database.

            I've tried to do this of many forms. Sometimes, I obtain a NamingException "not bound", using the BeanManager class defined by sun in Duke'sBank example. If I use this source code directly, I obtain an java.lang.reflect.UndeclaredThrowableException. And this code only tries to obtain a home interface of this EJB!!

            I think the problem is around contexts, because I'm calling an EJB from an MBean, instead of calling from a Servlet. But I don't know how to solve it!

            If somebody has any suggestion, tell me it, please.

            • 3. Re: calling an EJB from MBean
              Juha Lindfors Master

              There's nothing different about invoking an EJB from an MBean compared to invoking an EJB from a standalone client. The same API calls apply and the behavior is the same.

              Naming exception indicates you're using the wrong lookup name trying to get to the home proxy. Use the name in the global name space (MBeans don't have a private ENC and private references like EJBs).

              • 4. Re: calling an EJB from MBean
                Adrian Wilford Newbie

                How can I do it?

                • 5. Re: calling an EJB from MBean
                  Kabir Khan Master

                  I think if you look in the jmx-console under JNDIView you should be able to get the global JNDI names of your EJB's

                  • 6. Re: calling an EJB from MBean
                    Raja Master

                    There are multiple options here.
                    1. You could bundle them all into a EAR (SAR + JAR) so it will be loaded as one single entity.
                    2. As Juha pointed out, its no different from calling it from a standalone client Vs. servlet Vs. MBean. All you need to do is get the InitialContext and lookup your EJB JNDI. You will need to get your Home and Remote interfaces in ur SAR(ofcourse!!).