Jboss(6.4 EAP)到WebSphere(7.x)

时间:2016-05-13 18:21:37

标签: java java-ee jboss ejb websphere

我正在尝试从Jboss(6.4 EAP)到WebSphere(7.x)进行EJB调用。 我有一个从WebSphere(WAS)到WAS的工作示例,但是,相同的位置和查找名称返回名称未找到异常。我目前在作为WAR部署到Jboss的Web应用程序中进行此测试。

我没有在web.xml中定义EJB,也没有在jboss-web.xml中定义(我不相信我需要它)。 WebSphere中的EJB版本是2.1。

Properties env = new Properties();
env.put(Context.PROVIDER_URL, "corbaloc::example.test.com:11000");
InitialContext ctx = new InitialContext(env);
Object obj= ctx.lookup("cell/clusters/MyEJBHome12Cluster/MyEJBHome");

上面引发了NameNotFoundException:

javax.naming.NameNotFoundException: cell/clusters/MyEJBHome12Cluster/MyEJBHome -- service jboss.naming.context.java.cell.clusters."MyEJBHome12Cluster"."MyEJBHome"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
    at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:243)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.test.ejbClient.getRemoteConnection(ejbClient.java:192)
    at com.test.ejbClient.runIt(ejbClient.java:77)
    at com.test.TestRemoteEJB.doGet(TestRemoteEJB.java:59)

我也尝试使用sun工厂:com.sun.jndi.cosnaming.CNCtxFactory

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");

产生了类似的结果:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
    at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:61)
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:502)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:541)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:519)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.test.ejbClient.getRemoteConnection(ejbClient.java:192)
    at com.test.ejbClient.runIt(ejbClient.java:77)
    at com.test.TestRemoteEJB.doGet(TestRemoteEJB.java:59)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
    at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
    at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:251)
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:488)

尝试使用以下网站进行上述操作:Reference Link First

然后我尝试使用IBM客户端jar,只是为了看看我是否可以接到工作电话。我关注了这个网站:Reference Link 2

我添加了2个罐子:

  • com.ibm.ws.ejb.thinclient_8.5.0.jar
  • com.ibm.ws.orb_8.5.0.jar

我还添加了包含EJB类和存根类的所有jar。我使用了com.ibm.websphere.naming.WsnInitialContextFactory的工厂。它查找EJB很好,但在PortableRemoteObject.narrow调用期间,它失败并带有

java.lang.ClassCastException: com.test._MyEJBHome_Stub cannot be cast to org.omg.CORBA.Object

我怀疑我是否能够使用WAS jar,因为我必须运行Java 1.8,它不能使用我上面的客户端jar,也不喜欢在JBoss中使用IBM jar当Jboss能够做到这一点时。

1 个答案:

答案 0 :(得分:1)

我们最终找到了解决此问题的方法。 JBoss的查找中需要有一组神奇的字符。以前,提供程序URL和JNDI是分开的。现在,它们都在查找字符串中,如下所示。此外,没有其他参数添加到InitialContext。

InitialContext ctx = new InitialContext(); // no need to add anything to the context

// A few reminders about the below:
// 1. For multiple hosts, separate with commas, i.e. "corbaname::@<server:port>,:@<server2:port2>"
// 2. If periods are used in the lookup name, they must be escaped, i.e. MyEJBHome-1.0 needs to be MyEJBHome-1\.0
Object obj= ctx.lookup("corbaname::@example.test.com:11000/NameServiceServerRoot#cell/clusters/MyEJBHome12Cluster/MyEJBHome");

// Normal EJB things below
MyEJBHome home = (MyEJBHome) javax.rmi.PortableRemoteObject.narrow(obj, MyEJBHome.class);
MyEJB myEJB = home.create();