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

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

commit 0be3e38a07ceb1c75e568915bef496f63edbc9b6
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 3 17:23:53 2020 +0100

    Refactoring: Remove remainder of servlet4preview package
    
    The functionality remains but requires casting to the appropriate
    internal Tomcat class.
---
 java/org/apache/catalina/connector/Request.java    |  3 +-
 .../apache/catalina/connector/RequestFacade.java   |  9 +---
 .../catalina/core/ApplicationDispatcher.java       | 18 +-------
 .../catalina/core/ApplicationHttpRequest.java      | 11 ++---
 .../apache/catalina/core/ApplicationMapping.java   | 25 ++++++++++
 .../catalina/core/ApplicationMappingImpl.java      | 16 +++++++
 .../org/apache/catalina/filters/ExpiresFilter.java | 28 ++++++-----
 .../servlet4preview/http/HttpServletRequest.java   | 27 -----------
 .../http/HttpServletRequestWrapper.java            | 54 ----------------------
 ...estApplicationContextGetRequestDispatcherB.java |  3 +-
 .../catalina/core/TestApplicationMapping.java      |  3 +-
 webapps/docs/changelog.xml                         | 10 ++++
 12 files changed, 73 insertions(+), 134 deletions(-)

diff --git a/java/org/apache/catalina/connector/Request.java 
b/java/org/apache/catalina/connector/Request.java
index 71a107d..301d5a9 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -125,7 +125,7 @@ import org.ietf.jgss.GSSException;
  * @author Remy Maucherat
  * @author Craig R. McClanahan
  */
-public class Request implements 
org.apache.catalina.servlet4preview.http.HttpServletRequest {
+public class Request implements HttpServletRequest {
 
     private static final Log log = LogFactory.getLog(Request.class);
 
@@ -2303,7 +2303,6 @@ public class Request implements 
org.apache.catalina.servlet4preview.http.HttpSer
     }
 
 
-    @Override
     public ApplicationMappingImpl getHttpServletMapping() {
         return applicationMapping.getHttpServletMapping();
     }
diff --git a/java/org/apache/catalina/connector/RequestFacade.java 
b/java/org/apache/catalina/connector/RequestFacade.java
index 3ecf5b9..e80147c 100644
--- a/java/org/apache/catalina/connector/RequestFacade.java
+++ b/java/org/apache/catalina/connector/RequestFacade.java
@@ -34,6 +34,7 @@ import javax.servlet.ServletInputStream;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpUpgradeHandler;
@@ -43,7 +44,6 @@ import org.apache.catalina.Globals;
 import org.apache.catalina.core.ApplicationMappingImpl;
 import org.apache.catalina.core.ApplicationPushBuilder;
 import org.apache.catalina.security.SecurityUtil;
-import org.apache.catalina.servlet4preview.http.HttpServletRequest;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -1116,13 +1116,6 @@ public class RequestFacade implements HttpServletRequest 
{
     }
 
 
-    /**
-     * {@inheritDoc}
-     * <p>
-     * Pulled forward from Servlet 4.0. The method signature may be modified,
-     * removed or replaced at any time until Servlet 4.0 becomes final.
-     */
-    @Override
     public ApplicationMappingImpl getHttpServletMapping() {
         return request.getHttpServletMapping();
     }
diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java 
b/java/org/apache/catalina/core/ApplicationDispatcher.java
index eb3d420..c32a78e 100644
--- a/java/org/apache/catalina/core/ApplicationDispatcher.java
+++ b/java/org/apache/catalina/core/ApplicationDispatcher.java
@@ -371,14 +371,7 @@ final class ApplicationDispatcher implements 
AsyncDispatcher, RequestDispatcher
                                       hrequest.getPathInfo());
                 wrequest.setAttribute(RequestDispatcher.FORWARD_QUERY_STRING,
                                       hrequest.getQueryString());
-                ApplicationMappingImpl mapping;
-                if (hrequest instanceof 
org.apache.catalina.servlet4preview.http.HttpServletRequest) {
-                    mapping = 
((org.apache.catalina.servlet4preview.http.HttpServletRequest)
-                            hrequest).getHttpServletMapping();
-                } else {
-                    mapping = (new 
ApplicationMapping(null)).getHttpServletMapping();
-                }
-                wrequest.setAttribute(FORWARD_MAPPING, mapping);
+                wrequest.setAttribute(FORWARD_MAPPING, 
ApplicationMapping.getHttpServletMapping(hrequest));
             }
 
             wrequest.setContextPath(context.getEncodedPath());
@@ -626,14 +619,7 @@ final class ApplicationDispatcher implements 
AsyncDispatcher, RequestDispatcher
 
         wrequest.setAttribute(Globals.DISPATCHER_TYPE_ATTR, 
DispatcherType.ASYNC);
         wrequest.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, 
getCombinedPath());
-        ApplicationMappingImpl mapping;
-        if (hrequest instanceof 
org.apache.catalina.servlet4preview.http.HttpServletRequest) {
-            mapping = 
((org.apache.catalina.servlet4preview.http.HttpServletRequest)
-                    hrequest).getHttpServletMapping();
-        } else {
-            mapping = (new ApplicationMapping(null)).getHttpServletMapping();
-        }
-        wrequest.setAttribute(ASYNC_MAPPING, mapping);
+        wrequest.setAttribute(ASYNC_MAPPING, 
ApplicationMapping.getHttpServletMapping(hrequest));
 
         wrequest.setContextPath(context.getEncodedPath());
         wrequest.setRequestURI(requestURI);
diff --git a/java/org/apache/catalina/core/ApplicationHttpRequest.java 
b/java/org/apache/catalina/core/ApplicationHttpRequest.java
index fab0799..bd27924 100644
--- a/java/org/apache/catalina/core/ApplicationHttpRequest.java
+++ b/java/org/apache/catalina/core/ApplicationHttpRequest.java
@@ -35,6 +35,7 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletRequestWrapper;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpSession;
 
 import org.apache.catalina.Context;
@@ -65,8 +66,7 @@ import org.apache.tomcat.util.res.StringManager;
  * @author Craig R. McClanahan
  * @author Remy Maucherat
  */
-class ApplicationHttpRequest
-        extends 
org.apache.catalina.servlet4preview.http.HttpServletRequestWrapper {
+class ApplicationHttpRequest extends HttpServletRequestWrapper {
 
     private static final StringManager sm = 
StringManager.getManager(ApplicationHttpRequest.class);
 
@@ -526,7 +526,6 @@ class ApplicationHttpRequest
     }
 
 
-    @Override
     public ApplicationMappingImpl getHttpServletMapping() {
         return mapping;
     }
@@ -717,11 +716,7 @@ class ApplicationHttpRequest
         queryString = request.getQueryString();
         requestURI = request.getRequestURI();
         servletPath = request.getServletPath();
-        if (request instanceof 
org.apache.catalina.servlet4preview.http.HttpServletRequest) {
-            mapping = 
((org.apache.catalina.servlet4preview.http.HttpServletRequest) 
request).getHttpServletMapping();
-        } else {
-            mapping = (new ApplicationMapping(null)).getHttpServletMapping();
-        }
+        mapping = ApplicationMapping.getHttpServletMapping(request);
     }
 
 
diff --git a/java/org/apache/catalina/core/ApplicationMapping.java 
b/java/org/apache/catalina/core/ApplicationMapping.java
index 0c988cf..39ce111 100644
--- a/java/org/apache/catalina/core/ApplicationMapping.java
+++ b/java/org/apache/catalina/core/ApplicationMapping.java
@@ -16,6 +16,11 @@
  */
 package org.apache.catalina.core;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.RequestFacade;
 import org.apache.catalina.mapper.MappingData;
 
 public class ApplicationMapping {
@@ -83,4 +88,24 @@ public class ApplicationMapping {
     public void recycle() {
         mapping = null;
     }
+
+
+    public static ApplicationMappingImpl 
getHttpServletMapping(HttpServletRequest request) {
+        if (request instanceof RequestFacade) {
+            return ((RequestFacade) request).getHttpServletMapping();
+        } else if (request instanceof Request) {
+            return ((Request) request).getHttpServletMapping();
+        } else if (request instanceof ApplicationHttpRequest) {
+            return ((ApplicationHttpRequest) request).getHttpServletMapping();
+        }
+        return (new ApplicationMapping(null)).getHttpServletMapping();
+    }
+
+
+    public static ApplicationMappingImpl 
getHttpServletMapping(HttpServletRequestWrapper wrapper) {
+        if (wrapper instanceof ApplicationHttpRequest) {
+            return ((ApplicationHttpRequest) wrapper).getHttpServletMapping();
+        }
+        return (new ApplicationMapping(null)).getHttpServletMapping();
+    }
 }
diff --git a/java/org/apache/catalina/core/ApplicationMappingImpl.java 
b/java/org/apache/catalina/core/ApplicationMappingImpl.java
index 2362b1f..3922943 100644
--- a/java/org/apache/catalina/core/ApplicationMappingImpl.java
+++ b/java/org/apache/catalina/core/ApplicationMappingImpl.java
@@ -1,3 +1,19 @@
+/*
+ * 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.catalina.core;
 
 public class ApplicationMappingImpl {
diff --git a/java/org/apache/catalina/filters/ExpiresFilter.java 
b/java/org/apache/catalina/filters/ExpiresFilter.java
index 6c7ff78..66b21cf 100644
--- a/java/org/apache/catalina/filters/ExpiresFilter.java
+++ b/java/org/apache/catalina/filters/ExpiresFilter.java
@@ -42,6 +42,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
+import org.apache.catalina.core.ApplicationMapping;
+import org.apache.catalina.core.ApplicationMappingImpl;
 import org.apache.catalina.core.ApplicationMappingMatch;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -1292,21 +1294,17 @@ public class ExpiresFilter extends FilterBase {
                 innerRequest = ((ServletRequestWrapper) 
innerRequest).getRequest();
             }
 
-            if (innerRequest instanceof 
org.apache.catalina.servlet4preview.http.HttpServletRequest) {
-                org.apache.catalina.servlet4preview.http.HttpServletRequest 
servlet4Request =
-                        
(org.apache.catalina.servlet4preview.http.HttpServletRequest) innerRequest;
-
-                if (servlet4Request.getHttpServletMapping().getMappingMatch() 
== ApplicationMappingMatch.DEFAULT &&
-                        response.getStatus() == 
HttpServletResponse.SC_NOT_MODIFIED) {
-                    // Default servlet normally sets the content type but does 
not for
-                    // 304 responses. Look it up.
-                    String servletPath = request.getServletPath();
-                    if (servletPath != null) {
-                        int lastSlash = servletPath.lastIndexOf('/');
-                        if (lastSlash > -1) {
-                            String fileName = servletPath.substring(lastSlash 
+ 1);
-                            contentType = 
request.getServletContext().getMimeType(fileName);
-                        }
+            ApplicationMappingImpl mapping = 
ApplicationMapping.getHttpServletMapping(request);
+            if (mapping.getMappingMatch() == ApplicationMappingMatch.DEFAULT &&
+                    response.getStatus() == 
HttpServletResponse.SC_NOT_MODIFIED) {
+                // Default servlet normally sets the content type but does not 
for
+                // 304 responses. Look it up.
+                String servletPath = request.getServletPath();
+                if (servletPath != null) {
+                    int lastSlash = servletPath.lastIndexOf('/');
+                    if (lastSlash > -1) {
+                        String fileName = servletPath.substring(lastSlash + 1);
+                        contentType = 
request.getServletContext().getMimeType(fileName);
                     }
                 }
             }
diff --git 
a/java/org/apache/catalina/servlet4preview/http/HttpServletRequest.java 
b/java/org/apache/catalina/servlet4preview/http/HttpServletRequest.java
deleted file mode 100644
index f605ed7..0000000
--- a/java/org/apache/catalina/servlet4preview/http/HttpServletRequest.java
+++ /dev/null
@@ -1,27 +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.catalina.servlet4preview.http;
-
-import org.apache.catalina.core.ApplicationMappingImpl;
-
-/**
- * Provides early access to some parts of the Servlet 4.0 API.
- */
-public interface HttpServletRequest extends 
javax.servlet.http.HttpServletRequest {
-
-    public ApplicationMappingImpl getHttpServletMapping();
-}
diff --git 
a/java/org/apache/catalina/servlet4preview/http/HttpServletRequestWrapper.java 
b/java/org/apache/catalina/servlet4preview/http/HttpServletRequestWrapper.java
deleted file mode 100644
index 7ed31ce..0000000
--- 
a/java/org/apache/catalina/servlet4preview/http/HttpServletRequestWrapper.java
+++ /dev/null
@@ -1,54 +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.catalina.servlet4preview.http;
-
-import org.apache.catalina.core.ApplicationMappingImpl;
-
-/**
- * Provides early access to some parts of the Servlet 4.0 API.
- */
-public class HttpServletRequestWrapper extends 
javax.servlet.http.HttpServletRequestWrapper
-        implements HttpServletRequest {
-
-    /**
-     * Constructs a request object wrapping the given request.
-     *
-     * @param request The request to wrap
-     *
-     * @throws java.lang.IllegalArgumentException
-     *             if the request is null
-     */
-    public HttpServletRequestWrapper(javax.servlet.http.HttpServletRequest 
request) {
-        super(request);
-    }
-
-    private HttpServletRequest _getHttpServletRequest() {
-        return (HttpServletRequest) super.getRequest();
-    }
-
-    /**
-     * The default behavior of this method is to return
-     * {@link HttpServletRequest#getHttpServletMapping()} on the wrapped 
request
-     * object.
-     *
-     * @since Servlet 4.0
-     */
-    @Override
-    public ApplicationMappingImpl getHttpServletMapping() {
-        return this._getHttpServletRequest().getHttpServletMapping();
-    }
-}
diff --git 
a/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcherB.java
 
b/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcherB.java
index 8bcbcde..f2e7f5e 100755
--- 
a/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcherB.java
+++ 
b/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcherB.java
@@ -526,8 +526,7 @@ public class TestApplicationContextGetRequestDispatcherB 
extends TomcatBaseTest
             Assert.assertEquals(expectedServletPath, req.getServletPath());
             Assert.assertEquals(expectedPathInfo, req.getPathInfo());
             Assert.assertEquals(expectedQueryString, req.getQueryString());
-            ApplicationMappingImpl mapping =
-                    
((org.apache.catalina.servlet4preview.http.HttpServletRequest) 
req).getHttpServletMapping();
+            ApplicationMappingImpl mapping = 
ApplicationMapping.getHttpServletMapping(req);
             Assert.assertEquals(expectedMappingMatch, 
mapping.getMappingMatch());
             Assert.assertEquals(expectedMappingPattern, mapping.getPattern());
             Assert.assertEquals(expectedMappingMatchValue, 
mapping.getMatchValue());
diff --git a/test/org/apache/catalina/core/TestApplicationMapping.java 
b/test/org/apache/catalina/core/TestApplicationMapping.java
index 76ef88c..7636a3a 100644
--- a/test/org/apache/catalina/core/TestApplicationMapping.java
+++ b/test/org/apache/catalina/core/TestApplicationMapping.java
@@ -339,8 +339,7 @@ public class TestApplicationMapping extends TomcatBaseTest {
                 throws ServletException, IOException {
             resp.setContentType("text/plain;charset=UTF-8");
             PrintWriter pw = resp.getWriter();
-            ApplicationMappingImpl mapping = 
((org.apache.catalina.servlet4preview.http.HttpServletRequest)
-                    req).getHttpServletMapping();
+            ApplicationMappingImpl mapping = 
ApplicationMapping.getHttpServletMapping(req);
             pw.println("MatchValue=[" + mapping.getMatchValue() + "]");
             pw.println("Pattern=[" + mapping.getPattern() + "]");
             pw.println("MatchType=[" + mapping.getMappingMatch() + "]");
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index c4b0f93..7ad9daf 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -45,6 +45,16 @@
   issues do not "pop up" wrt. others).
 -->
 <section name="Tomcat 8.5.55 (markt)" rtext="in development">
+  <subsection name="Catalina">
+    <changelog>
+      <scode>
+        Remove the remainder of the deprecated Servlet 4 Preview API. Users
+        still depending on this feature should ideally upgrade to Tomcat
+        9.0.x. If upgrade is not possible, application code should cast to the
+        internal Tomcat implementation classes. (markt)
+      </scode>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 8.5.54 (markt)" rtext="release in progress">
   <subsection name="Catalina">


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

Reply via email to