Claus Ibsen created CAMEL-26014:
-----------------------------------

             Summary: camel-smpp - the body of the producer: a stream is sent 
empty, the 8-bit options, InOut and unknown commands
                 Key: CAMEL-26014
                 URL: https://issues.apache.org/jira/browse/CAMEL-26014
             Project: Camel
          Issue Type: Bug
          Components: camel-smpp
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while checking the body types of the smpp component for the catalog 
(CAMEL-24961).

h4. 1. A stream body is sent as an empty short message, and no body fails with 
a NullPointerException

For SubmitSm (the default), SubmitMulti and ReplaceSm, the smpp producer 
converts the body to a String more than once: in {{determineAlphabet}} and 
again in {{getShortMessage}} ({{SmppSmCommand}}, main 56aa5f4970a6, lines 92, 
113 and 165). The first conversion reads a stream body to its end, and the 
stream is not reset in between, so the short message is empty. A body that is 
null fails with a NullPointerException at line 114 ({{Cannot invoke 
"String.getBytes(java.nio.charset.Charset)" because "body" is null}}), rather 
than with an error that says the body is missing.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against the jSMPP 
SMPPServerSimulator that the camel-smpp integration tests use:
* a body that is a ByteArrayInputStream of "Hello stream": the delivery receipt 
has an empty text;
* the same text as a java.io.File: the receipt has "Hello file";
* no body: the NullPointerException above.

*Proposed change*: convert the body once, and fail with an 
InvalidPayloadException when there is none.

h4. 2. The 8-bit dataCoding and alphabet options do not send a byte array as it 
is, as the headers do

The smpp producer sends a byte array body as it is only when the 
{{CamelSmppDataCoding}} header, or else the {{CamelSmppAlphabet}} header, is an 
8-bit value ({{SmppSmCommand.has8bitDataCoding}}, main 56aa5f4970a6, lines 
118-126). The endpoint options {{dataCoding}} and {{alphabet}} with the same 
value do not do this: the body is converted to a String in the charset of the 
exchange and encoded with the {{encoding}} option, so bytes that are not text 
become {{?}}, while the data_coding of the PDU says 8-bit.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against the jSMPP simulator, with 
a body of the bytes {{41 42 E9 FF}}:
* with the header {{CamelSmppDataCoding=4}}: the simulator receives the four 
bytes as they are;
* with the endpoint options {{dataCoding=4&alphabet=4}}: it receives {{AB??}}.

*Proposed change*: take the endpoint options into account when deciding to send 
the bytes as they are, after the headers.

h4. 3. After an InOut send the message has no body and loses its headers

All six commands of the smpp producer put their result headers on 
{{ExchangeHelper.getResultMessage(exchange)}} (for example 
{{SmppSubmitSmCommand}}, main 56aa5f4970a6, line 97). When the exchange is 
InOut, that is a new, empty message, so after the send the message has no body, 
and the headers set before the send are gone; only the result headers, such as 
{{CamelSmppId}}, are left. A route that answers an HTTP request with the SMS it 
sent answers with an empty body.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against the jSMPP simulator: a 
header {{marker}}, the body "Hello inout" and {{to: smpp://...}} with 
{{pattern: InOut}}: after the send the body is null, {{marker}} is gone, and 
{{CamelSmppId}} is set. With InOnly, the body and the headers stay.

*Proposed change*: set the result headers on the message of the exchange, as 
InOnly does.

h4. 4. A CamelSmppCommand value that is not a command sends the body as an SMS

The smpp producer picks the command from the {{CamelSmppCommand}} header, and a 
value it does not know means SubmitSm ({{SmppCommandType.fromExchange}}, main 
56aa5f4970a6, line 97). So a misspelled command, such as {{querySm}} for 
{{QuerySm}}, sends the body as an SMS.

Checked on 4.24.0-SNAPSHOT with {{camel run}} against the jSMPP simulator: 
{{CamelSmppCommand=querySm}} with the body "typo sends an SMS": the simulator 
logs "Receiving submit_sm 'typo sends an SMS'".

*Proposed change*: fail for a value that is not a command, and keep SubmitSm 
for a missing header.

_Claude Code on behalf of davsclaus_



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

Reply via email to