on 07-10-2011 10:02 PM
Hi,
I try to call EJB module in A.ear from Servlet in another EAR file(B.ear) the ClassCastException returned on the context.lookup() code . So when i create a Dynamic Web Project(With the same code as Servlet in B.ear) and pack it in A.ear(The same EAR file with EJB module), it work fine. I have no idea. Could you please suggest me.
The ClassCastException : incompatible with interface ..... return on
HelloManBeanLocalHome home=(HelloManBeanLocalHome) ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");
The entire code is below :
try {
InitialContext ctx=new InitialContext();
HelloManBeanLocalHome home=(HelloManBeanLocalHome) ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");
HelloManBeanLocal remote=home.create();
lookupText=remote.helloMan("Test");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace(out);
}
Many Thanks
Hi Thongie,
Could you please bulid and redploy the two ear files. First bulid and deploy the A.ear file.
Then add the reference of A.ear to your B.ear, build the B.ear and deploy it and check.
If this doesn't work please look at this links
http://wiki.sdn.sap.com/wiki/display/XI/SapNetweaverProcessIntegration.CallEjb3.0methodfromJavaclassmappingPI7.1
Hope this helps you.
Regards,
Saleem Mohammad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saleem Mohammad.
Thank a lot for your post. I got this idea from your link. The below code work fine.
try {
InitialContext ctx=new InitialContext();
Object obj= ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");
ClassLoader homeCl = obj.getClass().getClassLoader();
Class<?> localHome = homeCl.loadClass(HelloManBeanLocalHome.class.getCanonicalName());
java.lang.reflect.Method method = localHome.getMethod("create");
Object homeObj = (Object)method.invoke(obj);
ClassLoader localCl=homeObj.getClass().getClassLoader();
Class<?> local = localCl.loadClass(HelloManBeanLocal.class.getCanonicalName());
Class args[] = {String.class};
java.lang.reflect.Method localMethod=local.getMethod("helloMan",args);
Object params[]={"Thongie"};
Object localObj = (Object)localMethod.invoke(homeObj,params);
lookupText=(String)localObj;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace(out);
}
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.