Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5289

Using GroovyServlet deployed to Tomcat with a multi-level context causes 404 errors

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.3, 1.8.5
    • Fix Version/s: 2.0.6, 1.8.9
    • Component/s: Groovlet / GSP
    • Labels:
      None
    • Environment:
      Ubuntu Linux, Tomcat 7

      Description

      When deploying an application which use the GroovyServlet to Tomcat with a simple context, there are no problems. However, when deploying the same application to the same Tomcat instance using a multi-level context a 404 error is returned.

      Attaching a sample application which demonstrates this behavior. Simply run "mvn package" to create a WAR from the project. Take the "groovyweb.war" file from the "target" directory and deploy it to a Tomcat server. This will work just fine. Now take the same WAR file, rename it to "apps#groovyweb.war" and deploy it to Tomcat. Now a 404 is presented and in the log, a message indicates that the groovy script cannot be found.

      ----------------

      Looking into this, it appears that the "#" in the name is causing the problem. In the "loadScriptName" method of GroovyScriptEngine, it is calling "conn.getURL().getPath()" on the URLConnection to the resource. Because there is a "#" character in the URL, this only returns the part of the URL up to the "#" character.

      GroovyScriptEngine.java
      public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException {
          URLConnection conn = rc.getResourceConnection(scriptName);
          String path = conn.getURL().getPath();
          ScriptCacheEntry entry = scriptCache.get(path);
          Class clazz = null;
          if (entry != null) clazz = entry.scriptClass;
          try {
              if (isSourceNewer(entry)) {
                  try {
                      String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : "UTF-8";
                      clazz = groovyLoader.parseClass(DefaultGroovyMethods.getText(conn.getInputStream(), encoding), path);
                  } catch (IOException e) {
                      throw new ResourceException(e);
                  }
              }
          } finally {
              forceClose(conn);
          }
          return clazz;
      }
      

        Attachments

        1. groovyweb.tar.gz
          2 kB
          Daniel Mikusa
        2. AbstractHttpServletTest.groovy.patch
          3 kB
          Daniel Mikusa
        3. AbstractHttpServlet.java.patch
          2 kB
          Daniel Mikusa

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              dmikusa Daniel Mikusa
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: