Velocity Tools
  1. Velocity Tools
  2. VELTOOLS-57

ServletToolboxManager fails for .war files

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3
    • Component/s: VelocityView
    • Labels:
      None
    • Environment:
      irrelevant

      Description

      When webapps are deployed as .war files and the ServletToolboxManager is loaded from a shared location (mine is in shared/lib on Tomcat), the getInstance(ServletContext,String) method always returns the same manager. This is because the call to ServletContext.getRealPath(String) method, whose return value is used as the key into the managersMap, returns null when the webapp is deployed as a jar, per the servlet API. So, all ServletContext's end up getting/putting their managers using the null key into the managersMap .

      This is easy to fix. You just need another way to scope the toolbox filename based on the input ServletContext that's guaranteed to return something unique.

      1. patch
        0.8 kB
        Justin Patterson

        Activity

        Hide
        Nathan Bubna added a comment -

        acked. thx.

        and can i assume this is an issue in version 1.2 as well?

        patches are always welcome.
        but if no one else steps up, i'll try to get this into the next version.

        Show
        Nathan Bubna added a comment - acked. thx. and can i assume this is an issue in version 1.2 as well? patches are always welcome. but if no one else steps up, i'll try to get this into the next version.
        Hide
        Justin Patterson added a comment -

        Sorry. It is actually 1.2 that I found it against.

        Show
        Justin Patterson added a comment - Sorry. It is actually 1.2 that I found it against.
        Hide
        Justin Patterson added a comment -

        This is the patch that I've made to my local tree and which has worked for me.

        Basically, I'm creating the map key based on the hashCode of the ServletContext. I couldn't find a better method on ServletContext that was guaranteed to give me a unique value. I don't think that this should be an issue since the cache is not persistent.

        Show
        Justin Patterson added a comment - This is the patch that I've made to my local tree and which has worked for me. Basically, I'm creating the map key based on the hashCode of the ServletContext. I couldn't find a better method on ServletContext that was guaranteed to give me a unique value. I don't think that this should be an issue since the cache is not persistent.
        Hide
        Nathan Bubna added a comment -

        yeah, looks like that'll do the trick.

        Of course, if we can make ServletToolboxManager serializable, we could just put it into the servlet context attributes with the relative path to the toolbox file as the key...

        but for now i'll stick with this. thanks!

        Show
        Nathan Bubna added a comment - yeah, looks like that'll do the trick. Of course, if we can make ServletToolboxManager serializable, we could just put it into the servlet context attributes with the relative path to the toolbox file as the key... but for now i'll stick with this. thanks!
        Hide
        Nathan Bubna added a comment -

        ok, the change is in. thanks!

        Show
        Nathan Bubna added a comment - ok, the change is in. thanks!

          People

          • Assignee:
            Nathan Bubna
            Reporter:
            Justin Patterson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development