1

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 {
    ....    
}
Community
  • 1
  • 1
user2611714
  • 123
  • 2
  • 9
  • @ user2611714 : initialize your Bin variable with `null` and than try. it should work. – HP's 411 Apr 22 '15 at 08:56
  • Ok, i tried. Now it fails with the exception: javax.naming.NameNotFoundException: Name [global/My-ear/My-ejb-1.0/MyBean] is not bound in this Context. Unable to find [global]. at org.apache.naming.NamingContext.lookup(NamingContext.java:818) at org.apache.naming.NamingContext.lookup(NamingContext.java:166) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157) at javax.naming.InitialContext.lookup(InitialContext.java:411) .... – user2611714 Apr 22 '15 at 09:13
  • @ user2611714 : Now, this error want to tell that, your `MyBean` is not accessible in this scope, Still you are missing something, will show full Code? – HP's 411 Apr 22 '15 at 10:37
  • Please, see update. What else should I show? – user2611714 Apr 22 '15 at 10:51

1 Answers1

0

There is missing of IntialContext class, you should have to try this in Your Bin.java while you initializing your Bin with host, port.

  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);
HP's 411
  • 483
  • 1
  • 9
  • 21
  • I've implemented your sample code and got the following error: javax.naming.NameNotFoundException: Name [IMyInterface] is not bound in this Context. Unable to find [IMyInterface]. – user2611714 Apr 23 '15 at 08:39