[
https://issues.apache.org/jira/browse/CAMEL-19512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17740957#comment-17740957
]
Nicolas Filotto commented on CAMEL-19512:
-----------------------------------------
After a deeper analysis, it appears that the behavior change is due to
CAMEL-19026, and the problem is not limited to {{InputStreamCache}}, it occurs
with any {{InputStream}} with {{setBacklogTracing(true)}} like in the test
project attached to this ticket.
Before CAMEL-19026, no message as XML was built with
{{setBacklogTracing(true)}} which implies that the headers were not read but
since CAMEL-19026, messages are built as XML such that the value of headers are
read more times so if the stream is not reset explicitly (streams in the body
are reset automatically if possible), we end up with no content when we try to
read it later which is the behavior that you get.
As a workaround, please avoid enabling the backlog tracing if not needed but
also avoid setting stream values to headers and properties, it is not a good
practice as your route won't be idempotent, indeed adding a simple logger to
display the content of your header can affect the result of your route while it
should not.
Try to rely on the result type of an expression to set value with a specific
type like for example {{setHeader("myheader2").simple("${body}",
String.class)}}, this way, you can read the content of your header as many
times as you want without affecting the overall result.
[~davsclaus] Maybe this behavior change should be documented somewhere, don't
you agree?
> SetHeader not working anymore with InputStreamCache type
> --------------------------------------------------------
>
> Key: CAMEL-19512
> URL: https://issues.apache.org/jira/browse/CAMEL-19512
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 3.20.3
> Environment: JDK 11
> Reporter: Xilai Dai
> Assignee: Nicolas Filotto
> Priority: Minor
> Attachments: test-setheader.zip
>
>
> It seems there is a regression from Camel 3.20.3 which is the SetHeader not
> working anymore with InputStreamCache type.
> Given that a simple route:
> {code}
> from("timer:cTimer_1" + "?period=" + 1 + "&repeatCount=" + 1 +
> "&delay=" + 1)
> .setHeader("myheader1").constant("Hi")
> .log(org.apache.camel.LoggingLevel.WARN, "MyRoute.cLog_1",
> "header myheader1 value is: ${header.myheader1}")
> .setHeader("myheader2").constant(iscache1)
> .log(org.apache.camel.LoggingLevel.WARN, "MyRoute.cLog_2",
> "header myheader2 value is: ${header.myheader2}")
> .setBody().constant(iscache2)
> .log(org.apache.camel.LoggingLevel.WARN, "MyRoute.cLog_3",
> "body value is: ${body}");
> {code}
> the value of header.myheader2 is always null from Camel 3.20.3, whereas in
> Camel 3.20.2 or earlier version, it worked as expected.
> Attached a sample project for easily reproduce the issue.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)