cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http FastHttpDateFormat.java

2005-08-16 Thread remm
remm2005/08/16 09:52:42

  Modified:webapps/docs changelog.xml
   util/java/org/apache/tomcat/util/http
FastHttpDateFormat.java
  Log:
  - 36173: Sync.
  
  Revision  ChangesPath
  1.357 +4 -0  jakarta-tomcat-catalina/webapps/docs/changelog.xml
  
  Index: changelog.xml
  ===
  RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v
  retrieving revision 1.356
  retrieving revision 1.357
  diff -u -r1.356 -r1.357
  --- changelog.xml 16 Aug 2005 16:20:17 -  1.356
  +++ changelog.xml 16 Aug 2005 16:52:42 -  1.357
  @@ -119,6 +119,10 @@
   Security exception in APR AJP implementation when running with the 
security
   manager enabled. (remm)
 
  +  
  +36173: Add missing sync in FastHttpDateFormat.formatDate, 
submitted 
  +by Alexei (remm)
  +  

 
   
  
  
  
  1.5   +3 -1  
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
  
  Index: FastHttpDateFormat.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FastHttpDateFormat.java   24 Feb 2004 08:50:04 -  1.4
  +++ FastHttpDateFormat.java   16 Aug 2005 16:52:42 -  1.5
  @@ -139,7 +139,9 @@
   }
   } else {
   synchronized (formatCache) {
  -newDate = format.format(dateValue);
  +synchronized (format) {
  +newDate = format.format(dateValue);
  +}
   updateCache(formatCache, longValue, newDate);
   }
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http FastHttpDateFormat.java

2003-01-04 Thread remm
remm2003/01/04 04:42:33

  Modified:util/java/org/apache/tomcat/util/http
FastHttpDateFormat.java
  Log:
  - Fix caching bug (caused by cut and paste abuse).
  
  Revision  ChangesPath
  1.3   +1 -1  
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
  
  Index: FastHttpDateFormat.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FastHttpDateFormat.java   3 Jan 2003 19:31:00 -   1.2
  +++ FastHttpDateFormat.java   4 Jan 2003 12:42:33 -   1.3
  @@ -199,7 +199,7 @@
   
   Long cachedDate = null;
   try {
  -cachedDate = (Long) formatCache.get(value);
  +cachedDate = (Long) parseCache.get(value);
   } catch (Exception e) {
   }
   if (cachedDate != null)
  
  
  

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http FastHttpDateFormat.java

2003-01-03 Thread remm
remm2003/01/03 11:31:00

  Modified:util/java/org/apache/tomcat/util/http
FastHttpDateFormat.java
  Log:
  - Major update to the cache (also handles parsing now).
  
  Revision  ChangesPath
  1.2   +117 -9
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
  
  Index: FastHttpDateFormat.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FastHttpDateFormat.java   9 Jan 2002 23:23:24 -   1.1
  +++ FastHttpDateFormat.java   3 Jan 2003 19:31:00 -   1.2
  @@ -63,6 +63,8 @@
   import java.util.HashMap;
   import java.util.Locale;
   import java.util.TimeZone;
  +import java.text.DateFormat;
  +import java.text.ParseException;
   import java.text.SimpleDateFormat;
   
   /**
  @@ -79,10 +81,20 @@
   /**
* HTTP date format.
*/
  -protected static SimpleDateFormat format = 
  +protected static final SimpleDateFormat format = 
   new SimpleDateFormat("EEE, dd MMM  HH:mm:ss zzz", Locale.US);
   
   
  +/**
  + * The set of SimpleDateFormat formats to use in getDateHeader().
  + */
  +protected static final SimpleDateFormat formats[] = {
  +new SimpleDateFormat("EEE, dd MMM  HH:mm:ss zzz", Locale.US),
  +new SimpleDateFormat("EE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
  +new SimpleDateFormat("EEE  d HH:mm:ss ", Locale.US)
  +};
  +
  +
   protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT");
   
   
  @@ -90,7 +102,13 @@
* GMT timezone - all HTTP dates are on GMT
*/
   static {
  +
   format.setTimeZone(gmtZone);
  +
  +formats[0].setTimeZone(gmtZone);
  +formats[1].setTimeZone(gmtZone);
  +formats[2].setTimeZone(gmtZone);
  +
   }
   
   
  @@ -107,9 +125,15 @@
   
   
   /**
  - * Date cache.
  + * Formatter cache.
  + */
  +protected static final HashMap formatCache = new HashMap();
  +
  +
  +/**
  + * Parser cache.
*/
  -protected static HashMap dateCache = new HashMap();
  +protected static final HashMap parseCache = new HashMap();
   
   
   // - Public Methods
  @@ -118,7 +142,7 @@
   /**
* Get the current date in HTTP format.
*/
  -public static String getCurrentDate() {
  +public static final String getCurrentDate() {
   
   long now = System.currentTimeMillis();
   if ((now - currentDateGenerated) > 1000) {
  @@ -137,19 +161,103 @@
   /**
* Get the HTTP format of the specified date.
*/
  -public static String getDate(Date date) {
  +public static final String formatDate
  +(long value, DateFormat threadLocalformat) {
   
  -String cachedDate = (String) dateCache.get(date);
  +String cachedDate = null;
  +Long longValue = new Long(value);
  +try {
  +cachedDate = (String) formatCache.get(longValue);
  +} catch (Exception e) {
  +}
   if (cachedDate != null)
   return cachedDate;
   
   String newDate = null;
  -synchronized (format) {
  -newDate = format.format(date);
  -dateCache.put(date, newDate);
  +Date dateValue = new Date(value);
  +if (threadLocalformat != null) {
  +newDate = threadLocalformat.format(dateValue);
  +synchronized (formatCache) {
  +updateCache(formatCache, longValue, newDate);
  +}
  +} else {
  +synchronized (formatCache) {
  +newDate = format.format(dateValue);
  +updateCache(formatCache, longValue, newDate);
  +}
   }
   return newDate;
   
  +}
  +
  +
  +/**
  + * Try to parse the given date as a HTTP date.
  + */
  +public static final long parseDate(String value, 
  +   DateFormat[] threadLocalformats) {
  +
  +Long cachedDate = null;
  +try {
  +cachedDate = (Long) formatCache.get(value);
  +} catch (Exception e) {
  +}
  +if (cachedDate != null)
  +return cachedDate.longValue();
  +
  +Long date = null;
  +if (threadLocalformats != null) {
  +date = internalParseDate(value, threadLocalformats);
  +synchronized (parseCache) {
  +updateCache(parseCache, value, date);
  +}
  +} else {
  +synchronized (parseCache) {
  +date = internalParseDate(value, formats);
  +updateCache(parseCache, value, date);
  +}

cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http FastHttpDateFormat.java

2002-01-09 Thread remm

remm02/01/09 15:23:24

  Modified:util/java/org/apache/tomcat/util/buf HexUtils.java
  Added:   util/java/org/apache/tomcat/util/http
FastHttpDateFormat.java
  Log:
  - Add the fast HTTP date generator, from Catalina.
  - Add a contant array to the HexTools, to do dec -> hex conversion.
  
  Revision  ChangesPath
  1.5   +20 -4 
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/HexUtils.java
  
  Index: HexUtils.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/HexUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HexUtils.java 31 Dec 2001 18:20:04 -  1.4
  +++ HexUtils.java 9 Jan 2002 23:23:24 -   1.5
  @@ -66,14 +66,20 @@
   /**
* Library of utility methods useful in dealing with converting byte arrays
* to and from strings of hexadecimal digits.
  + * Code from Ajp11, from Apache's JServ.
*
* @author Craig R. McClanahan
*/
   
   public final class HexUtils {
  -// Code from Ajp11, from Apache's JServ
  -
  -// Table for HEX to DEC byte translation
  +
  +
  +// -- Constants
  +
  +
  +/**
  + *  Table for HEX to DEC byte translation.
  + */
   public static final int[] DEC = {
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  @@ -92,7 +98,14 @@
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
   };
  -
  +
  +
  +/**
  + * Table for DEC to HEX byte translation.
  + */
  +public static final byte[] HEX = 
  +{ '0', '1', '2', '3', '4', '5', '6', 
  +  '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
   
   
   /**
  @@ -100,6 +113,9 @@
*/
   private static StringManager sm =
StringManager.getManager("org.apache.tomcat.util.buf.res");
  +
  +
  +// - Static Methods
   
   
   /**
  
  
  
  1.1  
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
  
  Index: FastHttpDateFormat.java
  ===
  /*
   * 
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *notice, this list of conditions and the following disclaimer in
   *the documentation and/or other materials provided with the
   *distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *any, must include the following acknowlegement:  
   *   "This product includes software developed by the 
   *Apache Software Foundation (http://www.apache.org/)."
   *Alternately, this acknowlegement may appear in the software itself,
   *if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *Foundation" must not be used to endorse or promote products derived
   *from this software without prior written permission. For written 
   *permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *nor may "Apache" appear in their names without prior written
   *permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ===