users@glassfish.java.net

getLastModified is not working?

From: <glassfish_at_javadesktop.org>
Date: Fri, 08 Oct 2010 04:15:57 PDT

Hi there,

I think I have found a bug where getLastModified is not working (that's from a servlet). I've tried to strip it down to a simple example so someone can confirm.

Take this simple servlet:

@WebServlet("/test")
public class TestServlet extends HttpServlet {
  private long tsInit;

  @Override
  public void init() throws ServletException {
    tsInit = System.currentTimeMillis();
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.getWriter().print("Now: " + new Date() + " tsInit: " + new Date(tsInit));
  }

  @Override
  protected long getLastModified(HttpServletRequest req) {
    return tsInit;
  }
}

When running in the current stable GF (version 3.0.1) and reloading this page this is what I get (headers from LiveHttpHeaders, firefox plugin):

http://127.0.0.1:8080/gfbug/test

GET /gfbug/test HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-es,es;q=0.8,en;q=0.5,en-us;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
If-Modified-Since: Fri, 08 Oct 2010 10:53:30 GMT

HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0
Server: GlassFish Server Open Source Edition 3.0.1
Last-Modified: Fri, 08 Oct 2010 10:53:30 GMT
Content-Length: 72
Date: Fri, 08 Oct 2010 10:54:15 GMT

If you notice the If-Modified-Since header then the response should be a 304 not a 200. It even splits the right Last-Modified!!
[Message sent by forum member 'sargue']

http://forums.java.net/jive/thread.jspa?messageID=484752