jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-4660

NPE in groovy.servlet.AbstractHttpServlet if deploy WAR to jetty

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.6
  • Fix Version/s: 1.8.6, 2.0-beta-3
  • Component/s: Groovlet / GSP
  • Labels:
    None
  • Environment:
    Jetty: 7.2.0.v20101020

Description

I have generated a (non-grails) war using gsp's mapped to groovy.servlet.TemplateServlet. If I deploy the War to Tomcat it works. If I unpack the war then it works in Jetty. But it fails with an NPE if I try to deploy it as a War with Jetty:

2011-02-04 11:04:06.030:INFO:data-pump-comparator-04.04.01-dev:GroovyTemplate: Servlet groovy.servlet.TemplateServlet initialized on
class groovy.text.GStringTemplateEngine
2011-02-04 11:04:06.030:WARN::/data-pump-comparator-04.04.01-dev/
java.lang.NullPointerException
at java.io.File.<init>(File.java:222)
at groovy.servlet.AbstractHttpServlet.getScriptUriAsFile(AbstractHttpServlet.java:306)
at groovy.servlet.TemplateServlet.service(TemplateServlet.java:388)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:533)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:475)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)

I think this is down to a problm in groovy.servlet.AbstractHttpServlet

TemplateServlet.service does this:

File file = super.getScriptUriAsFile(request);

AbstractHttpServlet.getScriptUriAsFile does this:
String uri = getScriptUri(request);
String real = servletContext.getRealPath(uri);
return new File(real).getAbsoluteFile();

The Javadocs for javax.servlet.ServletContext.getRealPath say:

  • This method returns null
  • if the servlet container cannot translate the virtual path
  • to a real path for any reason (such as when the content is
  • being made available from a .war archive).

I think that is why the failure happens. AFAIK it also happens with WebLogic (http://groovy.329449.n5.nabble.com/Groovlet-GSP-NPE-when-deployed-as-a-war-to-Weblogic-td3320802.html)

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    GROOVY-4660.patch
    09/Feb/11 12:34 PM
    16 kB
    Paul Cager

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Guillaume Laforge added a comment - 04/Feb/11 6:22 AM

So how do you suggest fixing this? (Even better, a patch is warmly welcome)

Show
Guillaume Laforge added a comment - 04/Feb/11 6:22 AM So how do you suggest fixing this? (Even better, a patch is warmly welcome)
Hide
Permalink
Paul Cager added a comment - 04/Feb/11 6:55 AM

Sure - I'll see if I can work out a patch.

As far as I can see getScriptUriAsFile is used instead of getScriptUri so that the file's DateLastUpdated timestamp may be used to determine if the cache is out of date. I believe we'd need to preserve that behaviour, but fall back to using a URI if the file is not available.

Show
Paul Cager added a comment - 04/Feb/11 6:55 AM Sure - I'll see if I can work out a patch. As far as I can see getScriptUriAsFile is used instead of getScriptUri so that the file's DateLastUpdated timestamp may be used to determine if the cache is out of date. I believe we'd need to preserve that behaviour, but fall back to using a URI if the file is not available.
Hide
Permalink
Paul Cager added a comment - 09/Feb/11 12:34 PM

Patch attached for you to look at.

Summary:

1) Minor change to AbstractHttpServlet.getScriptUriAsFile so that it returns null (rather than an NPE) if getRealPath returns null.

2) Change to TemplateServlet so that if getScriptUriAsFile returns null it will read the template text using servletContext.getResource(name) instead.

3) Change to TemplateServlet's caching, to allow for the fact that we might not have a File (when it checks file.dateLastModified).

4) Minor change to AbstractHttpServlet's test class.

Show
Paul Cager added a comment - 09/Feb/11 12:34 PM Patch attached for you to look at. Summary: 1) Minor change to AbstractHttpServlet.getScriptUriAsFile so that it returns null (rather than an NPE) if getRealPath returns null. 2) Change to TemplateServlet so that if getScriptUriAsFile returns null it will read the template text using servletContext.getResource(name) instead. 3) Change to TemplateServlet's caching, to allow for the fact that we might not have a File (when it checks file.dateLastModified). 4) Minor change to AbstractHttpServlet's test class.
Hide
Permalink
Guillaume Laforge added a comment - 02/Feb/12 10:19 AM

The patch needed to be applied somehow manually, as it couldn't be applied automatically, making me wonder from what exact version you made the patch, but anyway, I've tried a groovlet and template in a war on Jetty, and it worked fine with the adapted patch.

Show
Guillaume Laforge added a comment - 02/Feb/12 10:19 AM The patch needed to be applied somehow manually, as it couldn't be applied automatically, making me wonder from what exact version you made the patch, but anyway, I've tried a groovlet and template in a war on Jetty, and it worked fine with the adapted patch.

People

  • Assignee:
    Guillaume Laforge
    Reporter:
    Paul Cager
Vote (0)
Watch (1)

Dates

  • Created:
    04/Feb/11 6:19 AM
    Updated:
    12/Feb/12 4:03 AM
    Resolved:
    02/Feb/12 10:19 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.