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

Return 404 for non-existing paths in `TemplateServlet` when running from .war

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.4.13
    • None
    • Payara Micro

    Description

      When TemplateServlet is used in application servers that don't unpack a war (i.e. when the real path of resources could not be retrieved), an internal server error is returned upon trying to retrieve a non-existing template file.

      The expected behavior would be to get a 404, just as it is already the case when running from a extracted war.

      I had this behavior when running on a payara micro application server using the following web.xml snippet:

      <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
          <servlet>
              <servlet-name>GroovyTemplate</servlet-name>
              <servlet-class&gt;groovy.servlet.TemplateServlet</servlet-class&gt;
          </servlet>
          <servlet-mapping>
              <servlet-name>GroovyTemplate</servlet-name>
              <url-pattern>*.gsp</url-pattern>
          </servlet-mapping>
      </web-app>
      

      and requesting an url ending in *.gsp, but without a template with that name present.

      Please see the attached minimal example (docker required):
      Run it with:

      ./gradlew runDockerContainer
      

      and test the URLs
      http://localhost:8080/test.gsp (works)
      http://localhost:8080/unknown.gsp (500, but I would actually expect a 404)

      The corresponding stacktrace is

      java.lang.NullPointerException
              at groovy.servlet.TemplateServlet.getTemplate(TemplateServlet.java:331)
              at groovy.servlet.TemplateServlet.service(TemplateServlet.java:445)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
              at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1606)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
              at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:654)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:593)
              at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
              at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
              at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:466)
              at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:169)
              at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
              at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
              at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
              at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
              at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
              at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
              at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
              at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
              at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
              at java.lang.Thread.run(Thread.java:745)
      

      Attachments

        1. broken-template-servlet.tar.gz
          55 kB
          Thomas Reifenberger

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              tom-mi Thomas Reifenberger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: