Interesting. The discovery of the methods on the home and object is identical to what I was doing by doing so with a custom class loader, loading the class found via the ejb-jar.xml (in the jar file I had), etc. Same data. But... different classloaders.
I'm not convinced that you *have to have* the jar file for those classes in your path. At least, they're not in my test client. By using getEJBMetaData and finding the method I want to call via that data, it works great. Both for the create method on the home and for a method on an object created from the create method. I think it's clear that there must be some dynamic class loading going on. Regardless, your hints helped. Using the EJBMetaData for getting to the reflection objects was the big trick in this case (for me). Thanks, Joel ----- Original Message ----- From: <[EMAIL PROTECTED]> To: "Joel Riedesel" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, September 05, 2002 4:24 AM Subject: Re: [EJB-INT] Reflection and EJB lookups? > Joel, > assuming the following breakdown of the problem is correct, then my > answer is below: > > Requirements: > 1. Dynamic discovery of EJB Homes on a server. > 2. Dynamic discovery of create methods on EJBHomes. > 3. Calling of create methods from 2. > 4. Dynamic discovery of methods on EJBObjects created by 3. > 5. Calling of methods from 4. > > Assumptions: > 1. You have some access to the EJB jar files which have been deployed on a > server. > 2. You are in control of running the client app which will perform the > discovery of beans. > > > Joel, > For dynamic discovery of EJBs I think you will find JNDI is the most > elegant way of achieving this using a listBindings() on a particular > named context. This will allow you to enumerate all the elements which > have been bound within that context and perform a check to see if any of > the bound objects is an instanceof EJBHome. The object can then be cast to a type EJBHome and the method > getEJBMetaData() called to retrieve an EJBMetaData object which describes > this bean. Call the method getHomeInterfaceClass() to retrieve the actual > Home interface 'Clazz object' then use reflection on this interface to > discover the different create methods available. Prior to invoking a > create method, call getRemoteInterfaceClass on the EJBMetaData object to > get the beans remote interface and reflection can be used to discover the > various methods available. You can now invoke one of the create methods on > the home object to retrieve an EJBObject for which you now have a complete > method list. You can then invoke methods as required on the object. > > NOTE: For dynamic discovery and calling of methods you will somehow HAVE > TO HAVE the Home and Remote interfaces on the client classpath and, if > your server does not provide dynamic stub downloading, the stub for the > bean aswell. Now taking into account assumptions 1 & 2 above then you > could dynamically add all jars in the deployment directory of the relevant > EJB server to your classpath using a script which runs your client > application. Other than that, Im not sure how you could do this in a > generic way. > > > Duncan Alexander =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
