This is an automated email from the ASF dual-hosted git repository.
markt-asf 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 ac067952ab Refactor to reduce duplicate code
ac067952ab is described below
commit ac067952abea920b8720cd19a2b70e465e3c7cdb
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Jun 25 11:45:44 2026 +0100
Refactor to reduce duplicate code
---
.../apache/catalina/manager/ManagerServlet.java | 48 +++++++++++-----------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/java/org/apache/catalina/manager/ManagerServlet.java
b/java/org/apache/catalina/manager/ManagerServlet.java
index 927396b393..e38e422d97 100644
--- a/java/org/apache/catalina/manager/ManagerServlet.java
+++ b/java/org/apache/catalina/manager/ManagerServlet.java
@@ -1092,15 +1092,9 @@ public class ManagerServlet extends HttpServlet
implements ContainerServlet {
try {
if (tryAddServiced(name)) {
try {
- Context context = (Context) host.findChild(name);
+ // Validates the Context of the specified application
+ Context context = getContextForName(cn, writer, smClient);
if (context == null) {
- writer.println(
- smClient.getString("managerServlet.noContext",
Escape.htmlElementContent(cn.getDisplayName())));
- return;
- }
- // It isn't possible for the manager to reload itself
- if (context.getName().equals(this.context.getName())) {
-
writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.reload();
@@ -1419,14 +1413,9 @@ public class ManagerServlet extends HttpServlet
implements ContainerServlet {
String displayPath = cn.getDisplayName();
try {
- Context context = (Context) host.findChild(cn.getName());
+ // Validates the Context of the specified application
+ Context context = getContextForName(cn, writer, smClient);
if (context == null) {
- writer.println(smClient.getString("managerServlet.noContext",
Escape.htmlElementContent(displayPath)));
- return;
- }
- // It isn't possible for the manager to stop itself
- if (context.getName().equals(this.context.getName())) {
- writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
context.stop();
@@ -1462,17 +1451,9 @@ public class ManagerServlet extends HttpServlet
implements ContainerServlet {
String displayPath = cn.getDisplayName();
try {
-
- // Validate the Context of the specified application
- Context context = (Context) host.findChild(name);
+ // Validates the Context of the specified application
+ Context context = getContextForName(cn, writer, smClient);
if (context == null) {
- writer.println(smClient.getString("managerServlet.noContext",
Escape.htmlElementContent(displayPath)));
- return;
- }
-
- // It isn't possible for the manager to undeploy itself
- if (context.getName().equals(this.context.getName())) {
- writer.println(smClient.getString("managerServlet.noSelf"));
return;
}
@@ -1521,6 +1502,23 @@ public class ManagerServlet extends HttpServlet
implements ContainerServlet {
}
+ private Context getContextForName(ContextName cn, PrintWriter writer,
StringManager smClient) {
+ Context context = (Context) host.findChild(cn.getName());
+ if (context == null) {
+ writer.println(
+ smClient.getString("managerServlet.noContext",
Escape.htmlElementContent(cn.getDisplayName())));
+ return null;
+ }
+
+ // Manager cannot operate on itself
+ if (context.getName().equals(this.context.getName())) {
+ writer.println(smClient.getString("managerServlet.noSelf"));
+ return null;
+ }
+ return context;
+ }
+
+
// -------------------------------------------------------- Support Methods
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]