Hi Rajesh,

You should be able to look up your beans in JNDI and call your desired methods with help of java reflection.

I just tried a little example. It looks like that:

The registerEJB() method takes a JNDI context name as parameter and looks up your beans in the given context name like "/company/applications".

  public void registerEJBs(String aContextName) throws NamingException{

    NamingEnumeration theNames;

    Context theContext = new InitialContext();

    theNames = getNames(theContext, aContextName);

    while(theNames.hasMore()){

      NameClassPair theName = (NameClassPair)theNames.next();

      Object theObjectRef   = myContext.lookup(aContextName+"/"+theName.getName());

      EJBHome theHome       = (EJBHome)PortableRemoteObject.narrow(theObjectRef, EJBHome.class);

       //This works so far, but i am not sure if the home interface is always at index 0
      Class theHomeInterface= theHome.getClass().getInterfaces()[0];

      System.out.println("Home of "+aContextName+"/"+theName.getName()+" is " + theHomeInterface.getName());

      try{
        java.lang.reflect.Method theCreateMethod;
        Class[] theMethodArgs = {};

        //Get the create() method
        theCreateMethod = theHomeInterface.getMethod("create", theMethodArgs);
        System.out.println("home interface create method " + theCreateMethod.toString());

        Object[] theInvocationArgs = {};

        //Invoke the create method on the home interface
        Object theRemoteObject = theCreateMethod.invoke(theHome, theInvocationArgs);

        //This works so far, but i am not sure if the remote interface is always at index 0
        Class  theRemoteInterface = theRemoteObject.getClass().getInterfaces()[0];

        //You can look up your methods like this
        java.lang.reflect.Method[] theBusinessMethods;
        theBusinessMethods = theRemoteInterface.getMethods();

        System.out.println("The remote object is " + theRemoteInterface.getName());

      }catch(NoSuchMethodException anException){
        anException.printStackTrace();
      }catch(java.lang.reflect.InvocationTargetException anException){
        anException.printStackTrace();
      }catch(IllegalAccessException anException){
        anException.printStackTrace();
      }

    }

  }

  private NamingEnumeration getNames(Context aContext, String aName) throws NamingException{
    NamingEnumeration theNames;

    theNames = aContext.list(aName);

    return theNames;
  }

 
 I hope that this helped so far

Cheers

Lorenzo


Rajesh Vilasrao Bhujbal wrote:
hi,
i saw  your mail in JBoss-user list.
 
I am also trying to do same thing. I am sending reuest to queue through session EJB. MDB listen to quque and then calls business EJB. Business Beans are not known to MDB before hand. 
 
Can we call business EJB in such fashion? if yes, how?
 
 
Rajesh 
 
 
 
============
 
Hi Michael,

Yes, i am trying to "discover" EJB's on servers, lookup their home-interfaces and maybe create one or more bean-instances,  in order to register then in a sort of "application-registry" together with other non-EJB java applications.

Lorenzo

Maraya Michael wrote:
[EMAIL PROTECTED]">
	If I understand what you're saying, I think you're trying to access
EJBs without knowing what their names and home and remote interfaces are at
compile-time by using reflection at run-time. Is this what you're trying to
do?

---
Michael R. Maraya


----------
From: Lorenzo Resta[
SMTP:[EMAIL PROTECTED]]
Reply To:
[EMAIL PROTECTED]
Sent: Thursday, July 19, 2001 12:20 PM
To:
[EMAIL PROTECTED]
Subject: Re: [JBoss-user] Classnames in JNDI

Hi Burkhard,

The problem is that i don't know the bean's name. The list() method
returns
an enumeration of JNDI names found in the given context. If you have
deployed beans in the context, you
can get at the name and classname through the NameClassPair class.

I have also tried your approach :
home.getEJBMetaData().getHomeInterfaceClass(),
but i still get only classnames like "$Proxy0".

Do you get the real classnames?

Thanks

Lorenzo

Burkhard Vogel wrote:


Hi,
not sure about the return values of list() but you can do:
Object obj = new InitialContext().lookup(BeanName);
EJBHome home =
(EJBHome)javax.rmi.PortableRemoteObject.narrow(obj, EJBHome.class);
log.debug("HomeInterface: " +
home.getEJBMetaData().getHomeInterfaceClass());
Burkhard



Reply via email to