This content has been marked as final.
Show 4 replies
-
1. Re: how to read EJB- and Home- Interface from EJB
tom140978 Jan 25, 2004 5:47 PM (in response to tom140978)
can i read ejb-informations about "", , etc... with simply jndi lookup function??? With "env-entry" it's work!
should be:
can i read ejb-informations about "home","remote","description" , etc... with simply jndi lookup function??? With "env-entry" it's work!
the corrected ejb-jar.xml file is:(...) <description.>EJB that generates IDs for all</description> <display-name>IDGen EJB</display-name> <ejb-name>IDGen</ejb-name> <home.>idgen.interfaces.IDGenHome</home> <remote.>idgen.interfaces.IDGen</remote> <ejb-class >idgen.ejb.IDGenBean</ejb-class> <session-type >Stateless</session-type> <transaction-type >Container</transaction-type> (...)
-
2. Re: how to read EJB- and Home- Interface from EJB
juha Jan 26, 2004 2:54 PM (in response to tom140978)EJBHome.getEJBMetaData().getHomeInterfaceClass();
EJBHome.getEJBMetaData().getRemoteInterfaceClass(); -
3. Re: how to read EJB- and Home- Interface from EJB
tom140978 Jan 26, 2004 6:45 PM (in response to tom140978)Thanks @juha! It's works!
It's very compact solution, I like it!
I have searched 4 days for this solution!
the code work now:String ejbName = "ejbs/idgen/IDGen"; String funcName = "generate"; Object[] params = new Object[]{}; Class[] paramsClasses = new Class[]{}; try{ Context context = new InitialContext(); Object ref = context.lookup(ejbName); javax.ejb.EJBHome homeObject = (javax.ejb.EJBHome)PortableRemoteObject.narrow(ref, javax.ejb.EJBHome.class); Method createMethod = homeObject.getEJBMetaData().getHomeInterfaceClass().getMethod("create", new Class[]{}); EJBObject ejbObject = (EJBObject)createMethod.invoke(homeObject, new Object[]{}); Method generateMethod = homeObject.getEJBMetaData().getRemoteInterfaceClass().getMethod(funcName, paramsClasses); value = generateMethod.invoke(ejbObject, params); } catch (Exception e){ e.printStackTrace(); }
I founded today (before I readed your message) other possiblity. But it's more Difficulty to write (the part of code, come from JNDIView.java)...InitialContext ic = new InitialContext(); RMIAdaptor server = (RMIAdaptor)ic.lookup("jmx/rmi/RMIAdaptor"); ObjectName name = new ObjectName("jboss.j2ee:module=IDGenEJB.jar,service=EjbModule"); Collection containers = (Collection)server.getAttribute(name, "Containers"); for (Iterator iter = containers.iterator(); iter.hasNext();) { Container con = (Container) iter.next(); Thread.currentThread().setContextClassLoader(con.getClassLoader()); // String System.out.println(" + home:" + con.getBeanMetaData().getHome()); System.out.println(" + remote:" + con.getBeanMetaData().getRemote()); System.out.println(" + ejbClass:" + con.getBeanMetaData().getEjbClass()); }
One Question is very important for me too:
How can I become "description" information from ejb-jar.xml? I try to create an ejb browser tool and need this information for every deployed ejb...
If it's not possible to do, why informations like "description" are saved in ejb-jar.xml???
thanks!
Tom -
4. Re: how to read EJB- and Home- Interface from EJB
juha Jan 27, 2004 7:09 AM (in response to tom140978)For additional information like the descriptions you need to go through the proprietary API of the container, these are not exposed as part of standard J2EE APIs.
An example of this is the code snippet you already posted, con.getBeanMetaData().getXXX().
It is also a possibility that some of this is exposed through the JSR-77 spec MBeans. I'm not familiar with all the details these MBeans expose, so you'd have to check that spec yourself.