[logback-dev] [JIRA] Created: (LBCORE-192) JMSAppenderBase throws javax.naming.NoInitialContextException when reloading the configuration from JMX console
Petr KOKOREV (JIRA)
noreply-jira at qos.ch
Thu Jan 13 09:26:52 CET 2011
JMSAppenderBase throws javax.naming.NoInitialContextException when reloading the configuration from JMX console
---------------------------------------------------------------------------------------------------------------
Key: LBCORE-192
URL: http://jira.qos.ch/browse/LBCORE-192
Project: logback-core
Issue Type: Bug
Components: Appender
Affects Versions: 0.9.26
Environment: WebSphere 6.1, IBM JDK 1.5.0 J9 2.3, AIX / Windows XP
Reporter: Petr KOKOREV
Assignee: Logback dev list
The issue produces when I try to reload the configuration from the JMX console. I have a JMS appender defined as follows :
<appender name="JMS_TOPIC" class="ch.qos.logback.classic.net.JMSTopicAppender">
<param name="InitialContextFactoryName" value="com.ibm.websphere.naming.WsnInitialContextFactory" />
<param name="ProviderURL" value="iiop://localhost:10014" />
<param name="TopicConnectionFactoryBindingName" value="loggingTopicConnectionFactory" />
<param name="TopicBindingName" value="loggingTopic" />
<param name="LocationInfo" value="false" />
</appender>
Exception that I get :
15:15:43,704 |-ERROR in ch.qos.logback.classic.net.JMSTopicAppender[JMS_TOPIC] - Error while activating options for appender named [JMS_TOPIC]. javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
at javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
at at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:669)
at at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:259)
at at javax.naming.InitialContext.init(InitialContext.java:235)
at at javax.naming.InitialContext.<init>(InitialContext.java:209)
at at ch.qos.logback.core.net.JMSAppenderBase.buildJNDIContext(JMSAppenderBase.java:62)
at at ch.qos.logback.classic.net.JMSTopicAppender.start(JMSTopicAppender.java:97)
at at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:315)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:194)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:180)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:52)
at at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52)
at at ch.qos.logback.classic.jmx.JMXConfigurator.reloadByURL(JMXConfigurator.java:149)
at at ch.qos.logback.classic.jmx.JMXConfigurator.reloadDefaultConfiguration(JMXConfigurator.java:104)
at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at at java.lang.reflect.Method.invoke(Method.java:618)
at at com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(StandardMetaDataImpl.java:428)
at at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:238)
at at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:833)
at at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:802)
at at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1436)
at at javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:107)
at at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1273)
at at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1369)
at at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:810)
at at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at at java.lang.reflect.Method.invoke(Method.java:618)
at at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:309)
at at sun.rmi.transport.Transport$1.run(Transport.java:168)
at at java.security.AccessController.doPrivileged(AccessController.java:274)
at at sun.rmi.transport.Transport.serviceCall(Transport.java:164)
at at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:506)
at at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.handleRequest(TCPTransport.java:838)
at at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:912)
at at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at at java.lang.Class.forNameImpl(Native Method)
at at java.lang.Class.forName(Class.java:163)
at at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:57)
at at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:666)
at ... 40 common frames omitted
The real problem comes from the way the VersionHelper (com.sun.naming.internal.VersionHelper12) loads the InitialContextFactory class. In fact, it uses the Thread.currentThread().getContextClassLoader() method and then passes the result ClassLoader to the Class.forName(String className, boolean initializeBoolean, ClassLoader classLoader) method. Then the ClassNotFoundException is produced and causes the final NoInitialContextException. If it used the default class loader, everything would work fine.
The solution that I propose affects the buildJNDIContext() and lookup() methods in the JMSAppenderBase class. The idea is to replace the current thread's ContextClassLoader by the default getClass().getClassLoader() when calling new InitialContext(env) and restore the original one afterwards :
public Context buildJNDIContext() throws NamingException {
Context jndi = null;
final ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
try {
final ClassLoader newLoader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newLoader);
// addInfo("Getting initial context.");
if (initialContextFactoryName != null) {
Properties env = buildEnvProperties();
jndi = new InitialContext(env);
} else {
jndi = new InitialContext();
}
} finally {
Thread.currentThread().setContextClassLoader(originalLoader);
}
return jndi;
}
protected Object lookup(Context ctx, String name) throws NamingException {
final ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
try {
final ClassLoader newLoader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newLoader);
return ctx.lookup(name);
} catch (NameNotFoundException e) {
addError("Could not find name [" + name + "].");
throw e;
} finally {
Thread.currentThread().setContextClassLoader(originalLoader);
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the logback-dev
mailing list