javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory

QOS.ch JIRA | Petr Kokorev | 6 years ago
  1. 0

    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); } }

    QOS.ch JIRA | 6 years ago | Petr Kokorev
    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
  2. 0

    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); } }

    QOS.ch JIRA | 6 years ago | Petr Kokorev
    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
  3. 0

    WsnInitialContextFactory in WAS 6.1

    Google Groups | 7 years ago | xavi1xavi
    com.filenet.api.exception.EngineRuntimeException: API_UNEXPECTED_JNDI_ERROR: An unexpected error occured accessing JNDI.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Requirement to run standalone client for WAS 7

    Stack Overflow | 4 years ago | Ashish
    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
  6. 0

    jar file name for com.ibm.websphere.naming.WsnInitialContextFactory for WAS 6.1

    Google Groups | 10 years ago | sendmail...@yahoo.com
    javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]

    12 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassNotFoundException

      com.ibm.websphere.naming.WsnInitialContextFactory

      at java.lang.Class.forNameImpl()
    2. Java RT
      InitialContext.<init>
      1. java.lang.Class.forNameImpl(Native Method)
      2. java.lang.Class.forName(Class.java:163)
      3. com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:57)
      4. javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:666)
      5. javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:259)
      6. javax.naming.InitialContext.init(InitialContext.java:235)
      7. javax.naming.InitialContext.<init>(InitialContext.java:209)
      7 frames
    3. Logback Core Module
      JMSAppenderBase.buildJNDIContext
      1. ch.qos.logback.core.net.JMSAppenderBase.buildJNDIContext(JMSAppenderBase.java:62)
      1 frame
    4. Logback Classic Module
      JMSTopicAppender.start
      1. ch.qos.logback.classic.net.JMSTopicAppender.start(JMSTopicAppender.java:97)
      1 frame
    5. Logback Core Module
      GenericConfigurator.doConfigure
      1. ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
      2. ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:315)
      3. ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:194)
      4. ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:180)
      5. ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:52)
      6. ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332)
      7. ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
      8. ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93)
      9. ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52)
      9 frames
    6. Logback Classic Module
      JMXConfigurator.reloadDefaultConfiguration
      1. ch.qos.logback.classic.jmx.JMXConfigurator.reloadByURL(JMXConfigurator.java:149)
      2. ch.qos.logback.classic.jmx.JMXConfigurator.reloadDefaultConfiguration(JMXConfigurator.java:104)
      2 frames
    7. Java RT
      Thread.run
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:618)
      5. com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(StandardMetaDataImpl.java:428)
      6. com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:238)
      7. com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:833)
      8. com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:802)
      9. javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1436)
      10. javax.management.remote.rmi.RMIConnectionImpl.access$100(RMIConnectionImpl.java:107)
      11. javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1273)
      12. javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1369)
      13. javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:810)
      14. sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
      15. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      16. java.lang.reflect.Method.invoke(Method.java:618)
      17. sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:309)
      18. sun.rmi.transport.Transport$1.run(Transport.java:168)
      19. java.security.AccessController.doPrivileged(AccessController.java:274)
      20. sun.rmi.transport.Transport.serviceCall(Transport.java:164)
      21. sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:506)
      22. sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.handleRequest(TCPTransport.java:838)
      23. sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:912)
      24. java.lang.Thread.run(Thread.java:811)
      24 frames