You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/09/29 18:54:46 UTC
(tomcat) 06/13: Include the HTTP error response body in the error messages of the Manager Ant tasks
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit ee1e7853f52627059568e5a4e5013be0a889f548
Author: opencode <re...@apache.org>
AuthorDate: Tue Sep 29 19:09:16 2026 +0200
Include the HTTP error response body in the error messages of the Manager Ant tasks
---
.../apache/catalina/ant/AbstractCatalinaTask.java | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/java/org/apache/catalina/ant/AbstractCatalinaTask.java b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
index 8edc407063..cb60aef729 100644
--- a/java/org/apache/catalina/ant/AbstractCatalinaTask.java
+++ b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
@@ -16,6 +16,7 @@
*/
package org.apache.catalina.ant;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -296,6 +297,32 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
}
}
+ int responseCode = hconn.getResponseCode();
+ if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ // For error responses, getInputStream() below would throw and
+ // the response body - which typically explains the error -
+ // would be discarded. Include its first line in the message.
+ String errorBody = null;
+ try (InputStream errorStream = hconn.getErrorStream()) {
+ if (errorStream != null) {
+ BufferedReader errorReader = new BufferedReader(
+ new InputStreamReader(errorStream, StandardCharsets.UTF_8));
+ errorBody = errorReader.readLine();
+ }
+ }
+ StringBuilder message = new StringBuilder();
+ message.append("Server returned HTTP response code: ");
+ message.append(responseCode);
+ message.append(" for URL: ");
+ message.append(url);
+ message.append(command);
+ if (errorBody != null && !errorBody.isEmpty()) {
+ message.append(" - ");
+ message.append(errorBody);
+ }
+ throw new IOException(message.toString());
+ }
+
// Process the response message
reader = new InputStreamReader(hconn.getInputStream(), StandardCharsets.UTF_8);
StringBuilder buff = new StringBuilder();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org