Skip to content

Commit 3dca097

Browse files
committed
Fix complete status output with a failed context
1 parent b7d5660 commit 3dca097

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

java/org/apache/catalina/manager/StatusTransformer.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import jakarta.servlet.http.HttpServletResponse;
3636

37+
import org.apache.catalina.LifecycleState;
3738
import org.apache.tomcat.util.json.JSONFilter;
3839
import org.apache.tomcat.util.security.Escape;
3940

@@ -795,6 +796,8 @@ protected static void writeContext(PrintWriter writer, ObjectName objectName, MB
795796
contextName = "";
796797
}
797798

799+
Object stateName = mBeanServer.getAttribute(objectName, "stateName");
800+
798801
if (mode == 0) {
799802

800803
writer.print("<h1>");
@@ -803,12 +806,19 @@ protected static void writeContext(PrintWriter writer, ObjectName objectName, MB
803806
writer.print("</a>");
804807

805808
writer.print("<p>");
806-
Object startTime = mBeanServer.getAttribute(objectName, "startTime");
807-
writer.print(" Start time: " + new Date(((Long) startTime).longValue()));
808-
writer.print(" Startup time: ");
809-
writer.print(formatTime(mBeanServer.getAttribute(objectName, "startupTime"), false));
810-
writer.print(" TLD scan time: ");
811-
writer.print(formatTime(mBeanServer.getAttribute(objectName, "tldScanTime"), false));
809+
writer.print("State: " + stateName);
810+
if (!LifecycleState.FAILED.name().equals(stateName)) {
811+
/*
812+
* If in the FAILED state, the context will be an instance of FailedContext so the attributes normally
813+
* requested for a running context won't be available.
814+
*/
815+
Object startTime = mBeanServer.getAttribute(objectName, "startTime");
816+
writer.print(" Start time: " + new Date(((Long) startTime).longValue()));
817+
writer.print(" Startup time: ");
818+
writer.print(formatTime(mBeanServer.getAttribute(objectName, "startupTime"), false));
819+
writer.print(" TLD scan time: ");
820+
writer.print(formatTime(mBeanServer.getAttribute(objectName, "tldScanTime"), false));
821+
}
812822
if (managerON != null) {
813823
writeManager(writer, managerON, mBeanServer, mode);
814824
}
@@ -829,11 +839,19 @@ protected static void writeContext(PrintWriter writer, ObjectName objectName, MB
829839
} else if (mode == 2) {
830840
indent(writer, 2).append('{').println();
831841
appendJSonValue(indent(writer, 3), "name", JSONFilter.escape(JSONFilter.escape(name))).append(',');
832-
appendJSonValue(writer, "startTime",
833-
new Date(((Long) mBeanServer.getAttribute(objectName, "startTime")).longValue()).toString())
834-
.append(',');
835-
appendJSonValue(writer, "startupTime", mBeanServer.getAttribute(objectName, "startupTime")).append(',');
836-
appendJSonValue(writer, "tldScanTime", mBeanServer.getAttribute(objectName, "tldScanTime"));
842+
appendJSonValue(writer, "stateName", stateName);
843+
if (!LifecycleState.FAILED.name().equals(stateName)) {
844+
/*
845+
* If in the FAILED state, the context will be an instance of FailedContext so the attributes normally
846+
* requested for a running context won't be available.
847+
*/
848+
writer.append(',');
849+
appendJSonValue(writer, "startTime",
850+
new Date(((Long) mBeanServer.getAttribute(objectName, "startTime")).longValue()).toString())
851+
.append(',');
852+
appendJSonValue(writer, "startupTime", mBeanServer.getAttribute(objectName, "startupTime")).append(',');
853+
appendJSonValue(writer, "tldScanTime", mBeanServer.getAttribute(objectName, "tldScanTime"));
854+
}
837855
if (managerON != null) {
838856
writeManager(writer, managerON, mBeanServer, mode);
839857
}

webapps/docs/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@
304304
<subsection name="Web applications">
305305
<changelog>
306306
<!-- Entries for backport and removal before 12.0.0-M1 below this line -->
307+
<fix>
308+
Manager: Fix abrupt truncation of the HTML and JSON complete server
309+
status output if one or more of the web applications failed to start.
310+
(markt)
311+
</fix>
307312
</changelog>
308313
</subsection>
309314
<subsection name="Other">

0 commit comments

Comments
 (0)