Menu

#113 TaglibFactory should, opt, use Servlet 3.0 TLD Support

2.3.22
closed-fixed
5
2015-02-28
2011-01-04
No

The way FreeMarker's TaglibFactory find *.tld from JAR (peeking into in WEB-INF/lib, via ServletContext getResourcePaths) can cause issues in certain environments.

For example, I'm setting up a WAR-free "flat classpath" IDE development environment (Jetty-based) for http://mifos.org (which uses FreeMarker), and got hit by this. (https://github.com/vorburger/EclipseWebDevEnv/blob/servlet30-jetty7/simpleservers/ demonstrates the underlying approach leading to this problem - in this particular kind of set-up).

https://github.com/vorburger/EclipseWebDevEnv/commit/f06def15ac364a3c06d1a15ee4680ea90d62e60f#diff-5 how I worked around this (Jetty extension code, FreeMarker unpatched).

In Servlet 3.0 there is a new ServletContext.getJspConfigDescriptor()'s TaglibDescriptor, with getTaglibLocation() & getTaglibURI(). It would be cool if in the future FreeMarker could use that instead of getResourcePaths() to find TLDs - when it's running in a Servlet 3.0 container.

http://jira.magnolia-cms.com/browse/MAGNOLIA-2608 had hit the same issue as me, BTW.

Discussion

  • Dániel Dékány

    It's more a feature request than a bug. Anyway, I don't know when. A patch (CLA is needed!) that can be easily tested probably helps to move things forward. Although integrating/validating patches is still time. (Too bad companies don't care to finance some FM "sprints" now and then... That could move forward things a lot. I don't know, maybe I should ask around.)

     
  • Dániel Dékány

    I have checked the getJspConfigDescriptor API, but it seems all it does is extracting the taglib mappings from web.xml, which FreeMarker always did anyway. The requested thing is also a non-standard feature, not part of the JSP specification. So I have moved this over as an RFE.

     

    Last edit: Dániel Dékány 2014-12-09
  • Dániel Dékány

    Ticket moved from /p/freemarker/bugs/339/

     
  • Dániel Dékány

    • status: open --> open-accepted
    • assigned_to: Dániel Dékány
    • Group: --> 2.3.22
     
  • Dániel Dékány

    OK, I think the problem is solved. From the 2.3.22 version history:

    • RFE resolved [113] [114]: FreemarkerServlet can now discover META-INF/**/*.tld-s that are visible for the class loader but aren't in WEB-INF/lib/*.jar-s. For this feature to be active, you must setup the extra TLD lookup with the MetaInfTldSources and/or ClasspathTlds FreemarkerServlet init-params (see the Java API documentation of FreemarkerServlet for the description of these). For example, if you ran your application from Eclipse with an embedded servlet container, and thus the tag library jar-s aren't on the standard locations but are in the classpath like any other dependency, now you can just write:
      <init-param>
      <param-name>MetaInfTldSources</param-name>
      <param-value>classpath</param-value>
      </init-param>
      and then all the META-INF directories that are visible for the class loader will be searched for TLD-s.

    • MetaInfTldSources and ClasspathTlds can also be appended to or replaced by the values of Java system properties org.freemarker.jsp.metaInfTldSources and org.freemarker.jsp.classpathTlds, respectively. Thus one can adjust these in the Eclipse run configuration without modifying the web.xml. (See the Java API documentation of FreemarkerServlet for more.)

    • FreemarkerServlet now recognizes the org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern servlet context attribute, add entries to MetaInfTldSources (introduced above) from it.

    • Added protected FreemarkerServlet.createTaglibFactory() to allow fine tuning the settings of the TaglibFactory. It now have a few setters, like setObjectWrapper, setMetaInfTldSource, etc.

     

    Last edit: Dániel Dékány 2014-12-13
  • Dániel Dékány

    • Status: open-accepted --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB