-
1. Re: Dynamically accessing EJB at runtime
adrian.brock May 21, 2004 5:34 AM (in response to johanwa)Moved to the users forum along with your other post. Can you not read the warning
at the top of the forum?
Anyway, this was fixed in 3.2.4RC1 - something you would have discovered had you
used search. -
2. Re: Dynamically accessing EJB at runtime
johanwa May 21, 2004 5:45 AM (in response to johanwa)Thanks for the reply (about the fix).
Sorry to be such a bug in your obviously overstressed life. I am new to JBoss and to the forum (any forum for that matter), so once again, sorry for posting in the wrong place or not searching first. But I'm not trying to find excuses, I'm overworked to, so I blame myself for being such a dic, and bringing that out in you. -
3. Re: Dynamically accessing EJB at runtime
adrian.brock May 21, 2004 5:48 AM (in response to johanwa)Actually I posted on the wrong thread (a slip of the mouse :-)
You are in the correct forum, and my response is meant for somebody else. -
4. Re: Dynamically accessing EJB at runtime
adrian.brock May 21, 2004 5:51 AM (in response to johanwa)Your problem is here:
at CallResourcesEjb.main(CallResourcesEjb.java:35)
Where you are trying to do Class.newInstance() on an interface. -
5. Re: Dynamically accessing EJB at runtime
johanwa May 21, 2004 6:08 AM (in response to johanwa)Phew, I was getting a bit nervous on that comment, I'm not all that self asured. But thanks for the nice reply and sorry for my comments.
Code:Context ctx = new InitialContext(env); Object obj = ctx.lookup( "acme/Application" ); ApplicationHome home = (ApplicationHome)PortableRemoteObject.narrow(obj, ApplicationHome.class); Application app = (Application)home.findBaseKey("logon.label"); System.out.println("1. logon.label : " + app.getValue()); app = (Application)home.findKeyByLocale("en_ZA", "logon.label"); System.out.println("2. logon.label : " + app.getValue());Class bcHome = Class.forName("app.resources.ApplicationHome"); Method findBaseKey = bcHome.getMethod("findBaseKey", new Class[] { String.class }); Class bClass = Class.forName("app.resources.Application"); Method getValue = bClass.getMethod("getValue", null); Object boHome; // = bcHome.newInstance(); Object bObject = bClass.newInstance(); boHome = PortableRemoteObject.narrow(obj, bcHome); <-LINE 35 Object[] baseKeyVal = null; baseKeyVal[0] = "logon.label"; bObject = findBaseKey.invoke(boHome, baseKeyVal); System.out.println("3. logon.label : " + getValue.invoke(bObject, null));
And I get:
1. logon.label : Please log on.
2. logon.label : Kom gerus binne
Exception: app.resources.Applicationjava.lang.InstantiationException: app.resources.Application
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at CallResourcesEjb.main(CallResourcesEjb.java:35)
Thanks for the help, I'm quite new to Java and EJB's.
Appreciated. -
6. Re: Dynamically accessing EJB at runtime
adrian.brock May 21, 2004 6:34 AM (in response to johanwa)If it really is line 35, your source code does not match your class file.
This is the line in error:
Object bObject = bClass.newInstance();
Application (bClass) is an interface. -
7. Re: Dynamically accessing EJB at runtime
johanwa May 21, 2004 7:44 AM (in response to johanwa)You clever dog you! Thanks a mil, it works now. Struts can now be EJB enabled thanks to JBoss and the JBoss team. I'll send the complete solution on to the struts team when I'm done, maybe they'll want to publish it.
Thanks again.