-
1. Re: Unit test EJB3 Exception
wolfgangknauf Mar 25, 2009 8:32 AM (in response to mvpc)Hi,
what does the JNDIView ( http://www.jboss.org/community/docs/DOC-9583 ) display for your bean and for the app client?
According to the message, I would suspect that the JNDI path continues (something like "MyBean/local/somethingmore"), and your lookup is not done on the end node of the path.
Or did you configure the local interface name, which is a reference to something else?
Hope I could help
Wolfgang -
2. Re: Unit test EJB3 Exception
mvpc Mar 25, 2009 8:42 AM (in response to mvpc)I think the problem is not there, because I can get the Reference to MyBean with
ctx.lookup("MyBean/local")
The problem is when i try to narrow this with
MyBeanLocalInterface i = PortableRemoteObject.narrow(ref, MyBean.class)
Propably i'm missing some jar in the classpath. The server i'm using is JBoss.
Thanks for the attention! -
3. Re: Unit test EJB3 Exception
wolfgangknauf Mar 25, 2009 10:46 AM (in response to mvpc)Oops, my bad... Local interfaces can be cast directly:
MyLocal local = (MyLocal) ctx.lookup("MyBean/local");
Probably a "narrow" would even result in error.
By the way, with EJB3, the "narrow" is even for remote interfaces no longer required, direct casting is possible.
And one more thing: a Unit test probably means that you are using a remote application client? Then, shouldn't you use the remote interface?
Best regards
Wolfgang -
4. Re: Unit test EJB3 Exception
mvpc Mar 25, 2009 1:19 PM (in response to mvpc)Hummm I changed the code to:
MyLocal local = (MyLocal)ctx.lookup("MyBean/local");
But I am now getting the exception:
java.lang.ClassCastException: javax.naming.Reference cannot be cast to br.com.original.negocio.email.interfaces.IEmailLocal
Thanks! -
5. Re: Unit test EJB3 Exception
alrubinger Mar 25, 2009 2:22 PM (in response to mvpc)"mvpc" wrote:
java.lang.ClassCastException: javax.naming.Reference cannot be cast to br.com.original.negocio.email.interfaces.IEmailLocal
This is a common symptom that you don't have the proxy object factories on your client CP. Typically this is fixed by ensuring you've got $JBOSS_HOME/client/jbossall-client.jar defined. But I see some other issues.
* Your Unit Test is set up in a different JVM from the container? If so you'll need to lookup a business remote reference (ie. @Remote).
* Don't push local component or local business proxies through PortableRemoteObject.narrow...this is for the EJB 2.x remote home view only.
S,
ALR -
6. Re: Unit test EJB3 Exception
mvpc Mar 25, 2009 3:05 PM (in response to mvpc)I use the same JVM that the EJB is deployed and have added the jbossall-cliente.jar and it doesn't work at all, I get the same exception.
My EJB application is running when i execute the unit test. Is This right ? -
7. Re: Unit test EJB3 Exception
wolfgangknauf Mar 26, 2009 7:34 AM (in response to mvpc)Hi,
do you use JBoss 5? If yes: "jbossall-client.jar" just defines a bunch of classpath entries in its Manifest.mf, so you have to add much more JARs to your classpath (but I cannot tell you, which ones).
And one more thing: as your unit test seems to be a standalone application client, you have to use the REMOTE interface, not the local one (as ALRubinger already told you).
Hope this helps
Wolfgang -
8. Re: Unit test EJB3 Exception
wolfgangknauf Mar 26, 2009 7:40 AM (in response to mvpc)What do you mean with "I use the same JVM..." in your previous post? Same java.exe executable, or same process?
If the latter: how do you start the Unit Tests so that they run inside the container?
Wolfgang -
9. Re: Unit test EJB3 Exception
mvpc Mar 26, 2009 7:50 AM (in response to mvpc)I just meant that i am executing the unit tests on same machine that the EJB is deployed. Really I use JBoss 5 and i think there are lots of jars more to add to classpath. And I have to use local interface, i can't use remote interface in a application that's running locally.
Thanks! I'll search the jars :) -
10. Re: Unit test EJB3 Exception
itsme Mar 26, 2009 7:57 AM (in response to mvpc)In case of an test client startet with an own main method this client runs in fact in a different process then the jboss and your ejbs. In that case you must use the remote interfaces as per the process is remote to the jboss (as already Wolfgang and ALR said).