JCL icon indicating copy to clipboard operation
JCL copied to clipboard

JMS client is not working when initial context factory is loaded using JCL class loader

Open sandrocsimas opened this issue 7 years ago • 0 comments

I'm trying to implement a JMS client using Weblogic implementation, but its not working correctly. The inicial context factory class of Weblogic JMS implementation is weblogic.jndi.WLInitialContextFactory. I was looking at the code and I found the reason it was not working. The class mentioned above is found by JCL, but for some reason, JCL is creating the instance in a different way of the class loader used by JMS, the context class loader.

// JMS is instantiating the initial context factory this way:
loadClass(className, getContextClassLoader())

// The code above call...
Class.forName(className, true, classLoader)

// Getting class loader:
ClassLoader getContextClassLoader() {
  return AccessController.doPrivileged(
    new PrivilegedAction<ClassLoader>() {
      public ClassLoader run() {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader == null) {
          // Don't use bootstrap class loader directly!
          loader = ClassLoader.getSystemClassLoader();
        }
        return loader;
      }
    }
  );
}

Loading the initial context factory class using Thread.currentThread().getContextClassLoader() works fine. Using JCL class loader, the class is instantiated, but for some reason I could not connect to JMS server.

sandrocsimas avatar Nov 27 '17 13:11 sandrocsimas