[
https://issues.apache.org/jira/browse/CAMEL-25085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18120186#comment-18120186
]
Claus Ibsen commented on CAMEL-25085:
-------------------------------------
Merged to main by https://github.com/apache/camel/pull/26986 (4767770cff69).
Labelled for backport to camel-4.22.x and camel-4.18.x; left open until those
land. Thanks henrik242!
_Claude Code on behalf of davsclaus_
> Rest DSL: under json/xml binding a response without Content-Type ignores the
> verb's produces
> --------------------------------------------------------------------------------------------
>
> Key: CAMEL-25085
> URL: https://issues.apache.org/jira/browse/CAMEL-25085
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 4.18.4, 4.22.0, 4.22.1
> Reporter: Henrik
> Priority: Major
> Fix For: 4.18.5, 4.22.2, 4.23.0
>
>
> h3. Summary
> With {{bindingMode(json)}} set in the rest configuration, a verb that
> declares a non-json {{produces}} and returns a body without a Content-Type
> header gets {{{}Content-Type: application/json{}}}, and its body is passed
> through the json marshaller. For a binary body the marshalling fails and the
> client receives an empty HTTP 500.
> {code:java}
> restConfiguration().bindingMode(RestBindingMode.json);
> rest("/files").get("/{name}")
> .produces("application/octet-stream")
> .to("direct:download"); // sets an InputStream body, no Content-Type
> {code}
> 4.21.0 answered {{200 application/octet-stream}} with the file. 4.22.x
> answers {{{}500{}}}.
> h3. Cause
> CAMEL-24001 reordered {{RestBindingAdvice.ensureHeaderContentType}} so that
> the {{{}isJson{}}}/{{{}isXml{}}} flags are checked before the declared
> {{{}produces{}}}. When neither Accept, the Content-Type nor {{produces}}
> mentions json or xml, {{marshal}} derives {{isJson}} from the binding mode
> alone, so the flag is true for every verb under json binding and the declared
> media type is never used.
> The same applies to a {{produces("text/plain")}} verb called with {{{}Accept:
> application/json{}}}: before 4.18.4/4.22.0 it answered {{{}text/plain{}}},
> now it answers {{application/json}} with a json-quoted body.
> h3. Proposed fix
> When {{produces}} is set, pick the Content-Type from its entries: the first
> json entry if {{{}isJson{}}}, else the first xml entry if {{{}isXml{}}}, else
> the first entry. Only fall back to
> {{{}application/json{}}}/{{{}application/xml{}}} when {{produces}} is null.
> This keeps both CAMEL-24001 fixes (no Content-Type on body-less responses, a
> single media type instead of a raw multi-value {{{}produces{}}}).
> h3. Found in
> On the 4.21.0 -> 4.22.1 upgrade: two binary download endpoints started
> answering an empty 500, with nothing logged.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)