Copilot commented on code in PR #2326:
URL: https://github.com/apache/maven-resolver/pull/2326#discussion_r4605249749
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -133,12 +202,43 @@ public void generateException(T response,
BiConsumerChecked<Integer, String, E>
}
if (rfc9457Payload != null) {
throw new HttpRFC9457Exception(statusCode, reasonPhrase,
rfc9457Payload);
+ } else {
+ throw new HttpTransporterException(
+ statusCode, reasonPhrase,
generateBodyExtract(body, contentType));
}
- baseException.accept(statusCode, reasonPhrase);
- return;
+ } else {
+ // No body found but it is representing a RFC 9457 message due
to the content type.
+ throw new HttpRFC9457Exception(statusCode, reasonPhrase,
RFC9457Payload.INSTANCE);
}
- throw new HttpRFC9457Exception(statusCode, reasonPhrase,
RFC9457Payload.INSTANCE);
+ } else {
+ try {
+ body = getBody(response);
Review Comment:
With the JDK transporter, a non-RFC9457 error response that stalls before
EOF or the 64 KiB limit can now block in `getBody()` instead of reporting the
HTTP error. The configured timeout only covers response headers
(`JdkTransporter.java:812–815`), so the byte limit does not bound this wait.
Enforce a timeout for the diagnostic body read, close the stream on expiry, and
fall back to the status-only exception.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -49,12 +53,25 @@ public abstract class RFC9457Reporter<T, E extends
Exception, R> {
*/
public static final int MAX_BODY_BYTES = 64 * 1024;
- protected abstract boolean isRFC9457Message(T response);
+ /**
+ * Returns the content type of the response, or {@code null} if not
available.
+ * @param response The response to get the content type from.
+ * @return The content type of the response, or {@code null} if not
available, this should include optional parameters like charset.
+ */
+ protected abstract String getContentType(T response);
protected abstract int getStatusCode(T response);
protected abstract String getReasonPhrase(T response);
+ /**
+ * Returns the body of the response as a string, or {@code null} if not
available.
+ * The returned string should be truncated to {@link #MAX_BODY_BYTES}
bytes, and may be incomplete or malformed.
+ * @param response The response to get the body from.
+ * @return The body of the response as a string, or {@code null} if not
available.
+ * @throws IOException If an I/O error occurs while reading the body.
+ * @see #readBody(InputStream)
Review Comment:
This new reference points to a method that no longer exists: `readBody` now
requires both `InputStream` and `String`. Javadoc reports `error: reference not
found`, causing documentation generation to fail. Please update the reference
to the two-argument signature.
##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/connector/transport/http/RFC9457/RFC9457Reporter.java:
##########
@@ -133,12 +202,43 @@ public void generateException(T response,
BiConsumerChecked<Integer, String, E>
}
if (rfc9457Payload != null) {
throw new HttpRFC9457Exception(statusCode, reasonPhrase,
rfc9457Payload);
+ } else {
+ throw new HttpTransporterException(
+ statusCode, reasonPhrase,
generateBodyExtract(body, contentType));
}
- baseException.accept(statusCode, reasonPhrase);
- return;
+ } else {
+ // No body found but it is representing a RFC 9457 message due
to the content type.
+ throw new HttpRFC9457Exception(statusCode, reasonPhrase,
RFC9457Payload.INSTANCE);
}
- throw new HttpRFC9457Exception(statusCode, reasonPhrase,
RFC9457Payload.INSTANCE);
+ } else {
+ try {
+ body = getBody(response);
+ throw new HttpTransporterException(statusCode, reasonPhrase,
generateBodyExtract(body, contentType));
+ } catch (IOException e) {
+ throw new HttpTransporterException(statusCode, reasonPhrase);
+ }
+ }
+ }
+
+ /**
+ * Generates a body extract from the given body string (usually HTML)
+ * This method can be overridden to provide custom logic for generating a
body extract.
+ *
+ * @param body The body string to generate the extract from (already
truncated to {@link #MAX_BODY_BYTES} bytes).
+ * @param contentType The content type of the body, may be {@code null} if
unknown.
+ * @return The generated body extract.
+ */
+ public static String generateBodyExtract(String body, String contentType) {
+ if (contentType == null) {
+ return body;
+ }
+ final String lowerCaseContentType =
contentType.toLowerCase(Locale.ROOT);
+ if (lowerCaseContentType.equals("text")
+ || lowerCaseContentType.startsWith("text/")
+ || lowerCaseContentType.contains("json")) {
Review Comment:
XML error responses are textual, but `application/xml` and
`application/*+xml` fall through to `Binary data (...)`, discarding the
diagnostic body entirely. For example, an XML `<Error><Message>Access
denied</Message></Error>` response loses the very explanation this fallback is
meant to expose. Please recognize XML media types alongside JSON and text, and
cover them in the body-extract tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]