I created a bean object and encountered this error at run time,
java.lang.ClassCastException at
com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source) at
javax.rmi.PortableRemoteObject.narrow(Unknown Source) at Client_TestPortal.main Client_TestPortal.java:71) Caused by:
java.lang.ClassCastException: javax.naming.Reference ... 3 more
How to create bean object in my client? I have, a bean Interface, TestPortal
, and a bean class, TestPortalBean
, in an ear, PortalEJB
.
Here is the code, I am using to create EJB instance in client,
String sEjbRemote = "PortalEJB/TestPortalBean/remote";
Properties pProp = new Properties();
pProp.put("java.naming.factory.initial",sInitCtxtCls);
pProp.put("java.naming.provider.url", sUrl);
javax.naming.InitialContext initialContext = new InitialContext(pProp);
Object ref = initialContext.lookup(sEjbRemote);
System.out.println("\n\n \t Source :::"+ref.toString());
test.ejb.TestPortal testportal = (test.ejb.TestPortal)PortableRemoteObject.narrow(ref,test.ejb.TestPortal.class);
Object ref = initialContext.lookup(sEjbRemote);
When i print the object in SOP ref.toString();
i got the following information but i am not able to create object for TestPortal which is in the PoratlEJB.ear which is deployed in JBOSS- AS version : Jboss-5.0.1.GA
Source :::Reference Class Name: Proxy for: test.ejb.TestPortal
Type: ProxyFactoryKey Content: ProxyFactory/TestPortalBean/PortalEJB/TestPortalBean/remote Type: EJB Container Name Content: jboss.j2ee:ear=PortalEJB.ear,jar=PortalEJB.jar,name=TestPortalBean,serv ice=EJB3 Type: Proxy Factory is Local Content: false Type: Remote Business Interface Content: test.ejb.TestPortal Type: Remoting Host URL Content: socket://s9458:3973/