dev@glassfish.java.net

Re: Major problem with JNDI at webapp start

From: Peter Williams <Pete.Williams_at_Sun.COM>
Date: Sat, 13 Oct 2007 20:41:14 -0700

Hi Lilianne,

The code you posted creates an instance of TestJndi as a member of the
Filter, thus that class is loaded (and static initializers invoked and
InitialContext accessed) before Filter.init() (in fact, before the
Filter class itself is even loaded I believe) and that is the problem.

Lilianne E. Blaze wrote:
> As you see, doTest() gets called twice, first from line marked "*",
> second from within Filter.init. On Tomcat both tests succeed. On
> Glassfish first one fails, second succeeds.
>
> SRV 2.3.2.2? You mean this: "SRV.2.3.2.2 Tool Considerations
> The triggering of static initialization methods when a tool loads and
> introspects a
> web application is to be distinguished from the calling of the init
> method. Developers
> should not assume a servlet is in an active container runtime until the init
> method of the Servlet interface is called. For example, a servlet should
> not try to
> establish connections to databases or Enterprise JavaBeans™ containers
> when only
> static (class) initialization methods have been invoked."?
>
> Well, that would explain it. Swell.
>
> Is there anything that can be done about it?
>
Either use Tomcat (but be aware that this code is not spec compliant and
thus non-portable, possibly even to later versions of Tomcat) or find a
different design that doesn't rely on this. I'm not sure what you are
trying to accomplish so I don't have any useful suggestions. What you
have described seems very fragile to me though.

-Peter

> Greetings, Lilianne E. Blaze
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>