Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2960

ClassPathResource fails to get last version if the underlying ClassLoader uses a cache.

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Optional Optional
    • 5.3.0.CR1
    • 5.2.0.M1
    • drools-core
    • None
    • Hide

      Explained in Description field.

      Show
      Explained in Description field.
    • Workaround Exists
    • Hide

      Don't use "classpath:" resources and use "file:/" or "http://" instead.

      Show
      Don't use "classpath:" resources and use "file:/" or "http://" instead.
    • Medium

      I'm deploying drools-camel-server in a Tomcat 7 container. Inside the WEB-INF/classes directory I have some DRL files that I want to use.
      My knowledge-services.xml file declares the following kagent:

      <drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
      <drools:resources>
      <drools:resource type="DRL" source="classpath:simple.drl"/>
      ...
      </drools:resources>
      </drools:kagent>

      When spring parses this configuration file it creates a KnowledgeAgent instance with a ChangeSet containing all the listed resources.
      The next step is to start ResourceChangeNotifierService and ResourceChangeScannerService.
      So far so good.

      The problem:
      The problem I'm having is not directly related to drools, but I think it is quite easy to provide a solution for the people that is in my same situation.

      ClassPathResource is the class that represents a resource defined as "classpath:"

      This class has 2 important methods:

      public long getLastModified(){
      return this.classLoader.getResource( this.path ).openConnection().getLastModified();
      }

      public InputStream getInputStream(){
      return this.classLoader.getResourceAsStream( this.path );
      }

      The first method is used by ResourceChangeScannerService to check whether the resource has changed or not. It works fine. When the resource in the filesystem changes, the scanner detects the change without any problem.
      The scanner ends up notifying the kagent about the change, and the kagent passes the Resource to an instance of KnowledgeBuilder.
      An here is when things fail.
      The kbuilder uses the second method of ClassPathResource (getInputStream()) to get the content of the resource. In the case of Tomcat (and probably some other environments), it seems that the classloader (Tomcat's classloader) is using a cache. So the InputStream returned doesn't reflect the current state of the resource.
      Long story short: the agent is notified about a change in the resource, but the change is never applied to the kbase because the kbuilder is unable to get it

            esteban.aliverti@gmail.com Esteban Aliverti (Inactive)
            esteban.aliverti@gmail.com Esteban Aliverti (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

              Created:
              Updated:
              Resolved:
              Archived: