ClassCastException when obtaining a Remote Interface from th
jjmargon Apr 21, 2005 4:36 AMHi.
First of all, I'm using JBoss 4.0.1 and Eclipse 3.0.1M6 with MyEclipse.
I've deployed a Stateless Session Bean in the server and it's ok. In fact, when I see the jmx-console in the JNDI view I can see the values for the EJB deployed.
The issue is that when I try to access the EJB through a client (in my case a JUnit Test Case class, but also I've tried with a standalone application), always I get a ClassCastException.
The method of the client code I'm calling is:
public void testClientEJB(){ Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); props.put(Context.PROVIDER_URL, "localhost:3332"); try{ InitialContext ctx = new InitialContext(props); assertTrue(ctx!=null); Object ref = ctx.lookup("ejb/HelloWorld"); System.out.println("Got a reference to the EJB"); HelloWorldHome pruebaHome = (HelloWorldHome) PortableRemoteObject.narrow(ref,HelloWorldHome.class); assertTrue(pruebaHome!=null); HelloWorld pruebaServer = (HelloWorld) pruebaHome.create(); System.out.println(pruebaServer.execute()); }catch (Exception e){ e.printStackTrace(); } }
And the console output is:
Got a reference to the EJB java.lang.ClassCastException at client.HelloWorldClientTest.testClientEJB(HelloWorldClientTest.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Note: The line 29 in testClient is when I try to obtain the Remote Interface from the create method of the home interface,i.e.,
HelloWorld pruebaServer = (HelloWorld) pruebaHome.create();
Of course, I have in the classpath client the jbossall-client.jar
I've had the Eclipse EJB Project linked as a Project required on the build path (to make the interfaces classes available to the application) and the error was there.
I've tried to export a jar with the classes of the EJB and include this jar in the classpath of the application and the error continued there.
Someone has experienced this kind of error?
Thanks a lot