Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-531

Resource loading issue

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Minor
    • 2.4.1 SP4, 2.5
    • None
    • None
    • Low

    Description

      Recently I encountered a resource loading problem from within a tomcat webapp when trying to construct a JChannel when so triggered from a JMX MBean via the jconsole:

      channel = new JChannel("tcp.xml");

      Basically if the JChannel is constructed from a webapp, it can locate the "tcp.xml" from the classpath as a resource and works just fine. However if the JChannel is constructed from an MBean call stack via the jconsole, it failed to locate the resource due to the fact that the context classloading of the executing thread is different. So I hacked Util.java and it now worked in both cases. See below for details.

      My question is should the hack I made be incorporated into the official version ?

      (I hacked this on jgroups 2.2.9.4 , but I tried the latest 2.5.0CR1 which also seems to exhibit the same problem/behavior.)

      Hanson Char

      org.jgroups.util.Util.java
      =================
      public static InputStream getResourceAsStream(String name, Class clazz) {
      ClassLoader loader;

      try {
      loader=Thread.currentThread().getContextClassLoader();
      if(loader != null)

      { // hanson: returns only if resource is found // return loader.getResourceAsStream(name); InputStream is = loader.getResourceAsStream(name); if (is != null) return is; }

      }
      catch(Throwable t) {
      }

      if(clazz != null) {
      try {
      loader=clazz.getClassLoader();
      if(loader != null)

      { // hanson: returns only if resource is found // return loader.getResourceAsStream(name); InputStream is = loader.getResourceAsStream(name); if (is != null) return is; }

      }
      catch(Throwable t) {
      }
      }
      try {
      loader= ClassLoader.getSystemClassLoader();
      if(loader != null)

      { return loader.getResourceAsStream(name); }

      }
      catch(Throwable t) {
      }

      return null;
      }

      Attachments

        Activity

          People

            rhn-engineering-bban Bela Ban
            rhn-engineering-bban Bela Ban
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: