Uploaded image for project: '[Read Only] - Hippo Site Toolkit 2'
  1. [Read Only] - Hippo Site Toolkit 2
  2. HSTTWO-2976

Freemarker Servlet - Failed to load template from classpath: ftl resource on Windows

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • 2.28.03
    • None
    • None
    • WebLogic 12c / Windows

    Description

      Exception failing to load Freemarker template was found on WebLogic 12c/Windows environment.

      Exception:

      ==========================

      <May 21, 2014 2:46:46 PM EDT> <Error> <HTTP> <BEA-101005> <[ServletContext@1404590421[app:hippo-intranet module:/site path:null spec-version:3.0]] getRealPath() called with unsafe path: "/classpath:/org/hippoecm/hst/pagecomposer/builtin/components/vbox.ftl".
      java.io.IOException: The filename, directory name, or volume label syntax is incorrect
      at java.io.WinNTFileSystem.canonicalize0(Native Method)
      at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:414)
      at java.io.File.getCanonicalPath(File.java:618)
      at weblogic.servlet.internal.WebAppServletContext.getRealPath(WebAppServ
      letContext.java:678)
      at freemarker.cache.WebappTemplateLoader.findTemplateSource(WebappTempla
      teLoader.java:129)
      Truncated. see log file for complete stacktrace

      ==========================

      HstFreemarkerServlet uses freemarker.cache.MultiTemplateLoader which delegate call to the internal template loaders: 1) WebappTemplateLoader, 2) HstClassTemplateLoader, and 3) RepositoryTemplateLoader.

      MultiTemplateLoader doesn't catch any IOException other than FileNotFoundException. As a result, if WebappTemplateLoader throws an exception like excerpted above ("java.io.IOException: The filename, directory name, or volume label syntax is incorrect"), then MultiTemplateLoader doesn't try to load the template from the remaining template loaders.

      By the way, I've tested the following code in a jsp on non-Windows system:

      <%
      String path = "/classpath:/org/hippoecm/hst/pagecomposer/builtin/components/vbox.ftl";
      String realPath = application.getRealPath(path);
      out.println("realPath: " + realPath);
      %>

      It prints out the following on non-Windows environment without any problem:

      realPath: /home/woonsan/myhippoproject/target/tomcat6x/webapps/site/classpath:/org/hippoecm/hst/pagecomposer/builtin/components/vbox.ftl

      So, this problem seems to be a Window environment specific issue when processing with "classpath:" prefixed freemarker templates.

      Also, based on the stack trace, WebLogic seems to invoke java.io.File.getCanonicalPath() in ServletContext.getRealPath(), which might be a difference from the Tomcat's behavior. (That's probably why we cannot observe this problem on Tomcat/Windows environment.)

      Attachments

        Activity

          People

            jsheriff Junaidh Kadhar Sheriff
            wko Woonsan Ko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: