Testing Can';t访问远程EJB
我已经创建了带有远程和本地接口的EJBTesting Can';t访问远程EJB,testing,glassfish,ejb-3.0,integration,jndi,Testing,Glassfish,Ejb 3.0,Integration,Jndi,我已经创建了带有远程和本地接口的EJB @Stateless public class VendorBean implements VendorBeanLocal, VendorBeanRemote { ... } @Local public interface VendorBeanLocal { ... } @Remote public interface VendorBeanRemote { ... } 有一些方法可以代替圆点(在这种情况下没关系) 然
@Stateless
public class VendorBean implements VendorBeanLocal, VendorBeanRemote {
...
}
@Local
public interface VendorBeanLocal {
...
}
@Remote
public interface VendorBeanRemote {
...
}
有一些方法可以代替圆点(在这种情况下没关系)
然后将其部署到glassfish 3.1。它可以从我的客户端web应用程序(作为war部署在同一台服务器上)访问,并且运行良好。但我无法通过集成测试访问它
我编写了集成测试,该测试应该由maven 2运行。我在glassfish server.log中查找了这个bean的JNDI名称:
java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote
测试代码:
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");
Properties p=新属性();
p、 setProperty(Context.INITIAL\u Context\u工厂,“com.sun.jndi.cosnaming.CNCtxFactory”);
p、 setProperty(“org.omg.CORBA.ORBInitialHost”、“localhost”);
p、 setProperty(“org.omg.CORBA.ORBInitialPort”,“3700”);
上下文=新的初始上下文(p);
对象o=context.lookup(“java:global//VendorBean!.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() + ")");
}
namingumeration list=context.list(“”);
而(list.hasMore()){
NameClassPair ncPair=(NameClassPair)list.next();
System.out.print(ncPair.getName()+“(类型”);
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)
.VendorBeanRemote\uuuu 3\ux\u Internal\u RemoteBusinessHome\uuuu(键入com.sun.corba.se.impl.corba.CORBAObjectImpl)
SerialContextProvider(类型com.sun.corba.se.impl.corba.CORBAObjectImpl)
java:global(键入com.sun.jndi.cosnaming.CNCtx)
初始地理信息系统(键入com.sun.corba.se.impl.corba.CORBAObjectImpl)
所以,在上下文中看起来像bean
我做错了什么?请帮忙 我终于解决了这个问题。因此,代码是:
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");
Properties p=新属性();
p、 setProperty(Context.PROVIDER_URL,“corbaname:iiop:localhost:3700”);
上下文=新的初始上下文(p);
VendorBeanRemote vendorBean=(VendorBeanRemote)context.lookup(“java:global//vendorBean!.VendorBeanRemote”);
重要的是,gf-client.jar必须在类路径中。它可以从
glassfish lib目录。最终我设法解决了这个问题。因此,代码是:
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");
Properties p=新属性();
p、 setProperty(Context.PROVIDER_URL,“corbaname:iiop:localhost:3700”);
上下文=新的初始上下文(p);
VendorBeanRemote vendorBean=(VendorBeanRemote)context.lookup(“java:global//vendorBean!.VendorBeanRemote”);
重要的是,gf-client.jar必须在类路径中。它可以从
glassfish lib目录。如果有人在glassfish上的两个不同主机之间进行远程EJB调用,上述情况除外:
将您的orb-listener-1网络地址设置为您的IP地址。(配置中的ORB/IIOP listeners部分)如果有人在glassfish上的两个不同主机之间进行远程EJB调用,上述情况除外:
将您的orb-listener-1网络地址设置为您的IP地址。(配置中的ORB/IIOP listeners部分)它也可以在不提供任何属性的情况下工作,正如您所说的是默认值一样。使用app client容器(appclient)或利用Java Web Start也可能对该用例有用。它也可以在不提供任何属性的情况下工作,正如您所说的,这些都是默认值。使用应用程序客户端容器(appclient)或利用Java Web Start也可能对该用例有用。