My grails app on Tomcat tries to invoke a remote EJB, which is on GlassFish
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);
}
}
but it fails with the exception:
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
according to the issue Error while using jersey-client in osgi - No generator was provided, I copied hk2-api.jar, hk2-locator.jar, hk2-utils.jar, javax-inject.jar, jersey-guava-2.6.jar to tomcat/lib. But it doesn't help. What's wrong?
UPD: On glassfish (which is on the same host) side, we have
@Remote
public interface IMyInterface {
...
}
@Remote(IMyInterface .class)
@TransactionManagement(TransactionManagementType.BEAN)
@Stateless(mappedName = "MyBean")
public class MyBean implements IMyInterface {
....
}