Skip to main content

Can't seem to look up a env-entry

2 replies [Last post]
whartung
Offline
Joined: 2003-06-13
Points: 0

I have this piece of code:

<br />
        String configFile = null;<br />
        try {<br />
            Context env = (Context) new InitialContext().lookup("java:comp/env");<br />
            configFile = (String) env.lookup("config-path");<br />
        } catch (NamingException ex) {<br />
            Logger.getLogger(TestServlet.class.getName()).log(Level.SEVERE, null, ex);<br />
        }<br />
        return configFile;<br />

I have this in my web.xml.

</p>
<p>        config-path<br />
        java.lang.String<br />
        /hoss-config.xml</p>
<p>

and when I call that code, I get:

javax.naming.NamingException: invocation exception
at com.sun.enterprise.naming.NamingManagerImpl.getComponentId(NamingManagerImpl.java:1332)
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:827)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:396)
at javax.naming.InitialContext.lookup(InitialContext.java:351)

What's most annoying is that this "worked before", and "now it doesn't". :-/

Any hints? (Source was no help, it's just telling me that there's "no container context", which doesn't explain WHY there is no container context).

Anyway, GFv2r2 Windows JDK 5.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Amy Roh

webtier@javadesktop.org wrote:
> I have this piece of code:
> [code]
> String configFile = null;
> try {
> Context env = (Context) new InitialContext().lookup("java:comp/env");
> configFile = (String) env.lookup("config-path");
> } catch (NamingException ex) {
> Logger.getLogger(TestServlet.class.getName()).log(Level.SEVERE, null, ex);
> }
> return configFile;
> [/code]

Does this work?

javax.naming.Context initCtx = new javax.naming.InitialContext();
initCtx.lookup("java:comp/env/config-path");

>
> I have this in my web.xml.
>
> [code]
>
> config-path
> java.lang.String
> /hoss-config.xml
>

> [/code]
>
> and when I call that code, I get:
>
> javax.naming.NamingException: invocation exception
> at com.sun.enterprise.naming.NamingManagerImpl.getComponentId(NamingManagerImpl.java:1332)
> at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:827)
> at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
> at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:396)
> at javax.naming.InitialContext.lookup(InitialContext.java:351)
>
> What's most annoying is that this "worked before", and "now it doesn't". :-/
>
> Any hints? (Source was no help, it's just telling me that there's "no container context", which doesn't explain WHY there is no container context).
>
> Anyway, GFv2r2 Windows JDK 5.
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=315363
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

whartung
Offline
Joined: 2003-06-13
Points: 0

Hi Amy,

Thanx.

That didn't work. But now I know why.

The problem was that this DID work before, and now it doesn't. The key difference is that now, even those this code is running within the Servlet tier, the call I am making is coming from JMX. When I was making the call before, it was from a servlet.

So, the container JNDI environment isn't set up properly when I make a JMX call in to the container via an application registered MBean.

(Which is an important detail to know -- that means no EJB calls from my JMX MBeans, unless someone has a hint regarding that...)

But thank you for the quick response.