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

lihan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 523f9353cf Refactor. Reduce duplicate code. No functional change.
523f9353cf is described below

commit 523f9353cf849932dcba8f26cbfa9e886b87cad5
Author: lihan <li...@apache.org>
AuthorDate: Mon Oct 31 15:43:00 2022 +0800

    Refactor. Reduce duplicate code. No functional change.
---
 .../apache/catalina/core/StandardWrapperValve.java | 52 +++++++---------------
 1 file changed, 17 insertions(+), 35 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardWrapperValve.java 
b/java/org/apache/catalina/core/StandardWrapperValve.java
index f8061d6078..db565a033f 100644
--- a/java/org/apache/catalina/core/StandardWrapperValve.java
+++ b/java/org/apache/catalina/core/StandardWrapperValve.java
@@ -108,17 +108,7 @@ final class StandardWrapperValve extends ValveBase {
         if (!unavailable && wrapper.isUnavailable()) {
             
container.getLogger().info(sm.getString("standardWrapper.isUnavailable",
                     wrapper.getName()));
-            long available = wrapper.getAvailable();
-            if ((available > 0L) && (available < Long.MAX_VALUE)) {
-                response.setDateHeader("Retry-After", available);
-                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
-                        sm.getString("standardWrapper.isUnavailable",
-                                wrapper.getName()));
-            } else if (available == Long.MAX_VALUE) {
-                response.sendError(HttpServletResponse.SC_NOT_FOUND,
-                        sm.getString("standardWrapper.notFound",
-                                wrapper.getName()));
-            }
+            checkWrapperAvailable(response, wrapper);
             unavailable = true;
         }
 
@@ -131,17 +121,7 @@ final class StandardWrapperValve extends ValveBase {
             container.getLogger().error(
                     sm.getString("standardWrapper.allocateException",
                             wrapper.getName()), e);
-            long available = wrapper.getAvailable();
-            if ((available > 0L) && (available < Long.MAX_VALUE)) {
-                response.setDateHeader("Retry-After", available);
-                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
-                           sm.getString("standardWrapper.isUnavailable",
-                                        wrapper.getName()));
-            } else if (available == Long.MAX_VALUE) {
-                response.sendError(HttpServletResponse.SC_NOT_FOUND,
-                           sm.getString("standardWrapper.notFound",
-                                        wrapper.getName()));
-            }
+            checkWrapperAvailable(response, wrapper);
         } catch (ServletException e) {
             
container.getLogger().error(sm.getString("standardWrapper.allocateException",
                              wrapper.getName()), 
StandardWrapper.getRootCause(e));
@@ -217,20 +197,8 @@ final class StandardWrapperValve extends ValveBase {
             container.getLogger().error(sm.getString(
                     "standardWrapper.serviceException", wrapper.getName(),
                     context.getName()), e);
-            //            throwable = e;
-            //            exception(request, response, e);
             wrapper.unavailable(e);
-            long available = wrapper.getAvailable();
-            if ((available > 0L) && (available < Long.MAX_VALUE)) {
-                response.setDateHeader("Retry-After", available);
-                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
-                           sm.getString("standardWrapper.isUnavailable",
-                                        wrapper.getName()));
-            } else if (available == Long.MAX_VALUE) {
-                response.sendError(HttpServletResponse.SC_NOT_FOUND,
-                            sm.getString("standardWrapper.notFound",
-                                        wrapper.getName()));
-            }
+            checkWrapperAvailable(response, wrapper);
             // Do not save exception in 'throwable', because we
             // do not want to do exception(request, response, e) processing
         } catch (ServletException e) {
@@ -299,6 +267,20 @@ final class StandardWrapperValve extends ValveBase {
         }
     }
 
+    private void checkWrapperAvailable(Response response, StandardWrapper 
wrapper) throws IOException {
+        long available = wrapper.getAvailable();
+        if ((available > 0L) && (available < Long.MAX_VALUE)) {
+            response.setDateHeader("Retry-After", available);
+            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
+                       sm.getString("standardWrapper.isUnavailable",
+                                    wrapper.getName()));
+        } else if (available == Long.MAX_VALUE) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        sm.getString("standardWrapper.notFound",
+                                    wrapper.getName()));
+        }
+    }
+
 
     // -------------------------------------------------------- Private Methods
 


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

Reply via email to