users@glassfish.java.net

how to do JNDI lookups from LifeCycle modules

From: <glassfish_at_javadesktop.org>
Date: Sun, 09 Sep 2007 22:32:22 PDT

I want to look up an EJB from a lifecycle module. I tried this:

    public void handleEvent(LifecycleEvent event) throws ServerLifecycleException {
        if (event.getEventType() == event.READY_EVENT) {
            Context ctx = event.getLifecycleEventContext().getInitialContext();
                   Object hello = (Object) ctx.lookup("java:comp/env/ejb/Hello");

But it returns a NullPointerException wrapped in a NameNotFoundException.

Where can I find information about how to do JNDI lookups from lifecycle modules? I could not find any information about whether to look under "java:comp" or use "ejb/Hello" directly. And can I map this to a global JNDI name somehow?

Also, why the NPE? Should I open a bug report?

The stacktrace is:
javax.naming.NameNotFoundException: No object bound for java:comp/env/ejb/Hello [Root exception is java.lang.NullPointerException]
        at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:224)
        at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:337)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at examples.lifecycle.EJBAccessor.handleEvent(EJBAccessor.java:24)
        at com.sun.appserv.server.ServerLifecycleModule.postEvent(ServerLifecycleModule.java:223)
        at com.sun.appserv.server.ServerLifecycleModule.onReady(ServerLifecycleModule.java:269)
        at com.sun.appserv.server.LifecycleModuleService$onReadyCaller.doRun(LifecycleModuleService.java:295)
        at com.sun.appserv.management.util.misc.RunnableBase.runSync(RunnableBase.java:296)
        at com.sun.appserv.management.util.misc.RunnableBase._submit(RunnableBase.java:168)
        at com.sun.appserv.management.util.misc.RunnableBase.submit(RunnableBase.java:202)
        at com.sun.appserv.server.LifecycleModuleService.callAllModules(LifecycleModuleService.java:346)
        at com.sun.appserv.server.LifecycleModuleService.onReady(LifecycleModuleService.java:478)
        at com.sun.enterprise.server.ApplicationServer.onReady(ApplicationServer.java:526)
        at com.sun.enterprise.server.PEMain.run(PEMain.java:413)
        at com.sun.enterprise.server.PEMain.main(PEMain.java:338)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.sun.enterprise.server.PELaunch.main(PELaunch.java:412)
Caused by: java.lang.NullPointerException
        at com.sun.enterprise.naming.NamingManagerImpl.getComponentId(NamingManagerImpl.java:1330)
        at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:827)
        at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
        ... 19 more
[Message sent by forum member 'dkoper' (dkoper)]

http://forums.java.net/jive/thread.jspa?messageID=234610