This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit cdd2d17ae4a32a8794c337c3a47c05a8befd4f72 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 328a856d0c..40176a0073 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; @@ -299,6 +300,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]
