创建一个远程EJB项目,并作为Jar部署在IBM websphere服务器中。 现在,我在本地创建了一个EJB Client项目,并尝试连接为Remote调用。 但它抛出异常:java.lang.ClassCastException
package ejb3.test;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class TestEJBClient {
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties props = new Properties();
props.put(javax.naming.Context.PROVIDER_URL, "iiop://(ip of remote ejb server):2809");
ITestEJBRemoteInterface loEJB = null;
Object lobj;
try {
InitialContext ctx = new InitialContext(props);
System.out.println(ctx.getEnvironment());
lobj = ctx.lookup("ejb3/test/ITestEJBRemoteInterface");// look up of corba
System.out.println("--------" + lobj);
loEJB = (ITestEJBRemoteInterface) PortableRemoteObject.narrow((org.omg.CORBA.Object) lobj, ITestEJBRemoteInterface.class);
String lsName = "Kevin";
// Invoke the Method using bean object ;
System.out.println("Is " + lsName + " present in the list:: " + loEJB.checkNames(lsName));
System.out.println("EJB run successful");
}
catch (NamingException e) {
e.printStackTrace();
}
}
}
{com.ibm.websphere.naming.hostname.normalizer=com.ibm.ws.naming.util.DefaultHostnameNormalizer, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory, com.ibm.websphere.naming.name.syntax=jndi, com.ibm.websphere.naming.namespace.connection=lazy, com.ibm.ws.naming.ldap.ldapinitctxfactory=com.sun.jndi.ldap.LdapCtxFactory, com.ibm.websphere.naming.jndicache.cacheobject=populated, com.ibm.websphere.naming.namespaceroot=defaultroot, com.ibm.ws.naming.wsn.factory.initial=com.ibm.ws.naming.util.WsnInitCtxFactory, com.ibm.websphere.naming.jndicache.maxcachelife=0, com.ibm.websphere.naming.jndicache.maxentrylife=0, com.ibm.ws.naming.wsn.localonly=false, com.ibm.websphere.naming.jndicache.cachename=providerURL, java.naming.provider.url=iiop://10.176.106.207:2809, java.naming.factory.url.pkgs=com.ibm.ws.naming:com.ibm.ws.naming:com.ibm.ws.naming:com.ibm.ws.naming:com.ibm.ws.naming}
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
WARNING: WSVR0072W
Feb 18, 2016 7:39:53 PM null null
INFO: Client code attempting to load security configuration
Feb 18, 2016 7:39:53 PM null null
AUDIT: security.LoadSCI
Feb 18, 2016 7:39:53 PM null null
AUDIT: security.GettingConfig
Feb 18, 2016 7:39:53 PM null null
WARNING: ssl.default.password.in.use.CWPKI0041W
Feb 18, 2016 7:39:53 PM null null
INFO: ssl.disable.url.hostname.verification.CWPKI0027I
Feb 18, 2016 7:39:53 PM null null
AUDIT: security.AuthTarget
Feb 18, 2016 7:39:53 PM null null
AUDIT: security.ClientCSI
--------com.ibm.WsnOptimizedNaming._NamingContextStub:IOR:00bdbdbd0000003149444c3a636f6d2e69626d2f57736e4f7074696d697a65644e616d696e672f4e616d696e67436f6e746578743a312e3000bdbdbd0000000100000000000000f4000102bd0000000a6c6f63616c686f737400238c0000006b4a4d4249000000124773e3aa37643062633737336533616166633334000000240000004749454a500200f76a838007736572766572311a57736e44697374436f734f626a65637441646170746572574c4d00000016434c45564449434d2d3134334e6f6465303143656c6cbd00000007000000010000001400bdbdbd0501000100000000000101000000000049424d0a0000000800bd00011600000100000026000000020002bdbd49424d04000000050005020102bdbdbd0000001f0000000400bd0003000000200000000400bd0001000000250000000400bd0003
Exception in thread "P=592906:O=0:CT" java.lang.ClassCastException: cannot cast class com.ibm.WsnOptimizedNaming._NamingContextStub to interface ejb3.test.ITestEJBRemoteInterface
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:148)
at ejb3.test.TestEJBClient.main(TestEJBClient.java:38)
我怎么能解决这个错误? 任何人都可以分享你的想法。
答案 0 :(得分:0)
ClassCastException - if narrowFrom cannot be cast to narrowTo.
似乎corba.object和itestejbrremoteinterface与继承无关
答案 1 :(得分:0)
dumpNameSpace中的相关行是:
168 (top)/nodes/CLEVDICM-143Node01/servers/server1/ejb3.test.ITestEJBRemoteInterface
168 ejb3.test.ITestEJBRemoteInterface
192 (top)/nodes/CLEVDICM-143Node01/servers/server1/ejb/TestEJB(1)_jar/TestEJB(1).jar/TestEJB#ejb3.test.ITestEJBRemoteInterface
192 ejb3.test.ITestEJBRemoteInterface
服务器上下文的根目录是(top)/nodes/CLEVDICM-143Node01/servers/server1/
,这意味着您应该使用以下字符串之一:
ejb3.test.ITestEJBRemoteInterface
ejb/TestEJB(1)_jar/TestEJB(1).jar/TestEJB#ejb3.test.ITestEJBRemoteInterface