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 14:53:16 -0700

Are you absolutely sure that the static initializer in this case in not
invoked before the Filter.init() method? Without checking the spec to
be certain, I suspect that InitialContext is not available until
Filter.init() is fired and that in your case something else is loading
this file prematurely. See SRV 2.3.2.2 for a (possibly) related comment
on the use of static initializers.

FWIW, In a small example, I successfully loaded the environment entry
via a static initializer in a class referenced only via a Filter.init()
method. It also worked well in an @Resource injection annotation in the
filter class itself.

-Peter

Lilianne E. Blaze wrote:
> Hello,
> Support of context.xml isn't the problem, at least not at this point, I
> mentioned it because it's part of the target configuration.
>
> The code is in static initializer of a class which can be accessed from
> ContextListener or Filter.init, whichever is called first. Basically
> it's the first thing or one of the first things that get called on
> webapp init.
> Do you want me to write a simple test case? If so, does this list
> accepts attachements (I expect it to be in 10-20kb range)?
>
> Greetings, Lilianne E. Blaze
>
>
>
> Peter Williams wrote:
>
>> sun-web.xml is the server specific descriptor for webapps in
>> Glassfish. Glassfish does not use context.xml in any way.
>>
>> However, sun-web.xml does not provides fields to override env-entry
>> elements from web.xml. I believe the expectation is that you would
>> simply modify web.xml directly if the values needed changing.
>>
>> That said, I tried your example just now using my personal development
>> build of NB6 (roughly equivalent to the current nightly build of same)
>> and it worked flawlessly, no exceptions. The value was read from
>> web.xml exactly as expected.
>>
>> You don't mention where your context code is. Mine was in the
>> processRequest() method of generic NetBeans generated servlet.
>>
>> -Peter
>>
>> Lilianne E. Blaze wrote:
>>
>>> Hello,
>>> I'm using Glassfish b58g, the one provided with Netbeans 6.0b1. It seems
>>> JNDI is unavailable at webapp start.
>>>
>>> I have:
>>> <env-entry>
>>> <env-entry-name>xxx/test</env-entry-name>
>>> <env-entry-type>java.lang.String</env-entry-type>
>>> <env-entry-value>test 2</env-entry-value>
>>> </env-entry>
>>> In web.xml
>>>
>>> And:
>>> <Environment name="xxx/test" type="java.lang.String" value="test4"/>
>>> In /META-INF/context.xml
>>>
>>> Now I'm not sure if Glassfish uses /META-INF/context.xml, I think it
>>> does, but <env-entry> is standard JEE functionality.
>>>
>>> I'm using the following code:
>>> Context initCtx = new InitialContext();
>>> Context envCtx = (Context) initCtx.lookup("java:comp/env");
>>> String value = (String)envCtx.lookup("xxx/test");
>>>
>>> To get the value at webapp start. Obviously, it should get "test 2". I
>>> throws "javax.naming.NameNotFoundException: No object bound" instead.
>>> The same code works flawlessly on Tomcat 6.0.13.
>>>
>>> Changing "xxx/test" to just "test" in all places makes no difference.
>>>
>>> Due to technical requirements I can't use lazy-init here and I do have
>>> to use JNDI. So basically this is a showstopper for me.
>>>
>>> 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
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>