This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 1141d54700d3351ae4e8759c25f1f50b69471c0b Author: opencode <[email protected]> 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 fb5b9138e9..594b9215f6 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: [email protected] For additional commands, e-mail: [email protected]
