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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new e42ee16  Fix path used by the health check valve
e42ee16 is described below

commit e42ee169dbde36e9a6979f4b4036e3b2a0b1b3b4
Author: remm <r...@apache.org>
AuthorDate: Tue Sep 1 14:29:58 2020 +0200

    Fix path used by the health check valve
    
    When not associated with a Context, it should use the full URI.
---
 .../apache/catalina/valves/HealthCheckValve.java   | 23 ++++++++++++++++++++--
 webapps/docs/changelog.xml                         |  4 ++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java 
b/java/org/apache/catalina/valves/HealthCheckValve.java
index f8227ac..fb4a8e2 100644
--- a/java/org/apache/catalina/valves/HealthCheckValve.java
+++ b/java/org/apache/catalina/valves/HealthCheckValve.java
@@ -20,6 +20,8 @@ import java.io.IOException;
 
 import javax.servlet.ServletException;
 
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleException;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.tomcat.util.buf.MessageBytes;
@@ -35,8 +37,14 @@ public class HealthCheckValve extends ValveBase {
             "  \"status\": \"UP\",\n" +
             "  \"checks\": []\n" +
             "}";
+
     private String path = "/health";
 
+    /**
+     * Will be set to true if the valve is associated with a context.
+     */
+    protected boolean context = false;
+
     public HealthCheckValve() {
         super(true);
     }
@@ -50,10 +58,21 @@ public class HealthCheckValve extends ValveBase {
     }
 
     @Override
+    protected synchronized void startInternal() throws LifecycleException {
+        super.startInternal();
+        if (getContainer() instanceof Context) {
+            context = true;
+        } else {
+            context = false;
+        }
+    }
+
+    @Override
     public void invoke(Request request, Response response)
             throws IOException, ServletException {
-        MessageBytes requestPathMB = request.getRequestPathMB();
-        if (requestPathMB.equals(path)) {
+        MessageBytes urlMB =
+                context ? request.getRequestPathMB() : 
request.getDecodedRequestURIMB();
+        if (urlMB.equals(path)) {
             response.setContentType("application/json");
             response.getOutputStream().print(UP);
         } else {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1aa08b5..35dad91 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -101,6 +101,10 @@
         Use the correct method to calculate session idle time in
         <code>PersistentValve</code>. (kfujino)
       </fix>
+      <fix>
+        Fix path used by the health check valve when it is not associated with
+        a <code>Context</code>. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to