繁体   English   中英

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的有效示例,但是,相同的位置和查找名称返回一个名称未找到异常。 我目前正在作为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)

使用以下站点尝试了上述操作: 首先参考链接

然后,我尝试使用IBM客户端jar,以查看是否可以接到电话来工作。 我关注了这个网站: 参考链接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 jars,因为我必须在Java 1.8上运行,因此无法与上面的客户端jars一起使用,或者当Jboss应该能够在JBoss内部使用IBM jars时,我也不喜欢去做这个。

我们最终找到了解决该问题的方法。 在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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM