From 8fc5ae431b3372cac0cb6b8dd80f9a31f8a8ad55 Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 29 May 2008 21:32:02 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45101 Format dates for header value from DirContextURLConnection using HTTP format. Patch provided by Chris Hubick. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@661488 13f79535-47bb-0310-9956-ffa450edef68 --- .../naming/resources/DirContextURLConnection.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/java/org/apache/naming/resources/DirContextURLConnection.java b/java/org/apache/naming/resources/DirContextURLConnection.java index d7d8efb69..35c4c7358 100644 --- a/java/org/apache/naming/resources/DirContextURLConnection.java +++ b/java/org/apache/naming/resources/DirContextURLConnection.java @@ -39,6 +39,7 @@ import javax.naming.directory.Attributes; import org.apache.naming.JndiPermission; import org.apache.naming.resources.Resource; import org.apache.naming.resources.ResourceAttributes; +import org.apache.tomcat.util.http.FastHttpDateFormat; /** * Connection to a JNDI directory context. @@ -222,6 +223,18 @@ public class DirContextURLConnection } + protected String getHeaderValueAsString(Object headerValue) { + if (headerValue == null) return null; + if (headerValue instanceof Date) { + // return date strings (ie Last-Modified) in HTTP format, rather + // than Java format + return FastHttpDateFormat.formatDate( + ((Date)headerValue).getTime(), null); + } + return headerValue.toString(); + } + + /** * Returns an unmodifiable Map of the header fields. */ @@ -248,7 +261,8 @@ public class DirContextURLConnection ArrayList attributeValueList = new ArrayList(attribute.size()); NamingEnumeration attributeValues = attribute.getAll(); while (attributeValues.hasMore()) { - attributeValueList.add(attributeValues.next().toString()); + Object attrValue = attributeValues.next(); + attributeValueList.add(getHeaderValueAsString(attrValue)); } attributeValueList.trimToSize(); // should be a no-op if attribute.size() didn't lie headerFields.put(attributeID, Collections.unmodifiableList(attributeValueList)); @@ -285,7 +299,8 @@ public class DirContextURLConnection if (attributeID.equalsIgnoreCase(name)) { Attribute attribute = attributes.get(attributeID); if (attribute == null) return null; - return attribute.get(attribute.size()-1).toString(); + Object attrValue = attribute.get(attribute.size()-1); + return getHeaderValueAsString(attrValue); } } } catch (NamingException ne) { -- 2.11.0