dev@glassfish.java.net

Re: Major problem with JNDI at webapp start

From: Lilianne E. Blaze <lilianne_blaze_at_tlen.pl>
Date: Sun, 14 Oct 2007 06:08:10 +0200

Hello,
Well, thanks for help anyway, and for pointing me to that 2.3.2.2.

Peter Williams wrote:
> 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.
I have a custom log4j initialization which has to pull a couple of
things from jndi. That means absurdillion of "[static ]private Log log =
" everywhere - not only in my code, obviously - first of which will
trigger the custom initialization and therefore the problem. No matter,
I'll try two-stage initialization, I already have a pretty good idea how
to do it. Shame about a whole workday wasted on this though.

Greetings, Lilianne E. Blaze