Hi,
I practice to code EJB 2.0 but the error show on the context.lookup("JNDI").
I code the below for Java standalone to call EJB it work fine Hashtable jndiContextProp = new Hashtable(); jndiContextProp.put(Context.PROVIDER_URL, "ln5362-288:50004"); jndiContextProp.put(Context.SECURITY_PRINCIPAL, "Administrator"); jndiContextProp.put(Context.SECURITY_CREDENTIALS, "admin123"); jndiContextProp.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl"); try { InitialContext ctx=new InitialContext(jndiContextProp); sayHelloHome home=(sayHelloHome) ctx.lookup("HelloWorldBeanJNDI"); sayHelloRemote remote=home.create(); System.out.println(remote.sayHello("Test")); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }
but i code the below on servlet to call EJB the error occur.
try { InitialContext ctx=new InitialContext(); sayHelloLocalHome home=(sayHelloLocalHome) ctx.lookup("localejbs/HelloWorldBeanJNDI"); sayHelloLocal remote=home.create(); System.out.println(remote.sayHello("Test"));
} catch (Exception e) { // TODO: handle exception e.printStackTrace(out); }
The error state that java.lang.ClassCastException : incompatible with interface on 'sayHelloLocalHome home=(sayHelloLocalHome) ctx.lookup("localejbs/HelloWorldBeanJNDI");'
Below is the error trace : java.lang.ClassCastException: class
$Proxy616:sap.com/HelloWorld_EAR@com.sap.engine.boot.loader.ResourceMultiParentClassLoader@1bc3150@alive incompatible with interface ejb.sayHelloLocalHome:sap.com/Servlet_Exc_EAR@com.sap.engine.boot.loader.ResourceMultiParentClassLoader@7101cd@alive at sap.trianing.Servlet_Exc_WEB.doGet(Servlet_Exc_WEB.java:43) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
Pleased help.