cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.ClassCastException

Former Member
0 Kudos

I was following the sample car rental appplication with some minor modification, but encountered error as below, any help would be appreciated:

java.rmi.RemoteException: com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method test.

at TestObjectImpl0.test(TestObjectImpl0.java:202)

at TestObjectImpl0p4_Skel.dispatch(TestObjectImpl0p4_Skel.java:194)

at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:294)

at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:183)

at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:119)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)

Caused by: java.lang.ClassCastException

at TestBean.test(testBean.java:97)

at testObjectImpl0.test(TestObjectImpl0.java:186)

... 10 more

; nested exception is:

java.lang.ClassCastException

at com.sap.engine.services.ejb.exceptions.BaseRemoteException.writeReplace(BaseRemoteException.java:276)

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 java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:896)

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.services.rmi_p4.DispatchImpl.throwException(DispatchImpl.java:135)

at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:296)

at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:183)

at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:119)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

Remote Standalone Client side:

Properties env = new Properties();

env.put ( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl") ;

env.setProperty( javax.naming.Context.PROVIDER_URL, "host:port");

Context ic = new InitialContext(env);

TestHome home = (TestHome)ic.lookup("Test);

Test test = home.create();

String result = test.callService("param1", "param2", "param3", "param4");

Stateless Bean business logic:

private TestEntityLocalHome testHome;

public String test(String param1, String param2, String param3, String param4){

try{

Context ctx = new InitialContext();

// HERE'S THE ERROR BEGIN

testHome = (TestEntityLocalHome) ctx.lookup("TestEntity"); //JNDI

smsOutLocal = testHome.create(param1, param2, param3, param4, param5, param6, param7, param8);

}catch(NamingException e){

e.printStackTrace();

}

catch (CreateException e) {

e.printStackTrace();

}

}

Entity Bean:

public String ejbCreate(String param1, String param2, String param3, String param4, String param5, String param6, String param7, String param8) throws CreateException {

setparam1(param1);

setparam2(param2);

setDateI3(param3);

setparam4(param2);

setparam5(param5);

setparam6(param6);

setparam7(param7);

setparam8(param8);

return "OK";

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try this explicit type casting..

smsOutLocal = (Local_Interface_Name)testHome.create(param1, param2, param3, param4, param5, param6, param7, param8);

where smsOutLocal is instance of Local_Interface_Name.

Regards,

Uma

Answers (2)

Answers (2)

Former Member
0 Kudos

ClassCastException happened in this test method, which is to create a entity bean to store the data pass by remote standalone client. Is my way of lookup and creating the entity bean correct?

Stateless Bean business logic:

private TestEntityLocalHome testHome;

public String test(String param1, String param2, String param3, String param4){

try{

Context ctx = new InitialContext();

// HERE'S THE ERROR BEGIN

testHome = (TestEntityLocalHome) ctx.lookup("TestEntity"); //JNDI

smsOutLocal = testHome.create(param1, param2, param3, param4, param5, param6, param7, param8);

}catch(NamingException e){

e.printStackTrace();

}

catch (CreateException e) {

e.printStackTrace();

}

Former Member
0 Kudos

Hi Julius,

you have a ClassCastException in line 97 in the class testBean. What is your code in this line??

Btw, to lookup a bean remotely use:

MyExampleHome myExampleHome = (MyExampleHome)

javax.rmi.PortableRemoteObject.narrow(ctx.lookup(“sap.com/MyE

AR/MyExampleBean”), MyExampleHome.class);