users@glassfish.java.net

Re: JNDI entries inside application.xml

From: Gustavo Henrique Orair <gustavo.orair_at_gmail.com>
Date: Wed, 1 Feb 2012 11:17:51 -0200

I can't change the scope because it is a constant from logback implementation.

Is there another option available?
---------------------------------------------------------------------------------------------------------------------
                               Gustavo Henrique Orair
 Mestre em Ciência da Computação - MSc in Computer Science
                                    Universidade Federal de Minas Gerais
               Celular/Cell phone:  55-31-85157887
------------------------------------------------------------------------------------------------------------------



2012/1/31 Cheng Fang <cheng.fang_at_oracle.com>:
> Hi Orair,
>
> You will need to use fully qualified and scoped name, since this is an
> application-scoped resource:
>
> <env-entry-name>java:app/env/logback/context-name</env-entry-name>
>
> and Context.lookup("java:app/env/logback/context-name");
>
> -Cheng
>
>
> On 1/31/12 6:28 PM, Gustavo Henrique Orair wrote:
>>
>> Dear,
>> I am trying to enable logback logging separation (see
>> http://logback.qos.ch/manual/loggingSeparation.html).
>>
>> I need to create a logback/context-name resource  in JNDI.
>>
>> I need this environment variable ear scoped (other ears should have
>> different values for this resource), so I included in my
>> application.xml, the content:
>>   <env-entry>
>>     <description>The context name of the logger</description>
>>     <env-entry-name>logback/context-name</env-entry-name>
>>     <env-entry-type>java.lang.String</env-entry-type>
>>     <env-entry-value>app1</env-entry-value>
>>   </env-entry>
>>
>>
>> I am testing if the JNDI resource is available from a listener
>> included in a war inside my ear:
>>
>> public class InitListener implements ServletContextListener {
>>        @Override
>>        public void contextInitialized(ServletContextEvent ce) {
>>                // ch.qos.logback.classic.selector.ContextJNDISelector a;
>>                //
>>                //
>> ch.qos.logback.classic.selector.servlet.ContextDetachingSCL b;
>>
>>                String loggerContextName = null;
>>
>>                try {
>>                        Context ctx = JNDIUtil.getInitialContext();
>>                        loggerContextName = JNDIUtil.lookup(ctx,
>> JNDI_CONTEXT_NAME);
>>                } catch (NamingException ne) {
>>                        System.out.println("WARN: Failed to access the JNDI
>> Server while
>> search for JNDI resource [" + JNDI_CONTEXT_NAME + "].");
>>                }
>>
>>                if (loggerContextName != null) {
>>                        ContextSelector selector =
>> ContextSelectorStaticBinder.getSingleton().getContextSelector();
>>
>>                        LoggerContext context =
>> selector.getLoggerContext(loggerContextName);
>>                        if (context != null) {
>>                                System.out.println("Context named " +
>> loggerContextName + " was found.");
>>                        } else {
>>                                System.out.println("WARN: No context named
>> " + loggerContextName +
>> " was found.");
>>                        }
>>                } else {
>>                        System.out
>>                                        .println("WARN: Failed to get JNDI
>> resource ["
>>                                                        + JNDI_CONTEXT_NAME
>>                                                        + "]. It should
>> exists and define the name of the logger
>> context. See http://logback.qos.ch/manual/loggingSeparation.html for
>> more details.");
>>                }
>>        }
>>
>>        @Override
>>        public void contextDestroyed(ServletContextEvent ce) {
>>                // do nothing
>>        }
>>
>>
>> In server.log I can see the message:
>> WARN: Failed to get JNDI resource
>> [java:comp/env/logback/context-name]. It should exists and define the
>> name of the logger context. See
>> http://logback.qos.ch/manual/loggingSeparation.html for more
>> details.|#]
>>
>>
>>
>>
>> What am I missing?
>>
>>
>> Br,
>> Orair.