Is it possible to invoke multiple Session beans from one Session bean using Reflection

Showing Answers 1 - 4 of 4 Answers

Raja Seklhar reddy T

  • Sep 11th, 2005
 

You use reflection when you actually instantiate the objects or invoke the method.
In the EJB Scenario Beans invoke other Beans as clients. The client only looks up the objects (not instantiating) and the operations are invoked on the stubs only.

InitialContext ctx = new InitialContext();Object value = ctx.lookup(BEAN_JNDI_NAME);EJBHome ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(value, EJBHome.class);EJBMetaData metaData = ejbHome.getEJBMetaData();Class homeClass = metaData.getHomeInterfaceClass();Class remoteClass = metaData.getRemoteInterfaceClass();// add this line, so you get an object of the home interface typeejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(ejbHome, homeClass);// create the remote objectMethod methodCreate = homeClass.getDeclaredMethod("create", null);//Call a method on the remote interfaceEJBObject remoteObj = (EJBObject)methodCreate.invoke(ejbHome, null);Method methodGet = remoteClass.getDeclaredMethod(METHOD_NAME, params);

  Was this answer useful?  Yes

rajeev

  • May 31st, 2007
 

It is possible. But J2ee spec restricts the use of certain api's for eg Reflection, io,etc.
;)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions