This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 9609da1 Fix path used by the health check valve
9609da1 is described below
commit 9609da111f99ec387d64067d251669787620cff4
Author: remm <[email protected]>
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 481e8bc..be9c487 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 jakarta.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 dae52f6..d3327d7 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: [email protected]
For additional commands, e-mail: [email protected]