felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r1770706 - /felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
Date Mon, 21 Nov 2016 15:37:16 GMT
Author: bimargulies
Date: Mon Nov 21 15:37:16 2016
New Revision: 1770706

URL: http://svn.apache.org/viewvc?rev=1770706&view=rev
Log:
FELIX-5422: more date formats in lite.

Modified:
    felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java

Modified: felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java?rev=1770706&r1=1770705&r2=1770706&view=diff
==============================================================================
--- felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
(original)
+++ felix/trunk/httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
Mon Nov 21 15:37:16 2016
@@ -61,6 +61,12 @@ import org.apache.felix.httplite.osgi.Se
  **/
 public class HttpServletRequestImpl implements HttpServletRequest
 {
+
+    private static final SimpleDateFormat formatsTemplate[] = {
+            new SimpleDateFormat(HttpConstants.HTTP_DATE_FORMAT, Locale.US),
+            new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
+            new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
+    };
     /**
      * HTTP Method
      */
@@ -819,16 +825,17 @@ public class HttpServletRequestImpl impl
             return -1;
         }
 
-        try
-        {
-            SimpleDateFormat sdf = new SimpleDateFormat(HttpConstants.HTTP_DATE_FORMAT);
-            sdf.setTimeZone(TimeZone.getTimeZone(HttpConstants.HTTP_TIMEZONE));
-            return sdf.parse( headerValue ).getTime();
-        }
-        catch ( ParseException e )
-        {
-            throw new IllegalArgumentException( "Unable to convert to date: " + headerValue
);
+        for (int x = 0; x < formatsTemplate.length; x++) {
+        SimpleDateFormat sdf = formatsTemplate[x];
+            try {
+                sdf.setTimeZone(TimeZone.getTimeZone(HttpConstants.HTTP_TIMEZONE));
+                return sdf.parse(headerValue).getTime();
+            } catch (ParseException e) {
+                //
+            }
         }
+        // if none of them work.
+        throw new IllegalArgumentException("Unable to convert to date: " + headerValue);
     }
 
 



Mime
View raw message