Claus Ibsen created CAMEL-26159:
-----------------------------------
Summary: camel-salesforce - a Map or plain POJO body on a REST
operation is sent as its toString, and raw with a Map body sends an empty POST
Key: CAMEL-26159
URL: https://issues.apache.org/jira/browse/CAMEL-26159
Project: Camel
Issue Type: Bug
Components: camel-salesforce
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while adding the catalog body types of salesforce (CAMEL-24961, PR
#28410).
h4. 1. A Map or non-DTO POJO body on a REST operation is sent as its toString
{{JsonRestProcessor.getRequestStream(Exchange)}} (main 2a465aa4814c, lines
145-158) tries {{InputStream}}, then {{AbstractDTOBase}}, and then falls back
to {{in.getBody(String.class)}}. A {{Map}} (or any POJO that does not extend
{{AbstractDTOBase}}) is therefore sent as its {{toString()}}, e.g.
{{\{Name=x\}}}, which is not JSON, and the producer gives no error. Checked on
4.24.0-SNAPSHOT with the module's okhttp MockWebServer: {{createSObject}} with
a {{Map}} body posts {{\{Name=x\}}}.
Proposed: marshal a {{Map}} or other POJO body with the processor's
{{objectMapper}}, as is done for DTOs, and use the String fallback only for
text.
h4. 2. raw with a Map body sends a POST with an empty body
{{RawProcessor}} (main 2a465aa4814c, line 89) reads the body with
{{getBody(InputStream.class)}}. A {{Map}} has no conversion to {{InputStream}},
so the result is null and the request is sent with an empty body, with no
error. Checked on 4.24.0-SNAPSHOT with the MockWebServer.
Proposed: fail with an {{InvalidPayloadException}} when a non-null body cannot
be converted (or marshal a Map as JSON).
h4. 3. Composite sObject collections: an unparseable response completes the
exchange with no exception and a null body
{{CompositeSObjectCollectionsProcessor.processResponse}} (main 2a465aa4814c,
line 180) calls {{responseBody.get()}} on the {{Optional}}. When the response
could not be parsed the {{Optional}} is empty, so a {{NoSuchElementException}}
is thrown on the HTTP client thread; the {{finally}} block still calls
{{callback.done(false)}}, so the exchange completes with no exception and a
null body (silent failure). Checked on 4.24.0-SNAPSHOT with the MockWebServer.
Proposed: check {{isPresent()}} and set a {{SalesforceException}} on the
exchange when the response is empty or unparseable.
h4. 4. The rawPayload option description says String, but the REST producer
returns an InputStream
The javadoc of {{SalesforceEndpointConfig.setRawPayload}} (main 2a465aa4814c,
line 330), used as the option description in the catalog and docs, says "Use
raw payload {{String}} for request and response". With {{rawPayload=true}} the
REST producer returns an {{InputStream}}, not a String. Checked on
4.24.0-SNAPSHOT with the MockWebServer.
Proposed: change the description to say the response is the raw payload as an
{{InputStream}} (JSON or XML depending on {{format}}) and regenerate the docs.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)