<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    On 17/04/2011 02:31, Esteban Aliverti wrote:
    <blockquote
      cite="mid:BANLkTin8d4D43TVmFYPe9AB9yf_AZ5kuJA@mail.gmail.com"
      type="cite">
      <p>Thanks pablo (aka baunax)!<br>
        I agree that resource -&gt; file: is not always possible. But
        what about resource -&gt; URL? After all, i'm converting
        resources to URLs.</p>
    </blockquote>
    The URL will have a pointer to the file inside of the jar.<br>
    <a class="moz-txt-link-freetext" href="http://www.exampledepot.com/egs/java.net/JarUrl.html">http://www.exampledepot.com/egs/java.net/JarUrl.html</a><br>
    <br>
    Mark<br>
    <blockquote
      cite="mid:BANLkTin8d4D43TVmFYPe9AB9yf_AZ5kuJA@mail.gmail.com"
      type="cite">
      <p>Best regards,<br>
      </p>
      <div class="gmail_quote">El abr 16, 2011 5:18 p.m., "Pablo
        Nussembaum" &lt;<a moz-do-not-send="true"
          href="mailto:baunax@gmail.com">baunax@gmail.com</a>&gt;
        escribi&oacute;:<br type="attribution">
        &gt; Sorry "IF I *wasn't* clear" :-P<br>
        &gt; <br>
        &gt; On 04/16/2011 05:11 PM, Pablo Nussembaum wrote:<br>
        &gt;&gt; Sorry if I was clear. The problem when you do:
        ClassLoader.getResource( "resource.path" ) is the the resource
        can be inside a war the in WEB-INF/classes and the war could be
        NOT exploded in<br>
        &gt;&gt; container that's is deployed, so the translation to
        something like <a class="moz-txt-link-freetext" href="file://">file://</a> is NOT reliable.<br>
        &gt;&gt;<br>
        &gt;&gt; On 04/16/2011 05:05 PM, Mauricio Salatino wrote:<br>
        &gt;&gt;&gt; I'm still thinking about that mapping and those
        assumptions<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; On Sat, Apr 16, 2011 at 5:05 PM, Mauricio Salatino
        &lt;<a moz-do-not-send="true" href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>
        &lt;mailto:<a moz-do-not-send="true"
          href="mailto:salaboy@gmail.com">salaboy@gmail.com</a>&gt;&gt;
        wrote:<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; Can you? or Can't you?<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; On Sat, Apr 16, 2011 at 4:24 PM, Pablo Nussembaum
        &lt;<a moz-do-not-send="true" href="mailto:baunax@gmail.com">baunax@gmail.com</a>
        &lt;mailto:<a moz-do-not-send="true"
          href="mailto:baunax@gmail.com">baunax@gmail.com</a>&gt;&gt;
        wrote:<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; Esteban,<br>
        &gt;&gt;&gt; You can assume that a resource that was obtained
        from the classpath exists in your filesystem, for instance it
        can be a file inside a jar or war that are not exploded. In
        other words you<br>
        &gt;&gt;&gt; can't always convert an URL to <a class="moz-txt-link-rfc2396E" href="file://">"file://"</a>.<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; -- <br>
        &gt;&gt;&gt; Bauna<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; On 04/15/2011 08:52 AM, Esteban Aliverti wrote:<br>
        &gt;&gt;&gt;&gt; Hi Guys,<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; I want to discuss a problem I have found when
        using the combination of knowledge agent + classpathResources.<br>
        &gt;&gt;&gt;&gt; I will try to describe what am I doing first to
        give you some context. <br>
        &gt;&gt;&gt;&gt; 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.<br>
        &gt;&gt;&gt;&gt; My knowledge-services.xml file declares the
        following kagent:<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; &lt;drools:kagent id="kagent1" kbase="kbase1"
        new-instance="false"&gt;<br>
        &gt;&gt;&gt;&gt; &lt;drools:resources&gt; <br>
        &gt;&gt;&gt;&gt; &lt;drools:resource type="DRL"
        source="*classpath*:simple.drl"/&gt;<br>
        &gt;&gt;&gt;&gt; ... <br>
        &gt;&gt;&gt;&gt; &lt;/drools:resources&gt;<br>
        &gt;&gt;&gt;&gt; &lt;/drools:kagent&gt;<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; When spring parses this configuration file it
        creates a KnowledgeAgent instance with a ChangeSet containing
        all the listed resources.<br>
        &gt;&gt;&gt;&gt; The next step is to start
        ResourceChangeNotifierService and ResourceChangeScannerService.
        <br>
        &gt;&gt;&gt;&gt; So far so good.<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; The problem:<br>
        &gt;&gt;&gt;&gt; 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.<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; ClassPathResource is the class that represents
        a resource defined as "*classpath:"*<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; This class has 2 important methods:<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; public long getLastModified(){<br>
        &gt;&gt;&gt;&gt; return this.classLoader.getResource( this.path
        ).openConnection().getLastModified();<br>
        &gt;&gt;&gt;&gt; }<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; public InputStream getInputStream(){<br>
        &gt;&gt;&gt;&gt; return this.classLoader.getResourceAsStream(
        this.path );<br>
        &gt;&gt;&gt;&gt; }<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; 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<br>
        &gt;&gt;&gt;&gt; the change without any problem.<br>
        &gt;&gt;&gt;&gt; The scanner ends up notifying the kagent about
        the change, and the kagent passes the Resource to an instance of
        KnowledgeBuilder. <br>
        &gt;&gt;&gt;&gt; An here is when things fail.<br>
        &gt;&gt;&gt;&gt; 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<br>
        &gt;&gt;&gt;&gt; the classloader (Tomcat's classloader) is using
        a cache. So the InputStream returned doesn't reflect the current
        state of the resource.<br>
        &gt;&gt;&gt;&gt; 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 :P<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; Solutions:<br>
        &gt;&gt;&gt;&gt; The first solution is not to use classpath
        resources :). You can use just url resources like <a class="moz-txt-link-freetext" href="http://">http://</a> or
        <a class="moz-txt-link-freetext" href="file:/">file:/</a>. But honestly, when you have your rules inside your
        webapp, it is much<br>
        &gt;&gt;&gt;&gt; more comfortable and even manageable to avoid
        the use of real paths.<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; What I was thinking about (I already have a
        working prototype) is to create a new Resource type for these
        cases. This resource type will let you define your resources
        present in your<br>
        &gt;&gt;&gt;&gt; classpath as usually but it will translate them
        to URL Resource internally.<br>
        &gt;&gt;&gt;&gt; So, in the example above: <br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; &lt;drools:resource type="DRL"
        source="*URLClasspath*:simple.drl"/&gt;<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; is going to be translated (internally and in a
        transparent way) to something like:
        <a class="moz-txt-link-freetext" href="file:/usr/local/apache-tomcat-7/webapps/MyWebapp/WEB-INF/simple.drl">file:/usr/local/apache-tomcat-7/webapps/MyWebapp/WEB-INF/simple.drl</a>.<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; Opinions? <br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; Esteban Aliverti<br>
        &gt;&gt;&gt;&gt; - Developer @ <a moz-do-not-send="true"
          href="http://www.plugtree.com">http://www.plugtree.com</a>
        &lt;<a moz-do-not-send="true" href="http://www.plugtree.com">http://www.plugtree.com</a>&gt;<br>
        &gt;&gt;&gt;&gt; - Blog @ <a moz-do-not-send="true"
          href="http://ilesteban.wordpress.com">http://ilesteban.wordpress.com</a><br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt;<br>
        &gt;&gt;&gt;&gt; _______________________________________________<br>
        &gt;&gt;&gt;&gt; rules-dev mailing list<br>
        &gt;&gt;&gt;&gt; <a moz-do-not-send="true"
          href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
        &lt;mailto:<a moz-do-not-send="true"
          href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&gt;
        <a moz-do-not-send="true"
          href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; _______________________________________________<br>
        &gt;&gt;&gt; rules-dev mailing list<br>
        &gt;&gt;&gt; <a moz-do-not-send="true"
          href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
        &lt;mailto:<a moz-do-not-send="true"
          href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&gt;<br>
        &gt;&gt;&gt; <a moz-do-not-send="true"
          href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; -- <br>
        &gt;&gt;&gt; - CTO @ <a moz-do-not-send="true"
          href="http://www.plugtree.com">http://www.plugtree.com</a> <br>
        &gt;&gt;&gt; - MyJourney @ <a moz-do-not-send="true"
          href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
        &gt;&gt;&gt; - Co-Founder @ <a moz-do-not-send="true"
          href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>
        &gt;&gt;&gt; <br>
        &gt;&gt;&gt; - Salatino "Salaboy" Mauricio -<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt;<br>
        &gt;&gt;&gt; -- <br>
        &gt;&gt;&gt; - CTO @ <a moz-do-not-send="true"
          href="http://www.plugtree.com">http://www.plugtree.com</a> <br>
        &gt;&gt;&gt; - MyJourney @ <a moz-do-not-send="true"
          href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
        &gt;&gt;&gt; - Co-Founder @ <a moz-do-not-send="true"
          href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>
        &gt;&gt;&gt; <br>
        &gt;&gt;&gt; - Salatino "Salaboy" Mauricio -<br>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>