简体   繁体   中英

Exception when parsing RFC1123 date with HttpServletRequest#getDateHeader()

I am trying to parse the HTTP header Date: Tue, 15 Nov 1994 08:12:31 GMT for an HttpServletRequest with a call to request.getDateHeader("Date") but get the following exception:

java.lang.NumberFormatException: Tue, 15 Nov 1994 08:12:31 GMT
    at org.mortbay.io.BufferUtil.toLong(BufferUtil.java:106) 
    at org.mortbay.jetty.HttpFields$Field.getLongValue(HttpFields.java:1479)
    at org.mortbay.jetty.HttpFields.getLongField(HttpFields.java:720)
    at org.mortbay.jetty.Request.getIntHeader(Request.java:728)
    at javax.servlet.http.HttpServletRequestWrapper.getIntHeader(HttpServletRequestWrapper.java:106)
    at javax.servlet.http.HttpServletRequestWrapper.getIntHeader(HttpServletRequestWrapper.java:106)
    at com.google.appengine.tools.development.ResponseRewriterFilter$RequestWrapper.getDateHeader(ResponseRewriterFilter.java:417)
    at com.example.ExampleServlet.doPost(ExampleServlet.java:93)

What am I doing wrong? The sample date is taken directly from the HTTP specification , so I would expect it to be valid under RFC 1123. The servlet is part of an App Engine app (on development server).

This is a known bug in the app engine library. Here is the getDateHeader function at issue, and it clearly calls super.getIntHeader() . It doesn't look like Google is in a hurry to fix it, unfortunately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM