Author: remy.maucherat(a)jboss.com
Date: 2008-09-30 11:56:04 -0400 (Tue, 30 Sep 2008)
New Revision: 798
Removed:
trunk/java/org/apache/tomcat/util/buf/DateTool.java
Modified:
trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
trunk/java/org/apache/tomcat/util/http/ServerCookie.java
trunk/webapps/docs/changelog.xml
Log:
- Remove DateTool. Also restore the set timezone that was missing.
Modified: trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java
===================================================================
--- trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java 2008-09-29 15:47:49 UTC
(rev 797)
+++ trunk/java/org/apache/catalina/ssi/ResponseIncludeWrapper.java 2008-09-30 15:56:04 UTC
(rev 798)
@@ -22,6 +22,8 @@
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
@@ -29,7 +31,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import org.apache.catalina.util.DateTool;
/**
* A HttpServletResponseWrapper, used from
* <code>SSIServletExternalResolver</code>
@@ -44,8 +45,9 @@
*/
private static final String CONTENT_TYPE = "content-type";
private static final String LAST_MODIFIED = "last-modified";
- private static final DateFormat format =
- new SimpleDateFormat(DateTool.RFC1123_PATTERN, DateTool.LOCALE_US);
+ private static final DateFormat RFC1123_FORMAT;
+ private final static String RFC1123_PATTERN = "EEE, dd MMM yyyy HH:mm:ss
z";
+
protected long lastModified = -1;
private String contentType = null;
@@ -59,7 +61,11 @@
private ServletContext context;
private HttpServletRequest request;
-
+ static {
+ RFC1123_FORMAT = new SimpleDateFormat(RFC1123_PATTERN, Locale.US);
+ RFC1123_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
/**
* Initialize our wrapper with the current HttpServletResponse and
* ServletOutputStream.
@@ -212,8 +218,8 @@
String lname = name.toLowerCase();
if (lname.equals(LAST_MODIFIED)) {
try {
- synchronized(format) {
- lastModified = format.parse(value).getTime();
+ synchronized(RFC1123_FORMAT) {
+ lastModified = RFC1123_FORMAT.parse(value).getTime();
}
} catch (Throwable ignore) { }
} else if (lname.equals(CONTENT_TYPE)) {
@@ -234,8 +240,8 @@
String lname = name.toLowerCase();
if (lname.equals(LAST_MODIFIED)) {
try {
- synchronized(format) {
- lastModified = format.parse(value).getTime();
+ synchronized(RFC1123_FORMAT) {
+ lastModified = RFC1123_FORMAT.parse(value).getTime();
}
} catch (Throwable ignore) { }
}
Deleted: trunk/java/org/apache/tomcat/util/buf/DateTool.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/DateTool.java 2008-09-29 15:47:49 UTC (rev 797)
+++ trunk/java/org/apache/tomcat/util/buf/DateTool.java 2008-09-30 15:56:04 UTC (rev 798)
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.tomcat.util.buf;
-
-import java.text.DateFormat;
-import java.text.FieldPosition;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.apache.tomcat.util.res.StringManager;
-
-/**
- * Common place for date utils.
- *
- * @deprecated Will be replaced with a more efficient impl, based on
- * FastDateFormat, with an API using less objects.
- * @author dac(a)eng.sun.com
- * @author Jason Hunter [jch(a)eng.sun.com]
- * @author James Todd [gonzo(a)eng.sun.com]
- * @author Costin Manolache
- */
-public class DateTool {
-
- /** US locale - all HTTP dates are in english
- */
- private final static Locale LOCALE_US = Locale.US;
-
- /** GMT timezone - all HTTP dates are on GMT
- */
- public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
-
- /** format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
- */
- public final static String RFC1123_PATTERN =
- "EEE, dd MMM yyyy HH:mm:ss z";
-
- // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
- public final static String rfc1036Pattern =
- "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
-
- // format for C asctime() date string -- "Sun Nov 6 08:49:37 1994"
- public final static String asctimePattern =
- "EEE MMM d HH:mm:ss yyyy";
-
- /** Pattern used for old cookies
- */
- private final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss
z";
-
- /** DateFormat to be used to format dates. Called from MessageBytes
- */
- private final static DateFormat rfc1123Format =
- new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
-
- /** DateFormat to be used to format old netscape cookies
- Called from ServerCookie
- */
- private final static DateFormat oldCookieFormat =
- new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
-
- private final static DateFormat rfc1036Format =
- new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
-
- private final static DateFormat asctimeFormat =
- new SimpleDateFormat(asctimePattern, LOCALE_US);
-
- static {
- rfc1123Format.setTimeZone(GMT_ZONE);
- oldCookieFormat.setTimeZone(GMT_ZONE);
- rfc1036Format.setTimeZone(GMT_ZONE);
- asctimeFormat.setTimeZone(GMT_ZONE);
- }
-
- private static String rfc1123DS;
- private static long rfc1123Sec;
-
- private static StringManager sm =
- StringManager.getManager("org.apache.tomcat.util.buf.res");
-
- // Called from MessageBytes.getTime()
- static long parseDate( MessageBytes value ) {
- return parseDate( value.toString());
- }
-
- // Called from MessageBytes.setTime
- /**
- */
- public static String format1123( Date d ) {
- String dstr=null;
- synchronized(rfc1123Format) {
- dstr = format1123(d, rfc1123Format);
- }
- return dstr;
- }
-
- public static String format1123( Date d,DateFormat df ) {
- long dt = d.getTime() / 1000;
- if ((rfc1123DS != null) && (dt == rfc1123Sec))
- return rfc1123DS;
- rfc1123DS = df.format( d );
- rfc1123Sec = dt;
- return rfc1123DS;
- }
-
-
- // Called from ServerCookie
- /**
- */
- public static void formatOldCookie( Date d, StringBuffer sb,
- FieldPosition fp )
- {
- synchronized(oldCookieFormat) {
- oldCookieFormat.format( d, sb, fp );
- }
- }
-
- // Called from ServerCookie
- public static String formatOldCookie( Date d )
- {
- String ocf=null;
- synchronized(oldCookieFormat) {
- ocf= oldCookieFormat.format( d );
- }
- return ocf;
- }
-
-
- /** Called from HttpServletRequest.getDateHeader().
- Not efficient - but not very used.
- */
- public static long parseDate( String dateString ) {
- DateFormat [] format = {rfc1123Format,rfc1036Format,asctimeFormat};
- return parseDate(dateString,format);
- }
- public static long parseDate( String dateString, DateFormat []format ) {
- Date date=null;
- for(int i=0; i < format.length; i++) {
- try {
- date = format[i].parse(dateString);
- return date.getTime();
- } catch (ParseException e) { }
- catch (StringIndexOutOfBoundsException e) { }
- }
- String msg = sm.getString("httpDate.pe", dateString);
- throw new IllegalArgumentException(msg);
- }
-
-}
Modified: trunk/java/org/apache/tomcat/util/buf/MessageBytes.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/MessageBytes.java 2008-09-29 15:47:49 UTC (rev
797)
+++ trunk/java/org/apache/tomcat/util/buf/MessageBytes.java 2008-09-30 15:56:04 UTC (rev
798)
@@ -17,10 +17,8 @@
package org.apache.tomcat.util.buf;
-import java.text.*;
-import java.util.*;
-import java.io.Serializable;
import java.io.IOException;
+import java.io.Serializable;
/**
* This class is used to represent a subarray of bytes in an HTTP message.
@@ -115,7 +113,6 @@
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
- hasDateValue=false;
}
@@ -133,7 +130,6 @@
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
- hasDateValue=false;
}
/** Set the encoding. If the object was constructed from bytes[]. any
@@ -163,7 +159,6 @@
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
- hasDateValue=false;
}
/** Remove the cached string value. Use it after a conversion on the
@@ -187,7 +182,6 @@
hasHashCode=false;
hasIntValue=false;
hasLongValue=false;
- hasDateValue=false;
if (s == null) {
hasStrValue=false;
type=T_NULL;
@@ -544,34 +538,7 @@
private boolean hasIntValue=false;
private long longValue;
private boolean hasLongValue=false;
- private Date dateValue;
- private boolean hasDateValue=false;
- /**
- * @deprecated The buffer are general purpose, caching for headers should
- * be done in headers. The second parameter allows us to pass a date format
- * instance to avoid synchronization problems.
- */
- public void setTime(long t, DateFormat df) {
- // XXX replace it with a byte[] tool
- recycle();
- if( dateValue==null)
- dateValue=new Date(t);
- else
- dateValue.setTime(t);
- if( df==null )
- strValue=DateTool.format1123(dateValue);
- else
- strValue=DateTool.format1123(dateValue,df);
- hasStrValue=true;
- hasDateValue=true;
- type=T_STR;
- }
-
- public void setTime(long t) {
- setTime( t, null );
- }
-
/** Set the buffer to the representation of an int
*/
public void setInt(int i) {
@@ -611,7 +578,6 @@
hasHashCode=false;
hasIntValue=true;
hasLongValue=false;
- hasDateValue=false;
type=T_BYTES;
}
@@ -654,31 +620,9 @@
hasHashCode=false;
hasIntValue=false;
hasLongValue=true;
- hasDateValue=false;
type=T_BYTES;
}
- /**
- * @deprecated The buffer are general purpose, caching for headers should
- * be done in headers
- */
- public long getTime()
- {
- if( hasDateValue ) {
- if( dateValue==null) return -1;
- return dateValue.getTime();
- }
-
- long l=DateTool.parseDate( this );
- if( dateValue==null)
- dateValue=new Date(l);
- else
- dateValue.setTime(l);
- hasDateValue=true;
- return l;
- }
-
-
// Used for headers conversion
/** Convert the buffer to an int, cache the value
*/
Modified: trunk/java/org/apache/tomcat/util/http/ServerCookie.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/ServerCookie.java 2008-09-29 15:47:49 UTC (rev
797)
+++ trunk/java/org/apache/tomcat/util/http/ServerCookie.java 2008-09-30 15:56:04 UTC (rev
798)
@@ -23,6 +23,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
+import java.util.TimeZone;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
@@ -53,6 +54,19 @@
private int maxAge = -1;
private int version = 0;
+ // Other fields
+ private static final String OLD_COOKIE_PATTERN =
+ "EEE, dd-MMM-yyyy HH:mm:ss z";
+ private static final DateFormat OLD_COOKIE_FORMAT;
+ private static final String ancientDate;
+
+
+ static {
+ OLD_COOKIE_FORMAT = new SimpleDateFormat(OLD_COOKIE_PATTERN, Locale.US);
+ OLD_COOKIE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+ ancientDate = OLD_COOKIE_FORMAT.format(new Date(10000));
+ }
+
/**
* If set to true, we parse cookies according to the servlet spec,
*/
@@ -247,11 +261,6 @@
}
}
- private final static DateFormat oldCookieFormat =
- new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);
-
- private static final String ancientDate = oldCookieFormat.format(new Date(10000));
-
// TODO RFC2965 fields also need to be passed
public static void appendCookieValue( StringBuffer headerBuf,
int version,
@@ -262,7 +271,7 @@
String comment,
int maxAge,
boolean isSecure,
- boolean httpOnly)
+ boolean isHttpOnly)
{
StringBuffer buf = new StringBuffer();
// Servlet implementation checks name
@@ -297,16 +306,16 @@
// Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires Netscape format )
buf.append ("; Expires=");
// To expire immediately we need to set the time in past
- if (maxAge == 0) {
+ if (maxAge == 0)
buf.append( ancientDate );
- } else {
- synchronized(oldCookieFormat) {
- oldCookieFormat.format
- (new Date( System.currentTimeMillis() +
- maxAge *1000L), buf,
- new FieldPosition(0));
+ else
+ synchronized (OLD_COOKIE_FORMAT) {
+ OLD_COOKIE_FORMAT.format(
+ new Date(System.currentTimeMillis() +
+ maxAge*1000L),
+ buf, new FieldPosition(0));
}
- }
+
} else {
buf.append ("; Max-Age=");
buf.append (maxAge);
@@ -325,14 +334,13 @@
// Secure
if (isSecure) {
- buf.append ("; Secure");
+ buf.append ("; Secure");
}
// HttpOnly
- if (httpOnly) {
- buf.append ("; HttpOnly");
+ if (isHttpOnly) {
+ buf.append("; HttpOnly");
}
-
headerBuf.append(buf);
}
@@ -457,3 +465,4 @@
bc.setEnd(dest);
}
}
+
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-09-29 15:47:49 UTC (rev 797)
+++ trunk/webapps/docs/changelog.xml 2008-09-30 15:56:04 UTC (rev 798)
@@ -61,15 +61,15 @@
needed. (remm)
</fix>
<fix>
- Sync date format usage for old cookies. (remm)
- </fix>
- <fix>
<bug>45026</bug>: AJP should not use an empty reason phrase, due to
httpd 2 having a problem
with that at the moment. (rjung)
</fix>
<fix>
Allow AJP to read large body packets, up to the configured packet size. (remm)
</fix>
+ <fix>
+ Remote date tool class, since it has sync issues. (markt, remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">