Skip to content

Fix logging of error response body in AS2SenderModule#545

Merged
uhurusurfa merged 1 commit into
OpenAS2:masterfrom
JakeHuneau-LSPedia:patch-1
Jun 22, 2026
Merged

Fix logging of error response body in AS2SenderModule#545
uhurusurfa merged 1 commit into
OpenAS2:masterfrom
JakeHuneau-LSPedia:patch-1

Conversation

@JakeHuneau-LSPedia

Copy link
Copy Markdown
Contributor

Fix HTTP error response body logging in AS2SenderModule

Problem

When a partner returns a non-2xx HTTP response code, the error log message displays the raw Java byte array reference instead of the actual response body content.

Example of current broken output:

Error sending message. URL: https://partner.com:443/as2/incoming ::: Response Code: 500 Internal error. ::: Response Message: [B@24733dd5

This is caused by calling .toString() on the byte[] returned by resp.getBody(), which in Java outputs the type prefix [B and the object hash code rather than the string content.

Fix

Replace .toString() with new String(resp.getBody(), StandardCharsets.UTF_8) to correctly decode the response body bytes into a readable string.

Changes

AS2SenderModule.javasendMessage() method:

// Before
msg.setLogMsg("Error sending message. URL: " + url + " ::: Response Code: " + rc + " " + resp.getStatusPhrase() + " ::: Response Message: " + resp.getBody().toString());

// After
msg.setLogMsg("Error sending message. URL: " + url + " ::: Response Code: " + rc + " " + resp.getStatusPhrase() + " ::: Response Message: " + new String(resp.getBody(), java.nio.charset.StandardCharsets.UTF_8));

Impact

No behavioral change — error handling and resend logic are unaffected. This only improves the content of the log message so that partner error responses are human-readable, which significantly aids in debugging failed transmissions.

Updated log message to decode response body as UTF-8.

@uhurusurfa uhurusurfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for the fix.

@uhurusurfa uhurusurfa merged commit f8586e3 into OpenAS2:master Jun 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants