This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 6a3f8a5c8b Refactor to reduce duplicate code
6a3f8a5c8b is described below
commit 6a3f8a5c8b25b80d399791734a242f8ef368894d
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 5533b43eed..a91e875c0d 100644
--- a/java/org/apache/catalina/manager/ManagerServlet.java
+++ b/java/org/apache/catalina/manager/ManagerServlet.java
@@ -1094,15 +1094,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();
@@ -1400,14 +1394,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();
@@ -1443,17 +1432,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;
}
@@ -1502,6 +1483,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]