davsclaus commented on code in PR #28362:
URL: https://github.com/apache/camel/pull/28362#discussion_r4385929475
##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java:
##########
@@ -277,18 +276,30 @@ public ClassicHttpResponse execute(ClassicHttpRequest
request, HttpClientConnect
"Proxy " + route.getProxyHost().toHostString() + "
refused to forward the request to "
+ targetHost.toHostString() + ": " +
new StatusLine(response));
}
+ if (response instanceof ClassicHttpResponse classicResponse &&
classicResponse.getEntity() != null) {
Review Comment:
**Non-blocking: a parsed MDN is serialized and parsed a second time.**
When the response has a Content-Type,
`AS2BHttpClientConnection.receiveResponseEntity` has already replaced the
entity with a parsed `MimeEntity` during `endpoint.execute(...)`, for example a
`MultipartSignedEntity` or a `DispositionNotificationMultipartReportEntity`.
That entity is in memory and not streaming. Here `EntityUtils.toByteArray`
calls its `writeTo`, and the result goes into an `InputStreamEntity`.
`AS2ClientManager.sendRequest` then calls `parseAS2MessageEntity` again, and it
no longer sees an already-parsed entity, so every MDN is parsed twice.
It works today because the multipart parser skips the headers that `writeTo`
prepends to a non-main-body entity as preamble. But it depends on serialize,
then parse, giving back the same MDN, and that matters for signed MDN
verification. Only a raw entity, one the parser did not touch, still has unread
bytes on the socket. Copying only that one keeps the fix and leaves the parsed
MDN as it is:
```suggestion
if (response instanceof ClassicHttpResponse classicResponse &&
classicResponse.getEntity() != null
&& classicResponse.getEntity().isStreaming()) {
```
(The comment two lines down could then say that a parsed entity was already
read by `EntityParser` in `receiveResponseEntity`.)
--
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]