Claus Ibsen created CAMEL-26052:
-----------------------------------

             Summary: camel-as2 - client/send sends only text or a stream, an 
HTTP error does not fail the exchange, and more
                 Key: CAMEL-26052
                 URL: https://issues.apache.org/jira/browse/CAMEL-26052
             Project: Camel
          Issue Type: Bug
          Components: camel-as2
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of as2 (CAMEL-24961), checked with 
{{camel run}} with an as2 server/listen consumer, a receipt/receive consumer 
and client/send producers to them, all PLAIN messages.

h4. 1. client/send sends only text or a stream

With {{inBody=ediMessage}} the body is the {{ediMessage}} argument, an 
{{Object}}, so nothing converts it, and {{AS2ClientManager.send}} accepts only 
an {{InputStream}} or a {{String}} ({{AS2ClientManager}}, main 5aac7df76b83, 
lines 288-296). A byte[], a {{java.io.File}} or the {{GenericFile}} of a file 
consumer fails with "Message type not supported. Must be InputStream or 
String", wrapped in {{HttpException: Failed to create EDI message entity}} 
(line 301). So a route that sends the EDI files of a folder, {{from: file}} 
then {{to: as2:client/send}}, fails unless it converts the body to text first. 
Checked on 4.24.0-SNAPSHOT with {{camel run}}: a byte[], a File, a GenericFile 
from {{file:}} and a Map failed; text and a stream cache were sent.

*Proposed change*: convert the body to an InputStream when it is not a String 
or an InputStream already, or accept a byte[] and a file.

h4. 2. An HTTP error of the partner does not fail the exchange

The status of the response is not checked ({{AS2ClientManager}}, lines 
354-376), and {{AS2Producer.interceptResult}} sets the body to the receipt 
entity when there is one, and else to null (lines 41-53 of {{AS2Producer}}). So 
a 500 of the partner, such as a route of an as2 server that fails, gives a null 
body, as a send without a receipt does, and the exchange succeeds; only the 
HttpCoreContext in the exchange property {{CamelAs2.interchange}} shows the 
status. Checked on 4.24.0-SNAPSHOT with {{camel run}}: the server route threw, 
the server answered 500, and the client exchange did not fail.

*Proposed change*: fail the exchange for a status outside 2xx, or at least for 
one without a receipt.

h4. 3. The default of requestUri does not apply to client/send

{{AS2Configuration}} has {{@UriParam(defaultValue = "/") requestUri = "/"}} 
(lines 67-68), and the catalog says the default is "/". But the generated 
{{AS2ClientManagerEndpointConfiguration}} has its own {{requestUri}} field 
without a default (line 75), and only the set values are passed to the method, 
so a send without requestUri fails with "Missing properties for send, need one 
or more from (16 args)", which lists requestUri. The tests set it. Checked on 
4.24.0-SNAPSHOT with {{camel run}}.

*Proposed change*: apply the default, or mark requestUri required for 
client/send in the catalog.

h4. 4. ediMessageType is not read

The option {{ediMessageType}} is still documented, with the enum 
application/edifact, application/edi-x12, application/edi-consent and 
application/xml ({{AS2Configuration}}, lines 69-70), but the send reads 
{{ediMessageContentType}} only, so a send with ediMessageType fails with 
"Missing properties ... ediMessageContentType". The upgrade guide of 4.11 says 
ediMessageType was changed into two String options. The endpoint setter 
{{setEdiMessageContentType}} also sets {{ediMessageType}} ({{AS2Endpoint}}, 
lines 173-175). Checked on 4.24.0-SNAPSHOT with {{camel run}}.

*Proposed change*: remove or deprecate ediMessageType, and let the setter set 
ediMessageContentType.

h4. 5. ediMessageTransferEncoding=quoted-printable sends base64

For quoted-printable, {{EntityUtils}} encodes with a {{Base64OutputStream}} 
("TODO: implement QuotedPrintableOutputStream", lines 123-125), but the part is 
labelled quoted-printable, which the receiver decodes as such (the InputStream 
decode at lines 174-176 has the same mix-up). Checked on 4.24.0-SNAPSHOT with 
{{camel run}}: the server answered 500 to a quoted-printable message.

*Proposed change*: encode quoted-printable, or reject the option value.

h4. 6. The server logs an ERROR for every unencrypted message

Since CAMEL-22557 (4.16.0) the server puts the keys of the consumer in the 
HttpContext, reads the decrypting key back, and logs {{FATAL: Decrypting 
Private Key failed to be read back from HttpContext immediately after injection 
for path: ...}} at ERROR when it is null ({{AS2ServerConnection}}, lines 
316-319). A consumer of unencrypted messages has no decrypting key, so every 
PLAIN or signed message logs that line. Checked on 4.24.0-SNAPSHOT with {{camel 
run}}: each message to a server/listen consumer without a decrypting key logged 
it.

*Proposed change*: log only when the consumer has a decrypting key and the 
read-back fails, and not as FATAL.

h4. 7. The async MDN server logs an ERROR after each receipt

After an asynchronous receipt was received, {{AS2AsyncMDNServerConnection}} 
logged {{ERROR ... I/O exception: Connection is closed}} (line 215). Checked on 
4.24.0-SNAPSHOT with {{camel run}}, with receiptDeliveryOption set on the 
client and a receipt/receive consumer: the receipt reached the consumer, and 
the ERROR followed.

*Proposed change*: log a closed connection at DEBUG.

h4. Also read in the code, not run

* A request without an entity fails with a NullPointerException (an HTTP 500), 
on the server ({{HttpMessageUtils}}, line 136, then {{AS2Consumer}}, line 149) 
and on the receipt consumer ({{AS2AsyncMDNConsumer}}, lines 105-106).
* The docs list the apiName values client and server ({{as2-component.adoc}}, 
lines 37-40): receipt is missing.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to