Hello,
I am playing with "bean binding" on bean component. I know, that I can solve my 
requirements by another way. 
But anyway I think, that my "syntetic" example doesn't work how I expect (I 
tested it with Camel 2.11.2, 2.12.1).

I have a "streamBodyBindingBean" bean with this method:

public void bodyBinding(InputStream in) throws IOException {
  int byteCount = 0;
  int c;
  while((c = in.read()) != -1)
    byteCount++;
  System.out.println("ByteCount: " + byteCount);
}

And this route:

<route id="" trace="true">
  <from uri="direct://body-input-stream-binding-in"/>
  <to uri="bean://streamBodyBindingBean?method=bodyBinding(${body})"/>
  <!-- to uri="bean://isBodyBindingBean"/-->
  <to uri="mock://body-input-stream-binding-out"/>
</route>

Here is a way how I send exchange from test stuff:

ByteArrayInputStream in = new ByteArrayInputStream(
  "Small body, which I want to bind as InputStream".getBytes("UTF-8")
);
Exchange exchange = createExchangeWithBody(in);
exchange.getIn().setHeader("testHeader", "testHeader");
exchange.setPattern(ExchangePattern.InOnly);
template.send("direct://body-input-stream-binding-in", exchange);

In this case I got a sysout message: "ByteCount: 0".
When I used the commented variant in route, I got expected result: "ByteCount: 
47",  => is it an ${body} evaluation problem?

I think that the reason is MethodInfo class, line 526 (with strange comment for 
me):

// the parameter value was not already valid, but since the simple language 
have evaluated the expression
// which may change the parameterValue, so we have to check it again to see if 
its now valid
exp = exchange.getContext().getTypeConverter().convertTo(String.class, 
parameterValue);
// String values from the simple language is always valid
if (!valid) {
  ...
}

The line after "strange" comment caused that my "InputStream" is transformed 
into String (what can be a problem in case of "big" InputStream).
The question is, why this line isn't in "if(!valid)" block? I am unable to 
decide, if it is a problem, which should be reported to JIRA or 
I only don't understand how bean binding should work or if I have only 
"stupid/incorrect" example.

This i a reason, why I ask first here.

Thank you for any feedback.
Radek Kraus.

Reply via email to