我在Tomcat上的grails应用程序尝试调用GlassFish上的远程EJB
RemoteService.groovy
class RemoteService {
static transactional = false
static Bin bin;
public ICallCenter getAction() throws NamingException {
if (bin == null) {
bin = new Bin("127.0.0.1","3700") // local!
}
try{
return (IMyInterface)((bin.getInitialContext()).lookup("java:global/My-ear/My-ejb-1.0/MyBean"))
} catch (java.rmi.MarshalException e){
...
}
}
}
Bin.java
public class Bin {
private Properties props = new Properties();
public Bin(String host, String port) {
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", host);
props.setProperty("org.omg.CORBA.ORBInitialPort", port);
}
public InitialContext getInitialContext() throws NamingException {
return new InitialContext(props);
}
}
但它失败,但例外:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.IllegalStateException: No generator was provided and there is no default generator registered]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at my.pckg.web.service.Bin.getInitialContext(Bin.java:21)
at my.pckg.web.service.RemoteService.getAction(RemoteService.groovy:42)
at my.pckg.web.SecuredBaseController.isWorkSessionActive(SecuredBaseController.groovy:34)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: No generator was provided and there is no default generator registered
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:226)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:202)
at org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:187)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.newServiceLocator(AbstractModulesRegistryImpl.java:142)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:218)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:224)
at com.sun.enterprise.module.single.StaticModulesRegistry.createServiceLocator(StaticModulesRegistry.java:91)
at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:102)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.<init>(SerialInitContextFactory.java:130)
at com.sun.enterprise.naming.SerialInitContextFactory.<init>(SerialInitContextFactory.java:62)
at java.lang.Class.newInstance(Class.java:379)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 9 more
根据问题Error while using jersey-client in osgi - No generator was provided,我复制了 hk2-api.jar , hk2-locator.jar , hk2-utils.jar < / strong>, javax-inject.jar , jersey-guava-2.6.jar 到tomcat / lib。但它没有帮助。 出了什么问题?
UPD: 在glassfish(位于同一主机上),我们有
@Remote
public interface IMyInterface {
...
}
@Remote(IMyInterface .class)
@TransactionManagement(TransactionManagementType.BEAN)
@Stateless(mappedName = "MyBean")
public class MyBean implements IMyInterface {
....
}
答案 0 :(得分:0)
缺少IntialContext
课程,您应该在使用Bin
初始化host, port
时在 Bin.java 中尝试此操作。
props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);
SimpleBean bean = (SimpleBean) ctx.lookup(SimpleBean.class.getName());
String result = bean.sayHello("Daniel Suarez Jabonete");
oPrintWriter.println(result);