Jboss (6.4 EAP) 到 WebSphere (7.x)
Jboss (6.4 EAP) to WebSphere (7.x)
我正在尝试从 Jboss (6.4 EAP) 到 WebSphere (7.x) 进行 EJB 调用。
我有一个从 WebSphere (WAS) 到 WAS 的工作示例,但是,相同的位置和查找名称 returns 找不到名称异常。我目前正在作为 WAR 部署到 Jboss.
的 Web 应用程序内部进行此测试
我没有在 web.xml 和 jboss-web.xml 中定义 EJB(我认为我不需要它)。 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 应该能够做到这一点时,更喜欢在 JBoss 中使用 IBM jar。
我们最终确实找到了解决此问题的方法。在 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();
我正在尝试从 Jboss (6.4 EAP) 到 WebSphere (7.x) 进行 EJB 调用。 我有一个从 WebSphere (WAS) 到 WAS 的工作示例,但是,相同的位置和查找名称 returns 找不到名称异常。我目前正在作为 WAR 部署到 Jboss.
的 Web 应用程序内部进行此测试我没有在 web.xml 和 jboss-web.xml 中定义 EJB(我认为我不需要它)。 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 应该能够做到这一点时,更喜欢在 JBoss 中使用 IBM jar。
我们最终确实找到了解决此问题的方法。在 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();