You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/30 13:08:47 UTC

[tomcat] branch 7.0.x updated (2fb5a89 -> 1a772c4)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 2fb5a89  Add release date for 7.0.96
     new f852fb1  Prep for additional backports. Align with 8.5.x.
     new b61da62  Align with 8.5.x. Deprecate.
     new 24ebf35  Align with master. Spacing, Javadoc, remove unnecessary (...)
     new a846e4a  Deprecate FastDateFormat.RFC1123_DATE
     new e25eb15  Refactor to remove duplicate code
     new 1a772c4  Deprecate FastHttpDateFormat.formatDate(long, DateFormat)

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../catalina/authenticator/AuthenticatorBase.java  |   5 +-
 java/org/apache/catalina/connector/Request.java    |  46 ++-
 java/org/apache/catalina/connector/Response.java   | 179 ++++-----
 .../apache/catalina/servlets/WebdavServlet.java    | 421 ++++++---------------
 .../apache/catalina/util/ConcurrentDateFormat.java |   4 +
 .../util/http}/ConcurrentDateFormat.java           |  18 +-
 .../tomcat/util/http/FastHttpDateFormat.java       | 149 ++++----
 7 files changed, 304 insertions(+), 518 deletions(-)
 copy java/org/apache/{naming/resources => tomcat/util/http}/ConcurrentDateFormat.java (81%)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 03/06: Align with master. Spacing, Javadoc, remove unnecessary (...)

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 24ebf35f082e0198a5c3b6bc83e1c1becc305588
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 20:53:41 2019 +0100

    Align with master. Spacing, Javadoc, remove unnecessary (...)
---
 java/org/apache/catalina/connector/Request.java  |  14 +-
 java/org/apache/catalina/connector/Response.java | 157 +++++++++++++----------
 2 files changed, 91 insertions(+), 80 deletions(-)

diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java
index 71e381e..11c64bb 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -16,7 +16,6 @@
  */
 package org.apache.catalina.connector;
 
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
@@ -113,16 +112,13 @@ import org.ietf.jgss.GSSException;
  * @author Remy Maucherat
  * @author Craig R. McClanahan
  */
-public class Request
-implements HttpServletRequest {
+public class Request implements HttpServletRequest {
 
     private static final Log log = LogFactory.getLog(Request.class);
 
     // ----------------------------------------------------------- Constructors
 
-
     public Request() {
-
         formats[0].setTimeZone(GMT_ZONE);
         formats[1].setTimeZone(GMT_ZONE);
         formats[2].setTimeZone(GMT_ZONE);
@@ -160,7 +156,6 @@ implements HttpServletRequest {
 
     // ----------------------------------------------------- Variables
 
-
     protected static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
 
 
@@ -2775,10 +2770,7 @@ implements HttpServletRequest {
     }
 
     /**
-     * @throws IOException If an I/O error occurs
-     * @throws IllegalStateException If the response has been committed
-     * @throws ServletException If the caller is responsible for handling the
-     *         error and the container has NOT set the HTTP response code etc.
+     * {@inheritDoc}
      */
     @Override
     public boolean authenticate(HttpServletResponse response)
@@ -2949,7 +2941,7 @@ implements HttpServletRequest {
                             try {
                                 value = part.getString(Parameters.DEFAULT_ENCODING);
                             } catch (UnsupportedEncodingException e) {
-                                // Should not be possible
+                                // Not possible
                             }
                         }
                         if (maxPostSize >= 0) {
diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java
index 539fe6b..1d45bf7 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -32,7 +32,6 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
-import java.util.Vector;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.SessionTrackingMode;
@@ -155,18 +154,18 @@ public class Response implements HttpServletResponse {
     }
 
     /**
-     * Get the Coyote response.
+     * @return the Coyote response.
      */
     public org.apache.coyote.Response getCoyoteResponse() {
-        return (coyoteResponse);
+        return this.coyoteResponse;
     }
 
 
     /**
-     * Return the Context within which this Request is being processed.
+     * @return the Context within which this Request is being processed.
      */
     public Context getContext() {
-        return (request.getContext());
+        return request.getContext();
     }
 
     /**
@@ -245,7 +244,6 @@ public class Response implements HttpServletResponse {
 
     // --------------------------------------------------------- Public Methods
 
-
     /**
      * Release all object references, and initialize instance variables, in
      * preparation for reuse of this object.
@@ -289,9 +287,8 @@ public class Response implements HttpServletResponse {
 
     // ------------------------------------------------------- Response Methods
 
-
     /**
-     * Return the number of bytes the application has actually written to the
+     * @return the number of bytes the application has actually written to the
      * output stream. This excludes chunking, compression, etc. as well as
      * headers.
      */
@@ -301,8 +298,9 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the number of bytes the actually written to the socket. This
+     * @return the number of bytes the actually written to the socket. This
      * includes chunking, compression, etc. but excludes headers.
+     * @param flush if <code>true</code> will perform a buffer flush first
      */
     public long getBytesWritten(boolean flush) {
         if (flush) {
@@ -327,11 +325,13 @@ public class Response implements HttpServletResponse {
 
     /**
      * Application commit flag accessor.
+     *
+     * @return <code>true</code> if the application has committed the response
      */
     public boolean isAppCommitted() {
-        return (this.appCommitted || isCommitted() || isSuspended()
+        return this.appCommitted || isCommitted() || isSuspended()
                 || ((getContentLength() > 0)
-                    && (getContentWritten() >= getContentLength())));
+                    && (getContentWritten() >= getContentLength()));
     }
 
 
@@ -372,10 +372,10 @@ public class Response implements HttpServletResponse {
     protected Request request = null;
 
     /**
-     * Return the Request with which this Response is associated.
+     * @return the Request with which this Response is associated.
      */
     public org.apache.catalina.connector.Request getRequest() {
-        return (this.request);
+        return this.request;
     }
 
     /**
@@ -393,15 +393,16 @@ public class Response implements HttpServletResponse {
      */
     protected ResponseFacade facade = null;
 
+
     /**
-     * Return the <code>ServletResponse</code> for which this object
+     * @return the <code>ServletResponse</code> for which this object
      * is the facade.
      */
     public HttpServletResponse getResponse() {
         if (facade == null) {
             facade = new ResponseFacade(this);
         }
-        return (facade);
+        return facade;
     }
 
 
@@ -429,6 +430,8 @@ public class Response implements HttpServletResponse {
 
     /**
      * Suspended flag accessor.
+     *
+     * @return <code>true</code> if the response is suspended
      */
     public boolean isSuspended() {
         return outputBuffer.isSuspended();
@@ -437,6 +440,8 @@ public class Response implements HttpServletResponse {
 
     /**
      * Closed flag accessor.
+     *
+     * @return <code>true</code> if the response has been closed
      */
     public boolean isClosed() {
         return outputBuffer.isClosed();
@@ -445,6 +450,8 @@ public class Response implements HttpServletResponse {
 
     /**
      * Set the error flag.
+     *
+     * @return <code>false</code> if the error flag was already set
      */
     public boolean setError() {
         boolean result = getCoyoteResponse().setError();
@@ -460,6 +467,8 @@ public class Response implements HttpServletResponse {
 
     /**
      * Error flag accessor.
+     *
+     * @return <code>true</code> if the response has encountered an error
      */
     public boolean isError() {
         return getCoyoteResponse().isError();
@@ -506,7 +515,7 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the content length that was set or calculated for this Response.
+     * @return the content length that was set or calculated for this Response.
      */
     public int getContentLength() {
         return getCoyoteResponse().getContentLength();
@@ -514,7 +523,7 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the content type that was set or calculated for this response,
+     * @return the content type that was set or calculated for this response,
      * or <code>null</code> if no content type was set.
      */
     @Override
@@ -563,7 +572,7 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the actual buffer size used for this Response.
+     * @return the actual buffer size used for this Response.
      */
     @Override
     public int getBufferSize() {
@@ -572,16 +581,16 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the character encoding used for this Response.
+     * @return the character encoding used for this Response.
      */
     @Override
     public String getCharacterEncoding() {
-        return (getCoyoteResponse().getCharacterEncoding());
+        return getCoyoteResponse().getCharacterEncoding();
     }
 
 
     /**
-     * Return the servlet output stream associated with this Response.
+     * @return the servlet output stream associated with this Response.
      *
      * @exception IllegalStateException if <code>getWriter</code> has
      *  already been called for this response
@@ -606,16 +615,16 @@ public class Response implements HttpServletResponse {
 
 
     /**
-     * Return the Locale assigned to this response.
+     * @return the Locale assigned to this response.
      */
     @Override
     public Locale getLocale() {
-        return (getCoyoteResponse().getLocale());
+        return getCoyoteResponse().getLocale();
     }
 
 
     /**
-     * Return the writer associated with this Response.
+     * @return the writer associated with this Response.
      *
      * @exception IllegalStateException if <code>getOutputStream</code> has
      *  already been called for this response
@@ -657,6 +666,8 @@ public class Response implements HttpServletResponse {
 
     /**
      * Has the output of this response already been committed?
+     *
+     * @return <code>true</code> if the response has been committed
      */
     @Override
     public boolean isCommitted() {
@@ -765,7 +776,6 @@ public class Response implements HttpServletResponse {
         }
 
         getCoyoteResponse().setContentLength(length);
-
     }
 
 
@@ -811,7 +821,7 @@ public class Response implements HttpServletResponse {
     }
 
 
-    /*
+    /**
      * Overrides the name of the character encoding used in the body
      * of the request. This method must be called prior to reading
      * request parameters or reading input using getReader().
@@ -889,7 +899,6 @@ public class Response implements HttpServletResponse {
 
     @Override
     public Collection<String> getHeaderNames() {
-
         MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
         int n = headers.size();
         List<String> result = new ArrayList<String>(n);
@@ -903,19 +912,18 @@ public class Response implements HttpServletResponse {
 
     @Override
     public Collection<String> getHeaders(String name) {
-
         Enumeration<String> enumeration =
                 getCoyoteResponse().getMimeHeaders().values(name);
-        Vector<String> result = new Vector<String>();
+        List<String> result = new ArrayList<String>();
         while (enumeration.hasMoreElements()) {
-            result.addElement(enumeration.nextElement());
+            result.add(enumeration.nextElement());
         }
         return result;
     }
 
 
     /**
-     * Return the error message that was set with <code>sendError()</code>
+     * @return the error message that was set with <code>sendError()</code>
      * for this Response.
      */
     public String getMessage() {
@@ -945,7 +953,6 @@ public class Response implements HttpServletResponse {
 
     // -------------------------------------------- HttpServletResponse Methods
 
-
     /**
      * Add the specified Cookie to those that will be included with
      * this Response.
@@ -970,8 +977,9 @@ public class Response implements HttpServletResponse {
 
     /**
      * Special method for adding a session cookie as we should be overriding
-     * any previous
-     * @param cookie
+     * any previous.
+     *
+     * @param cookie The new session cookie to add the response
      */
     public void addSessionCookieInternal(final Cookie cookie) {
         if (isCommitted()) {
@@ -1100,7 +1108,7 @@ public class Response implements HttpServletResponse {
      * visible to {@link org.apache.coyote.Response}
      *
      * Called from set/addHeader.
-     * Return true if the header is special, no need to set the header.
+     * @return <code>true</code> if the header is special, no need to set the header.
      */
     private boolean checkSpecialHeader(String name, String value) {
         if (name.equalsIgnoreCase("Content-Type")) {
@@ -1142,6 +1150,7 @@ public class Response implements HttpServletResponse {
      * Has the specified header been set already in this response?
      *
      * @param name Name of the header to check
+     * @return <code>true</code> if the header has been set
      */
     @Override
     public boolean containsHeader(String name) {
@@ -1168,16 +1177,15 @@ public class Response implements HttpServletResponse {
      * into the specified redirect URL, if necessary.
      *
      * @param url URL to be encoded
+     * @return <code>true</code> if the URL was encoded
      */
     @Override
     public String encodeRedirectURL(String url) {
-
         if (isEncodeable(toAbsolute(url))) {
-            return (toEncoded(url, request.getSessionInternal().getIdInternal()));
+            return toEncoded(url, request.getSessionInternal().getIdInternal());
         } else {
-            return (url);
+            return url;
         }
-
     }
 
 
@@ -1186,6 +1194,7 @@ public class Response implements HttpServletResponse {
      * into the specified redirect URL, if necessary.
      *
      * @param url URL to be encoded
+     * @return <code>true</code> if the URL was encoded
      *
      * @deprecated As of Version 2.1 of the Java Servlet API, use
      *  <code>encodeRedirectURL()</code> instead.
@@ -1193,7 +1202,7 @@ public class Response implements HttpServletResponse {
     @Override
     @Deprecated
     public String encodeRedirectUrl(String url) {
-        return (encodeRedirectURL(url));
+        return encodeRedirectURL(url);
     }
 
 
@@ -1202,6 +1211,7 @@ public class Response implements HttpServletResponse {
      * into the specified URL, if necessary.
      *
      * @param url URL to be encoded
+     * @return <code>true</code> if the URL was encoded
      */
     @Override
     public String encodeURL(String url) {
@@ -1221,9 +1231,9 @@ public class Response implements HttpServletResponse {
             } else if (url.equals(absolute) && !hasPath(url)) {
                 url += '/';
             }
-            return (toEncoded(url, request.getSessionInternal().getIdInternal()));
+            return toEncoded(url, request.getSessionInternal().getIdInternal());
         } else {
-            return (url);
+            return url;
         }
 
     }
@@ -1234,6 +1244,7 @@ public class Response implements HttpServletResponse {
      * into the specified URL, if necessary.
      *
      * @param url URL to be encoded
+     * @return <code>true</code> if the URL was encoded
      *
      * @deprecated As of Version 2.1 of the Java Servlet API, use
      *  <code>encodeURL()</code> instead.
@@ -1241,12 +1252,12 @@ public class Response implements HttpServletResponse {
     @Override
     @Deprecated
     public String encodeUrl(String url) {
-        return (encodeURL(url));
+        return encodeURL(url);
     }
 
 
     /**
-     * Send an acknowledgment of a request.
+     * Send an acknowledgement of a request.
      *
      * @exception IOException if an input/output error occurs
      */
@@ -1337,6 +1348,10 @@ public class Response implements HttpServletResponse {
      * Internal method that allows a redirect to be sent with a status other
      * than {@link HttpServletResponse#SC_FOUND} (302). No attempt is made to
      * validate the status code.
+     *
+     * @param location Location URL to redirect to
+     * @param status HTTP status code that will be sent
+     * @throws IOException an IO exception occurred
      */
     public void sendRedirect(String location, int status) throws IOException {
         if (isCommitted()) {
@@ -1435,8 +1450,9 @@ public class Response implements HttpServletResponse {
 
         char cc=name.charAt(0);
         if (cc=='C' || cc=='c') {
-            if (checkSpecialHeader(name, value))
-            return;
+            if (checkSpecialHeader(name, value)) {
+                return;
+            }
         }
 
         getCoyoteResponse().setHeader(name, value);
@@ -1512,7 +1528,6 @@ public class Response implements HttpServletResponse {
 
     // ------------------------------------------------------ Protected Methods
 
-
     /**
      * Return <code>true</code> if the specified URL should be encoded with
      * a session identifier.  This will be true if all of the following
@@ -1525,26 +1540,27 @@ public class Response implements HttpServletResponse {
      * </ul>
      *
      * @param location Absolute URL to be validated
+     * @return <code>true</code> if the URL should be encoded
      */
     protected boolean isEncodeable(final String location) {
 
         if (location == null) {
-            return (false);
+            return false;
         }
 
         // Is this an intra-document reference?
         if (location.startsWith("#")) {
-            return (false);
+            return false;
         }
 
         // Are we in a valid session that is not using cookies?
         final Request hreq = request;
         final Session session = hreq.getSessionInternal(false);
         if (session == null) {
-            return (false);
+            return false;
         }
         if (hreq.isRequestedSessionIdFromCookie()) {
-            return (false);
+            return false;
         }
 
         // Is URL encoding permitted
@@ -1574,15 +1590,15 @@ public class Response implements HttpServletResponse {
         try {
             url = new URL(location);
         } catch (MalformedURLException e) {
-            return (false);
+            return false;
         }
 
         // Does this URL match down to (and including) the context path?
         if (!hreq.getScheme().equalsIgnoreCase(url.getProtocol())) {
-            return (false);
+            return false;
         }
         if (!hreq.getServerName().equalsIgnoreCase(url.getHost())) {
-            return (false);
+            return false;
         }
         int serverPort = hreq.getServerPort();
         if (serverPort == -1) {
@@ -1601,25 +1617,25 @@ public class Response implements HttpServletResponse {
             }
         }
         if (serverPort != urlPort) {
-            return (false);
+            return false;
         }
 
         String contextPath = getContext().getPath();
         if (contextPath != null) {
             String file = url.getFile();
             if (!file.startsWith(contextPath)) {
-                return (false);
+                return false;
             }
             String tok = ";" +
                     SessionConfig.getSessionUriParamName(request.getContext()) +
                     "=" + session.getIdInternal();
             if( file.indexOf(tok, contextPath.length()) >= 0 ) {
-                return (false);
+                return false;
             }
         }
 
         // This URL belongs to our web application, so it is encodeable
-        return (true);
+        return true;
 
     }
 
@@ -1630,6 +1646,7 @@ public class Response implements HttpServletResponse {
      * already absolute, return it unchanged.
      *
      * @param location URL to be (possibly) converted and then returned
+     * @return the encoded URL
      *
      * @exception IllegalArgumentException if a MalformedURLException is
      *  thrown when converting the relative URL to an absolute one
@@ -1637,7 +1654,7 @@ public class Response implements HttpServletResponse {
     protected String toAbsolute(String location) {
 
         if (location == null) {
-            return (location);
+            return location;
         }
 
         boolean leadingSlash = location.startsWith("/");
@@ -1719,15 +1736,17 @@ public class Response implements HttpServletResponse {
 
         } else {
 
-            return (location);
+            return location;
 
         }
 
     }
 
-    /*
+    /**
      * Removes /./ and /../ sequences from absolute URLs.
      * Code borrowed heavily from CoyoteAdapter.normalize()
+     *
+     * @param cc the char chunk containing the chars to normalize
      */
     private void normalize(CharChunk cc) {
         // Strip query string and/or fragment first as doing it this way makes
@@ -1813,14 +1832,15 @@ public class Response implements HttpServletResponse {
     }
 
     private void copyChars(char[] c, int dest, int src, int len) {
-        for (int pos = 0; pos < len; pos++) {
-            c[pos + dest] = c[pos + src];
-        }
+        System.arraycopy(c, src, c, dest, len);
     }
 
 
     /**
-     * Determine if an absolute URL has a path component
+     * Determine if an absolute URL has a path component.
+     *
+     * @param uri the URL that will be checked
+     * @return <code>true</code> if the URL has a path
      */
     private boolean hasPath(String uri) {
         int pos = uri.indexOf("://");
@@ -1856,11 +1876,11 @@ public class Response implements HttpServletResponse {
      *
      * @param url URL to be encoded with the session id
      * @param sessionId Session id to be included in the encoded URL
+     * @return the encoded URL
      */
     protected String toEncoded(String url, String sessionId) {
-
         if ((url == null) || (sessionId == null)) {
-            return (url);
+            return url;
         }
 
         String path = url;
@@ -1886,7 +1906,6 @@ public class Response implements HttpServletResponse {
         }
         sb.append(anchor);
         sb.append(query);
-        return (sb.toString());
-
+        return sb.toString();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 04/06: Deprecate FastDateFormat.RFC1123_DATE

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit a846e4abf0b5b6307c34c52c1063dca4d3526354
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 21:05:19 2019 +0100

    Deprecate FastDateFormat.RFC1123_DATE
---
 java/org/apache/catalina/connector/Request.java    | 32 ++++++++++++++++------
 java/org/apache/catalina/connector/Response.java   | 22 ++++-----------
 .../tomcat/util/http/FastHttpDateFormat.java       |  3 ++
 3 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java
index 11c64bb..53f3925 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -119,10 +119,10 @@ public class Request implements HttpServletRequest {
     // ----------------------------------------------------------- Constructors
 
     public Request() {
-        formats[0].setTimeZone(GMT_ZONE);
-        formats[1].setTimeZone(GMT_ZONE);
-        formats[2].setTimeZone(GMT_ZONE);
-
+        formats = new SimpleDateFormat[formatsTemplate.length];
+        for(int i = 0; i < formats.length; i++) {
+            formats[i] = (SimpleDateFormat) formatsTemplate[i].clone();
+        }
     }
 
 
@@ -156,6 +156,10 @@ public class Request implements HttpServletRequest {
 
     // ----------------------------------------------------- Variables
 
+    /**
+     * @deprecated Unused. This will be removed in Tomcat 10.
+     */
+    @Deprecated
     protected static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
 
 
@@ -176,11 +180,17 @@ public class Request implements HttpServletRequest {
      *
      * Notice that because SimpleDateFormat is not thread-safe, we can't
      * declare formats[] as a static variable.
+     *
+     * @deprecated Unused. This will be removed in Tomcat 10
      */
-    protected SimpleDateFormat formats[] = {
-            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", 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)
+    @Deprecated
+    protected final SimpleDateFormat formats[];
+
+    @Deprecated
+    private static final SimpleDateFormat formatsTemplate[] = {
+        new SimpleDateFormat(FastHttpDateFormat.RFC1123_DATE, 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)
     };
 
 
@@ -2231,7 +2241,7 @@ public class Request implements HttpServletRequest {
         }
 
         // Attempt to convert the date header in a variety of formats
-        long result = FastHttpDateFormat.parseDate(value, formats);
+        long result = FastHttpDateFormat.parseDate(value);
         if (result != (-1L)) {
             return result;
         }
@@ -3663,5 +3673,9 @@ public class Request implements HttpServletRequest {
                         // NO-OP
                     }
                 });
+
+        for (SimpleDateFormat sdf : formatsTemplate) {
+            sdf.setTimeZone(GMT_ZONE);
+        }
     }
 }
diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java
index 1d45bf7..2d5c558 100644
--- a/java/org/apache/catalina/connector/Response.java
+++ b/java/org/apache/catalina/connector/Response.java
@@ -31,7 +31,6 @@ import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Locale;
-import java.util.TimeZone;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.SessionTrackingMode;
@@ -43,7 +42,6 @@ import org.apache.catalina.Globals;
 import org.apache.catalina.Session;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.security.SecurityUtil;
-import org.apache.catalina.util.DateTool;
 import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.SessionConfig;
 import org.apache.juli.logging.Log;
@@ -98,7 +96,10 @@ public class Response implements HttpServletResponse {
 
     /**
      * The date format we will use for creating date headers.
+     *
+     * @deprecated Unused. This will be removed in Tomcat 10
      */
+    @Deprecated
     protected SimpleDateFormat format = null;
 
 
@@ -1058,14 +1059,7 @@ public class Response implements HttpServletResponse {
             return;
         }
 
-        if (format == null) {
-            format = new SimpleDateFormat(DateTool.HTTP_RESPONSE_DATE_HEADER,
-                                          Locale.US);
-            format.setTimeZone(TimeZone.getTimeZone("GMT"));
-        }
-
-        addHeader(name, FastHttpDateFormat.formatDate(value, format));
-
+        addHeader(name, FastHttpDateFormat.formatDate(value));
     }
 
 
@@ -1416,13 +1410,7 @@ public class Response implements HttpServletResponse {
             return;
         }
 
-        if (format == null) {
-            format = new SimpleDateFormat(DateTool.HTTP_RESPONSE_DATE_HEADER,
-                                          Locale.US);
-            format.setTimeZone(TimeZone.getTimeZone("GMT"));
-        }
-
-        setHeader(name, FastHttpDateFormat.formatDate(value, format));
+        setHeader(name, FastHttpDateFormat.formatDate(value));
     }
 
 
diff --git a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
index 4f787a2..66a767a 100644
--- a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
+++ b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
@@ -41,7 +41,10 @@ public final class FastHttpDateFormat {
 
     /**
      * The only date format permitted when generating HTTP headers.
+     *
+     * @deprecated Unused. This will be removed in Tomcat 10.
      */
+    @Deprecated
     public static final String RFC1123_DATE = "EEE, dd MMM yyyy HH:mm:ss zzz";
 
     // HTTP date formats


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 06/06: Deprecate FastHttpDateFormat.formatDate(long, DateFormat)

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 1a772c43e3d13791464af5a3bf8141ff08e1d219
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 21:32:28 2019 +0100

    Deprecate FastHttpDateFormat.formatDate(long, DateFormat)
---
 java/org/apache/catalina/servlets/WebdavServlet.java     | 6 +++---
 java/org/apache/tomcat/util/http/FastHttpDateFormat.java | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java
index 54ef218..ebe86f2 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -2199,7 +2199,7 @@ public class WebdavServlet extends DefaultServlet {
             generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
             if (isFile) {
                 generatedXML.writeProperty("D", "getlastmodified",
-                        FastHttpDateFormat.formatDate(lastModified, null));
+                        FastHttpDateFormat.formatDate(lastModified));
                 generatedXML.writeProperty("D", "getcontentlength", Long.toString(contentLength));
                 if (contentType != null) {
                     generatedXML.writeProperty("D", "getcontenttype", contentType);
@@ -2317,7 +2317,7 @@ public class WebdavServlet extends DefaultServlet {
                 } else if (property.equals("getlastmodified")) {
                     if (isFile) {
                         generatedXML.writeProperty("D", "getlastmodified",
-                                FastHttpDateFormat.formatDate(lastModified, null));
+                                FastHttpDateFormat.formatDate(lastModified));
                     } else {
                         propertiesNotFound.addElement(property);
                     }
@@ -2541,7 +2541,7 @@ public class WebdavServlet extends DefaultServlet {
             result.append("\nOwner:");
             result.append(owner);
             result.append("\nExpiration:");
-            result.append(FastHttpDateFormat.formatDate(expiresAt, null));
+            result.append(FastHttpDateFormat.formatDate(expiresAt));
             Enumeration<String> tokensList = tokens.elements();
             while (tokensList.hasMoreElements()) {
                 result.append("\nToken:");
diff --git a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
index 66a767a..11e7f31 100644
--- a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
+++ b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
@@ -117,7 +117,10 @@ public final class FastHttpDateFormat {
      * @param threadLocalformat Ignored. The local ConcurrentDateFormat will
      *                          always be used.
      * @return the HTTP date
+     *
+     * @deprecated Unused. This will be removed in Tomcat 10
      */
+    @Deprecated
     public static final String formatDate(long value, DateFormat threadLocalformat) {
         return formatDate(value);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 05/06: Refactor to remove duplicate code

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit e25eb1550f2d5df7b1fb8b0fc30a3e0923977fe1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 21:30:19 2019 +0100

    Refactor to remove duplicate code
---
 .../apache/catalina/servlets/WebdavServlet.java    | 417 ++++++---------------
 1 file changed, 105 insertions(+), 312 deletions(-)

diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java
index 2b677d3..54ef218 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -2110,13 +2110,6 @@ public class WebdavServlet extends DefaultServlet {
             return;
         }
 
-        generatedXML.writeElement("D", "response", XMLWriter.OPENING);
-        String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " +
-                WebdavStatus.getStatusText(WebdavStatus.SC_OK);
-
-        // Generating href element
-        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
-
         String href = req.getContextPath() + req.getServletPath();
         if ((href.endsWith("/")) && (path.startsWith("/")))
             href += path.substring(1);
@@ -2125,246 +2118,12 @@ public class WebdavServlet extends DefaultServlet {
         if ((cacheEntry.context != null) && (!href.endsWith("/")))
             href += "/";
 
-        generatedXML.writeText(rewriteUrl(href));
-
-        generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
-
-        String resourceName = path;
-        int lastSlash = path.lastIndexOf('/');
-        if (lastSlash != -1)
-            resourceName = resourceName.substring(lastSlash + 1);
-
-        switch (type) {
-
-        case FIND_ALL_PROP :
-
-            generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
-            generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
-
-            generatedXML.writeProperty("D", "creationdate",
-                    getISOCreationDate(cacheEntry.attributes.getCreation()));
-            generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
-            generatedXML.writeData(resourceName);
-            generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
-            if (cacheEntry.resource != null) {
-                generatedXML.writeProperty
-                    ("D", "getlastmodified", FastHttpDateFormat.formatDate
-                           (cacheEntry.attributes.getLastModified(), null));
-                generatedXML.writeProperty
-                    ("D", "getcontentlength",
-                     String.valueOf(cacheEntry.attributes.getContentLength()));
-                String contentType = getServletContext().getMimeType
-                    (cacheEntry.name);
-                if (contentType != null) {
-                    generatedXML.writeProperty("D", "getcontenttype",
-                            contentType);
-                }
-                generatedXML.writeProperty("D", "getetag",
-                        cacheEntry.attributes.getETag());
-                generatedXML.writeElement("D", "resourcetype",
-                        XMLWriter.NO_CONTENT);
-            } else {
-                generatedXML.writeElement("D", "resourcetype",
-                        XMLWriter.OPENING);
-                generatedXML.writeElement("D", "collection",
-                        XMLWriter.NO_CONTENT);
-                generatedXML.writeElement("D", "resourcetype",
-                        XMLWriter.CLOSING);
-            }
-
-            generatedXML.writeProperty("D", "source", "");
-
-            String supportedLocks = "<D:lockentry>"
-                + "<D:lockscope><D:exclusive/></D:lockscope>"
-                + "<D:locktype><D:write/></D:locktype>"
-                + "</D:lockentry>" + "<D:lockentry>"
-                + "<D:lockscope><D:shared/></D:lockscope>"
-                + "<D:locktype><D:write/></D:locktype>"
-                + "</D:lockentry>";
-            generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
-            generatedXML.writeText(supportedLocks);
-            generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
-
-            generateLockDiscovery(path, generatedXML);
-
-            generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "status", XMLWriter.OPENING);
-            generatedXML.writeText(status);
-            generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
-
-            break;
-
-        case FIND_PROPERTY_NAMES :
-
-            generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
-            generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
-
-            generatedXML.writeElement("D", "creationdate",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "displayname", XMLWriter.NO_CONTENT);
-            if (cacheEntry.resource != null) {
-                generatedXML.writeElement("D", "getcontentlanguage",
-                        XMLWriter.NO_CONTENT);
-                generatedXML.writeElement("D", "getcontentlength",
-                        XMLWriter.NO_CONTENT);
-                generatedXML.writeElement("D", "getcontenttype",
-                        XMLWriter.NO_CONTENT);
-                generatedXML.writeElement("D", "getetag", XMLWriter.NO_CONTENT);
-                generatedXML.writeElement("D", "getlastmodified",
-                        XMLWriter.NO_CONTENT);
-            }
-            generatedXML.writeElement("D", "resourcetype",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "source", XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "lockdiscovery",
-                                      XMLWriter.NO_CONTENT);
-
-            generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "status", XMLWriter.OPENING);
-            generatedXML.writeText(status);
-            generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
-
-            break;
-
-        case FIND_BY_PROPERTY :
-
-            Vector<String> propertiesNotFound = new Vector<String>();
-
-            // Parse the list of properties
-
-            generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
-            generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
-
-            Enumeration<String> properties = propertiesVector.elements();
-
-            while (properties.hasMoreElements()) {
-
-                String property = properties.nextElement();
-
-                if (property.equals("creationdate")) {
-                    generatedXML.writeProperty
-                        ("D", "creationdate",
-                         getISOCreationDate(cacheEntry.attributes.getCreation()));
-                } else if (property.equals("displayname")) {
-                    generatedXML.writeElement
-                        ("D", "displayname", XMLWriter.OPENING);
-                    generatedXML.writeData(resourceName);
-                    generatedXML.writeElement
-                        ("D", "displayname", XMLWriter.CLOSING);
-                } else if (property.equals("getcontentlanguage")) {
-                    if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
-                    } else {
-                        generatedXML.writeElement("D", "getcontentlanguage",
-                                                  XMLWriter.NO_CONTENT);
-                    }
-                } else if (property.equals("getcontentlength")) {
-                    if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
-                    } else {
-                        generatedXML.writeProperty
-                            ("D", "getcontentlength",
-                             (String.valueOf(cacheEntry.attributes.getContentLength())));
-                    }
-                } else if (property.equals("getcontenttype")) {
-                    if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
-                    } else {
-                        generatedXML.writeProperty
-                            ("D", "getcontenttype",
-                             getServletContext().getMimeType
-                             (cacheEntry.name));
-                    }
-                } else if (property.equals("getetag")) {
-                    if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
-                    } else {
-                        generatedXML.writeProperty
-                            ("D", "getetag", cacheEntry.attributes.getETag());
-                    }
-                } else if (property.equals("getlastmodified")) {
-                    if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
-                    } else {
-                        generatedXML.writeProperty
-                            ("D", "getlastmodified", FastHttpDateFormat.formatDate
-                                    (cacheEntry.attributes.getLastModified(), null));
-                    }
-                } else if (property.equals("resourcetype")) {
-                    if (cacheEntry.context != null) {
-                        generatedXML.writeElement("D", "resourcetype",
-                                XMLWriter.OPENING);
-                        generatedXML.writeElement("D", "collection",
-                                XMLWriter.NO_CONTENT);
-                        generatedXML.writeElement("D", "resourcetype",
-                                XMLWriter.CLOSING);
-                    } else {
-                        generatedXML.writeElement("D", "resourcetype",
-                                XMLWriter.NO_CONTENT);
-                    }
-                } else if (property.equals("source")) {
-                    generatedXML.writeProperty("D", "source", "");
-                } else if (property.equals("supportedlock")) {
-                    supportedLocks = "<D:lockentry>"
-                        + "<D:lockscope><D:exclusive/></D:lockscope>"
-                        + "<D:locktype><D:write/></D:locktype>"
-                        + "</D:lockentry>" + "<D:lockentry>"
-                        + "<D:lockscope><D:shared/></D:lockscope>"
-                        + "<D:locktype><D:write/></D:locktype>"
-                        + "</D:lockentry>";
-                    generatedXML.writeElement("D", "supportedlock",
-                            XMLWriter.OPENING);
-                    generatedXML.writeText(supportedLocks);
-                    generatedXML.writeElement("D", "supportedlock",
-                            XMLWriter.CLOSING);
-                } else if (property.equals("lockdiscovery")) {
-                    if (!generateLockDiscovery(path, generatedXML))
-                        propertiesNotFound.addElement(property);
-                } else {
-                    propertiesNotFound.addElement(property);
-                }
-
-            }
-
-            generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "status", XMLWriter.OPENING);
-            generatedXML.writeText(status);
-            generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
-            generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
-
-            Enumeration<String> propertiesNotFoundList =
-                propertiesNotFound.elements();
-
-            if (propertiesNotFoundList.hasMoreElements()) {
-
-                status = "HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND + " " +
-                        WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND);
-
-                generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
-                generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
-
-                while (propertiesNotFoundList.hasMoreElements()) {
-                    generatedXML.writeElement
-                        ("D", propertiesNotFoundList.nextElement(),
-                         XMLWriter.NO_CONTENT);
-                }
-
-                generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
-                generatedXML.writeElement("D", "status", XMLWriter.OPENING);
-                generatedXML.writeText(status);
-                generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
-                generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
-
-            }
-
-            break;
-
-        }
-
-        generatedXML.writeElement("D", "response", XMLWriter.CLOSING);
+        String rewrittenUrl = rewriteUrl(href);
 
+        generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector,
+                cacheEntry.context == null, false, cacheEntry.attributes.getCreation(), cacheEntry.attributes.getLastModified(),
+                cacheEntry.attributes.getContentLength(), getServletContext().getMimeType(cacheEntry.name),
+                cacheEntry.attributes.getETag());
     }
 
 
@@ -2393,22 +2152,33 @@ public class WebdavServlet extends DefaultServlet {
         if (lock == null)
             return;
 
-        generatedXML.writeElement("D", "response", XMLWriter.OPENING);
-        String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " +
-                WebdavStatus.getStatusText(WebdavStatus.SC_OK);
-
-        // Generating href element
-        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
-
         String absoluteUri = req.getRequestURI();
         String relativePath = getRelativePath(req);
         String toAppend = path.substring(relativePath.length());
         if (!toAppend.startsWith("/"))
             toAppend = "/" + toAppend;
 
-        generatedXML.writeText(rewriteUrl(RequestUtil.normalize(
-                absoluteUri + toAppend)));
+        String rewrittenUrl = rewriteUrl(RequestUtil.normalize(
+                absoluteUri + toAppend));
+
+        generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector,
+                true, true, lock.creationDate.getTime(), lock.creationDate.getTime(),
+                0, "", "");
+    }
+
+
+    private void generatePropFindResponse(XMLWriter generatedXML, String rewrittenUrl,
+            String path, int propFindType, Vector<String> propertiesVector, boolean isFile,
+            boolean isLockNull, long created, long lastModified, long contentLength,
+            String contentType, String eTag) {
+
+        generatedXML.writeElement("D", "response", XMLWriter.OPENING);
+        String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " +
+                WebdavStatus.getStatusText(WebdavStatus.SC_OK);
 
+        // Generating href element
+        generatedXML.writeElement("D", "href", XMLWriter.OPENING);
+        generatedXML.writeText(rewrittenUrl);
         generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
 
         String resourceName = path;
@@ -2416,28 +2186,37 @@ public class WebdavServlet extends DefaultServlet {
         if (lastSlash != -1)
             resourceName = resourceName.substring(lastSlash + 1);
 
-        switch (type) {
+        switch (propFindType) {
 
         case FIND_ALL_PROP :
 
             generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
             generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
 
-            generatedXML.writeProperty("D", "creationdate",
-                    getISOCreationDate(lock.creationDate.getTime()));
+            generatedXML.writeProperty("D", "creationdate", getISOCreationDate(created));
             generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
             generatedXML.writeData(resourceName);
             generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
-            generatedXML.writeProperty("D", "getlastmodified",
-                                       FastHttpDateFormat.formatDate
-                                       (lock.creationDate.getTime(), null));
-            generatedXML.writeProperty("D", "getcontentlength",
-                    String.valueOf(0));
-            generatedXML.writeProperty("D", "getcontenttype", "");
-            generatedXML.writeProperty("D", "getetag", "");
-            generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
-            generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
+            if (isFile) {
+                generatedXML.writeProperty("D", "getlastmodified",
+                        FastHttpDateFormat.formatDate(lastModified, null));
+                generatedXML.writeProperty("D", "getcontentlength", Long.toString(contentLength));
+                if (contentType != null) {
+                    generatedXML.writeProperty("D", "getcontenttype", contentType);
+                }
+                generatedXML.writeProperty("D", "getetag", eTag);
+                if (isLockNull) {
+                    generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
+                    generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
+                    generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
+                } else {
+                    generatedXML.writeElement("D", "resourcetype", XMLWriter.NO_CONTENT);
+                }
+            } else {
+                generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
+                generatedXML.writeElement("D", "collection", XMLWriter.NO_CONTENT);
+                generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
+            }
 
             generatedXML.writeProperty("D", "source", "");
 
@@ -2467,23 +2246,18 @@ public class WebdavServlet extends DefaultServlet {
             generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
             generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
 
-            generatedXML.writeElement("D", "creationdate",
-                                      XMLWriter.NO_CONTENT);
+            generatedXML.writeElement("D", "creationdate", XMLWriter.NO_CONTENT);
             generatedXML.writeElement("D", "displayname", XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "getcontentlanguage",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "getcontentlength",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "getcontenttype",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "getetag", XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "getlastmodified",
-                                      XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "resourcetype",
-                                      XMLWriter.NO_CONTENT);
+            if (isFile) {
+                generatedXML.writeElement("D", "getcontentlanguage", XMLWriter.NO_CONTENT);
+                generatedXML.writeElement("D", "getcontentlength", XMLWriter.NO_CONTENT);
+                generatedXML.writeElement("D", "getcontenttype", XMLWriter.NO_CONTENT);
+                generatedXML.writeElement("D", "getetag", XMLWriter.NO_CONTENT);
+                generatedXML.writeElement("D", "getlastmodified", XMLWriter.NO_CONTENT);
+            }
+            generatedXML.writeElement("D", "resourcetype", XMLWriter.NO_CONTENT);
             generatedXML.writeElement("D", "source", XMLWriter.NO_CONTENT);
-            generatedXML.writeElement("D", "lockdiscovery",
-                                      XMLWriter.NO_CONTENT);
+            generatedXML.writeElement("D", "lockdiscovery", XMLWriter.NO_CONTENT);
 
             generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
             generatedXML.writeElement("D", "status", XMLWriter.OPENING);
@@ -2509,36 +2283,58 @@ public class WebdavServlet extends DefaultServlet {
                 String property = properties.nextElement();
 
                 if (property.equals("creationdate")) {
-                    generatedXML.writeProperty("D", "creationdate",
-                            getISOCreationDate(lock.creationDate.getTime()));
+                    generatedXML.writeProperty("D", "creationdate", getISOCreationDate(created));
                 } else if (property.equals("displayname")) {
-                    generatedXML.writeElement("D", "displayname",
-                            XMLWriter.OPENING);
+                    generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
                     generatedXML.writeData(resourceName);
-                    generatedXML.writeElement("D", "displayname",
-                            XMLWriter.CLOSING);
+                    generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
                 } else if (property.equals("getcontentlanguage")) {
-                    generatedXML.writeElement("D", "getcontentlanguage",
-                            XMLWriter.NO_CONTENT);
+                    if (isFile) {
+                        generatedXML.writeElement("D", "getcontentlanguage",
+                                XMLWriter.NO_CONTENT);
+                    } else {
+                        propertiesNotFound.addElement(property);
+                    }
                 } else if (property.equals("getcontentlength")) {
-                    generatedXML.writeProperty("D", "getcontentlength",
-                            (String.valueOf(0)));
+                    if (isFile) {
+                        generatedXML.writeProperty("D", "getcontentlength",
+                                Long.toString(contentLength));
+                    } else {
+                        propertiesNotFound.addElement(property);
+                    }
                 } else if (property.equals("getcontenttype")) {
-                    generatedXML.writeProperty("D", "getcontenttype", "");
+                    if (isFile) {
+                        generatedXML.writeProperty("D", "getcontenttype", contentType);
+                    } else {
+                        propertiesNotFound.addElement(property);
+                    }
                 } else if (property.equals("getetag")) {
-                    generatedXML.writeProperty("D", "getetag", "");
+                    if (isFile) {
+                        generatedXML.writeProperty("D", "getetag", eTag);
+                    } else {
+                        propertiesNotFound.addElement(property);
+                    }
                 } else if (property.equals("getlastmodified")) {
-                    generatedXML.writeProperty
-                        ("D", "getlastmodified",
-                          FastHttpDateFormat.formatDate
-                         (lock.creationDate.getTime(), null));
+                    if (isFile) {
+                        generatedXML.writeProperty("D", "getlastmodified",
+                                FastHttpDateFormat.formatDate(lastModified, null));
+                    } else {
+                        propertiesNotFound.addElement(property);
+                    }
                 } else if (property.equals("resourcetype")) {
-                    generatedXML.writeElement("D", "resourcetype",
-                            XMLWriter.OPENING);
-                    generatedXML.writeElement("D", "lock-null",
-                            XMLWriter.NO_CONTENT);
-                    generatedXML.writeElement("D", "resourcetype",
-                            XMLWriter.CLOSING);
+                    if (isFile) {
+                        if(isLockNull) {
+                            generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
+                            generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
+                            generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
+                        } else {
+                            generatedXML.writeElement("D", "resourcetype", XMLWriter.NO_CONTENT);
+                        }
+                    } else {
+                        generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
+                        generatedXML.writeElement("D", "collection", XMLWriter.NO_CONTENT);
+                        generatedXML.writeElement("D", "resourcetype",XMLWriter.CLOSING);
+                    }
                 } else if (property.equals("source")) {
                     generatedXML.writeProperty("D", "source", "");
                 } else if (property.equals("supportedlock")) {
@@ -2549,11 +2345,9 @@ public class WebdavServlet extends DefaultServlet {
                         + "<D:lockscope><D:shared/></D:lockscope>"
                         + "<D:locktype><D:write/></D:locktype>"
                         + "</D:lockentry>";
-                    generatedXML.writeElement("D", "supportedlock",
-                            XMLWriter.OPENING);
+                    generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
                     generatedXML.writeText(supportedLocks);
-                    generatedXML.writeElement("D", "supportedlock",
-                            XMLWriter.CLOSING);
+                    generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
                 } else if (property.equals("lockdiscovery")) {
                     if (!generateLockDiscovery(path, generatedXML))
                         propertiesNotFound.addElement(property);
@@ -2580,9 +2374,8 @@ public class WebdavServlet extends DefaultServlet {
                 generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
 
                 while (propertiesNotFoundList.hasMoreElements()) {
-                    generatedXML.writeElement
-                        ("D", propertiesNotFoundList.nextElement(),
-                         XMLWriter.NO_CONTENT);
+                    generatedXML.writeElement("D", propertiesNotFoundList.nextElement(),
+                            XMLWriter.NO_CONTENT);
                 }
 
                 generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/06: Align with 8.5.x. Deprecate.

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit b61da624970e718d9609b11b2c0532de5d37734a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 20:35:11 2019 +0100

    Align with 8.5.x. Deprecate.
    
    Use org.apache.tomcat.util.http.ConcurrentDateFormat instead
---
 java/org/apache/catalina/authenticator/AuthenticatorBase.java | 5 ++---
 java/org/apache/catalina/servlets/WebdavServlet.java          | 2 +-
 java/org/apache/catalina/util/ConcurrentDateFormat.java       | 4 ++++
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/authenticator/AuthenticatorBase.java b/java/org/apache/catalina/authenticator/AuthenticatorBase.java
index 0c6ff36..a80c4dd 100644
--- a/java/org/apache/catalina/authenticator/AuthenticatorBase.java
+++ b/java/org/apache/catalina/authenticator/AuthenticatorBase.java
@@ -19,7 +19,6 @@ package org.apache.catalina.authenticator;
 import java.io.IOException;
 import java.security.Principal;
 import java.security.cert.X509Certificate;
-import java.util.Date;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
@@ -40,7 +39,6 @@ import org.apache.catalina.connector.Response;
 import org.apache.catalina.deploy.LoginConfig;
 import org.apache.catalina.deploy.SecurityConstraint;
 import org.apache.catalina.realm.GenericPrincipal;
-import org.apache.catalina.util.ConcurrentDateFormat;
 import org.apache.catalina.util.SessionIdGeneratorBase;
 import org.apache.catalina.util.StandardSessionIdGenerator;
 import org.apache.catalina.valves.ValveBase;
@@ -48,6 +46,7 @@ import org.apache.coyote.ActionCode;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.ExceptionUtils;
+import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -76,7 +75,7 @@ public abstract class AuthenticatorBase extends ValveBase
     /**
      * "Expires" header always set to Date(1), so generate once only
      */
-    private static final String DATE_ONE = ConcurrentDateFormat.formatRfc1123(new Date(1));
+    private static final String DATE_ONE = FastHttpDateFormat.formatDate(1);
 
     /**
      * The string manager for this package.
diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java
index 1f477cb..2b677d3 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -49,13 +49,13 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.catalina.connector.RequestFacade;
-import org.apache.catalina.util.ConcurrentDateFormat;
 import org.apache.catalina.util.DOMWriter;
 import org.apache.catalina.util.URLEncoder;
 import org.apache.catalina.util.XMLWriter;
 import org.apache.naming.resources.CacheEntry;
 import org.apache.naming.resources.Resource;
 import org.apache.naming.resources.ResourceAttributes;
+import org.apache.tomcat.util.http.ConcurrentDateFormat;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.RequestUtil;
 import org.apache.tomcat.util.security.MD5Encoder;
diff --git a/java/org/apache/catalina/util/ConcurrentDateFormat.java b/java/org/apache/catalina/util/ConcurrentDateFormat.java
index 7980ded..175f23e 100644
--- a/java/org/apache/catalina/util/ConcurrentDateFormat.java
+++ b/java/org/apache/catalina/util/ConcurrentDateFormat.java
@@ -27,7 +27,11 @@ import java.util.concurrent.ConcurrentLinkedQueue;
  * A thread safe wrapper around {@link SimpleDateFormat} that does not make use
  * of ThreadLocal and - broadly - only creates enough SimpleDateFormat objects
  * to satisfy the concurrency requirements.
+ *
+ * @deprecated Unused. This will be removed in Tomcat 10.
+ *             Use {@link org.apache.tomcat.util.http.ConcurrentDateFormat}
  */
+@Deprecated
 public class ConcurrentDateFormat {
 
     private final String format;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/06: Prep for additional backports. Align with 8.5.x.

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f852fb13e430be3862676b8b7cc691a59da4070e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 20:18:01 2019 +0100

    Prep for additional backports. Align with 8.5.x.
---
 .../tomcat/util/http/ConcurrentDateFormat.java     |  72 +++++++++++
 .../tomcat/util/http/FastHttpDateFormat.java       | 143 +++++++++------------
 2 files changed, 136 insertions(+), 79 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/ConcurrentDateFormat.java b/java/org/apache/tomcat/util/http/ConcurrentDateFormat.java
new file mode 100644
index 0000000..613b1ba
--- /dev/null
+++ b/java/org/apache/tomcat/util/http/ConcurrentDateFormat.java
@@ -0,0 +1,72 @@
+/*
+ * 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.http;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Queue;
+import java.util.TimeZone;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ * A thread safe wrapper around {@link SimpleDateFormat} that does not make use
+ * of ThreadLocal and - broadly - only creates enough SimpleDateFormat objects
+ * to satisfy the concurrency requirements.
+ */
+public class ConcurrentDateFormat {
+
+    private final String format;
+    private final Locale locale;
+    private final TimeZone timezone;
+    private final Queue<SimpleDateFormat> queue = new ConcurrentLinkedQueue<SimpleDateFormat>();
+
+    public ConcurrentDateFormat(String format, Locale locale, TimeZone timezone) {
+        this.format = format;
+        this.locale = locale;
+        this.timezone = timezone;
+        SimpleDateFormat initial = createInstance();
+        queue.add(initial);
+    }
+
+    public String format(Date date) {
+        SimpleDateFormat sdf = queue.poll();
+        if (sdf == null) {
+            sdf = createInstance();
+        }
+        String result = sdf.format(date);
+        queue.add(sdf);
+        return result;
+    }
+
+    public Date parse(String source) throws ParseException {
+        SimpleDateFormat sdf = queue.poll();
+        if (sdf == null) {
+            sdf = createInstance();
+        }
+        Date result = sdf.parse(source);
+        queue.add(sdf);
+        return result;
+    }
+
+    private SimpleDateFormat createInstance() {
+        SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
+        sdf.setTimeZone(timezone);
+        return sdf;
+    }
+}
diff --git a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
index d4af86d..4f787a2 100644
--- a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
+++ b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
@@ -18,7 +18,6 @@ package org.apache.tomcat.util.http;
 
 import java.text.DateFormat;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
 import java.util.Map;
@@ -41,39 +40,33 @@ public final class FastHttpDateFormat {
 
 
     /**
-     * HTTP date format.
+     * The only date format permitted when generating HTTP headers.
      */
-    private static final SimpleDateFormat format =
-        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+    public static final String RFC1123_DATE = "EEE, dd MMM yyyy HH:mm:ss zzz";
 
+    // HTTP date formats
+    private static final String DATE_RFC5322 = "EEE, dd MMM yyyy HH:mm:ss z";
+    private static final String DATE_OBSOLETE_RFC850 = "EEEEEE, dd-MMM-yy HH:mm:ss zzz";
+    private static final String DATE_OBSOLETE_ASCTIME = "EEE MMMM d HH:mm:ss yyyy";
 
-    /**
-     * The set of SimpleDateFormat formats to use in getDateHeader().
-     */
-    private static final SimpleDateFormat formats[] = {
-        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", 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)
-    };
-
+    private static final ConcurrentDateFormat FORMAT_RFC5322;
+    private static final ConcurrentDateFormat FORMAT_OBSOLETE_RFC850;
+    private static final ConcurrentDateFormat FORMAT_OBSOLETE_ASCTIME;
 
-    private static final TimeZone gmtZone = TimeZone.getTimeZone("GMT");
+    private static final ConcurrentDateFormat[] httpParseFormats;
 
-
-    /**
-     * GMT timezone - all HTTP dates are on GMT
-     */
     static {
+        // All the formats that use a timezone use GMT
+        TimeZone tz = TimeZone.getTimeZone("GMT");
 
-        format.setTimeZone(gmtZone);
-
-        formats[0].setTimeZone(gmtZone);
-        formats[1].setTimeZone(gmtZone);
-        formats[2].setTimeZone(gmtZone);
+        FORMAT_RFC5322 = new ConcurrentDateFormat(DATE_RFC5322, Locale.US, tz);
+        FORMAT_OBSOLETE_RFC850 = new ConcurrentDateFormat(DATE_OBSOLETE_RFC850, Locale.US, tz);
+        FORMAT_OBSOLETE_ASCTIME = new ConcurrentDateFormat(DATE_OBSOLETE_ASCTIME, Locale.US, tz);
 
+        httpParseFormats = new ConcurrentDateFormat[] {
+                FORMAT_RFC5322, FORMAT_OBSOLETE_RFC850, FORMAT_OBSOLETE_ASCTIME };
     }
 
-
     /**
      * Instant on which the currentDate object was generated.
      */
@@ -89,15 +82,13 @@ public final class FastHttpDateFormat {
     /**
      * Formatter cache.
      */
-    private static final Map<Long, String> formatCache =
-            new ConcurrentHashMap<Long, String>(CACHE_SIZE);
+    private static final Map<Long, String> formatCache = new ConcurrentHashMap<Long, String>(CACHE_SIZE);
 
 
     /**
      * Parser cache.
      */
-    private static final Map<String, Long> parseCache =
-            new ConcurrentHashMap<String, Long>(CACHE_SIZE);
+    private static final Map<String, Long> parseCache = new ConcurrentHashMap<String, Long>(CACHE_SIZE);
 
 
     // --------------------------------------------------------- Public Methods
@@ -105,94 +96,88 @@ public final class FastHttpDateFormat {
 
     /**
      * Get the current date in HTTP format.
+     * @return the HTTP date
      */
     public static final String getCurrentDate() {
-
         long now = System.currentTimeMillis();
         if ((now - currentDateGenerated) > 1000) {
-            synchronized (format) {
-                if ((now - currentDateGenerated) > 1000) {
-                    currentDate = format.format(new Date(now));
-                    currentDateGenerated = now;
-                }
-            }
+            currentDate = FORMAT_RFC5322.format(new Date(now));
+            currentDateGenerated = now;
         }
         return currentDate;
-
     }
 
 
     /**
      * Get the HTTP format of the specified date.
+     * @param value The date
+     * @param threadLocalformat Ignored. The local ConcurrentDateFormat will
+     *                          always be used.
+     * @return the HTTP date
      */
-    public static final String formatDate
-        (long value, DateFormat threadLocalformat) {
+    public static final String formatDate(long value, DateFormat threadLocalformat) {
+        return formatDate(value);
+    }
+
 
+    /**
+     * Get the HTTP format of the specified date.
+     * @param value The date
+     * @return the HTTP date
+     */
+    public static final String formatDate(long value) {
         Long longValue = Long.valueOf(value);
         String cachedDate = formatCache.get(longValue);
         if (cachedDate != null) {
             return cachedDate;
         }
 
-        String newDate = null;
-        Date dateValue = new Date(value);
-        if (threadLocalformat != null) {
-            newDate = threadLocalformat.format(dateValue);
-            updateFormatCache(longValue, newDate);
-        } else {
-            synchronized (format) {
-                newDate = format.format(dateValue);
-            }
-            updateFormatCache(longValue, newDate);
-        }
+        String newDate = FORMAT_RFC5322.format(new Date(value));
+        updateFormatCache(longValue, newDate);
         return newDate;
     }
 
 
     /**
      * Try to parse the given date as a HTTP date.
+     * @param value The HTTP date
+     * @param threadLocalformats Ignored. The local array of
+     *                           ConcurrentDateFormat will always be used.
+     * @return the date as a long
+     *
+     * @deprecated Unused. This will be removed in Tomcat 10
+     *             Use {@link #parseDate(String)}
      */
-    public static final long parseDate(String value,
-                                       DateFormat[] threadLocalformats) {
+    @Deprecated
+    public static final long parseDate(String value, DateFormat[] threadLocalformats) {
+        return parseDate(value);
+    }
+
+
+    /**
+     * Try to parse the given date as a HTTP date.
+     * @param value The HTTP date
+     * @return the date as a long or <code>-1</code> if the value cannot be
+     *         parsed
+     */
+    public static final long parseDate(String value) {
 
         Long cachedDate = parseCache.get(value);
         if (cachedDate != null) {
             return cachedDate.longValue();
         }
 
-        Long date = null;
-        if (threadLocalformats != null) {
-            date = internalParseDate(value, threadLocalformats);
-            updateParseCache(value, date);
-        } else {
-            date = internalParseDate(value, formats);
-            updateParseCache(value, date);
-        }
-        if (date == null) {
-            return (-1L);
-        }
-
-        return date.longValue();
-    }
-
-
-    /**
-     * Parse date with given formatters.
-     */
-    private static final Long internalParseDate
-        (String value, DateFormat[] formats) {
-        Date date = null;
-        for (int i = 0; (date == null) && (i < formats.length); i++) {
+        long date = -1;
+        for (int i = 0; (date == -1) && (i < httpParseFormats.length); i++) {
             try {
-                date = formats[i].parse(value);
+                date = httpParseFormats[i].parse(value).getTime();
+                updateParseCache(value, Long.valueOf(date));
             } catch (ParseException e) {
                 // Ignore
             }
         }
-        if (date == null) {
-            return null;
-        }
-        return Long.valueOf(date.getTime());
+
+        return date;
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org