2012-02-01 165 views
1

我用远程和本地接口创建了EJB。无法访问远程EJB

@Stateless 
public class VendorBean implements VendorBeanLocal, VendorBeanRemote { 

    ... 

} 

@Local 
public interface VendorBeanLocal { 

    ... 

} 

@Remote 
public interface VendorBeanRemote { 

    ... 

} 

有一些方法,而不是点(在这种情况下没有关系)。

然后将其部署到glassfish 3.1。它可以从我的客户端Web应用程序访问(作为战争部署在同一台服务器上)并且工作正常。但是我无法从我的集成测试中访问它。

我写这应该由Maven 2中运行我在GlassFish server.log的看着这个bean的JNDI名称集成测试:

java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote 

,并写了测试。但我始终对查找得到的异常:

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:501) 
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:540) 
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:518) 
    at javax.naming.InitialContext.lookup(InitialContext.java:409) 
    at com.widewebtech.mercury.core.test.ejb.VendorBeanIntegrationTest.manageVendor(VendorBeanIntegrationTest.java:126) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:616) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140) 
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127) 
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:616) 
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345) 
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009) 
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._NamingContextExtStub.resolve(_NamingContextExtStub.java:406) 
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:487) 
    ... 33 more 

测试的代码:

Properties p = new Properties(); 
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"); 
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); 
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 
Context context = new InitialContext(p); 

Object o = context.lookup("java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote"); 

我很困惑。我读过很多文章,尝试了很多建议,但没有任何作用。

我也试着列出测试中的语境:

NamingEnumeration<NameClassPair> list = context.list(""); 
while (list.hasMore()) { 
    NameClassPair ncPair = (NameClassPair) list.next(); 
    System.out.print(ncPair.getName() + " (type "); 
    System.out.println(ncPair.getClassName() + ")"); 
} 

结果:

<package>.VendorBeanRemote__3_x_Internal_RemoteBusinessHome__ (type com.sun.corba.se.impl.corba.CORBAObjectImpl) 
SerialContextProvider (type com.sun.corba.se.impl.corba.CORBAObjectImpl) 
java:global (type com.sun.jndi.cosnaming.CNCtx) 
INITIAL_GIS (type com.sun.corba.se.impl.corba.CORBAObjectImpl) 

所以,看起来像在上下文豆。

我做错了什么?请帮忙!

回答

1

最终我设法解决了这个问题。所以,代码是:

Properties p = new Properties(); 
p.setProperty(Context.PROVIDER_URL, "corbaname:iiop:localhost:3700"); 
context = new InitialContext(p); 

VendorBeanRemote vendorBean = (VendorBeanRemote) context.lookup("java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote"); 

重要的是,gf-client.jar必须在类路径中。它可以从 glassfish lib目录中获取。

+2

它的工作原理也没有提供任何属性,因为您已经声明的属性是默认值。 – 2012-02-02 16:53:08

+1

使用应用程序客户端容器(appclient)或利用Java Web Start也可能对此用例有用。 – vkraemer 2012-02-03 03:00:58

0

如果有人在glassfish上的两台不同主机之间进行远程EJB调用,除了上面说的例外: 将您的orb-listener-1网络地址设置为您的IP。 (配置中的ORB/IIOP监听器部分)