You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2013/10/04 11:11:42 UTC

[jira] [Resolved] (CAMEL-6810) Bean Component/BeanBinding: Body as InputStream parametr (specified as ${body} in route)

     [ https://issues.apache.org/jira/browse/CAMEL-6810?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-6810.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.13.0
                   2.12.2
                   2.11.3

Thanks for reporting

> Bean Component/BeanBinding: Body as InputStream parametr (specified as ${body} in route)
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-6810
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6810
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.11.2, 2.12.1
>            Reporter: Radek Kraus
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.11.3, 2.12.2, 2.13.0
>
>
> I discovered following problem (which was already shortly discussed in [Camel user forum|http://camel.465427.n5.nabble.com/Bean-component-Bean-Binding-Body-as-InputStream-parametr-specified-as-body-in-route-td5740656.ht]).
> I have a "streamBodyBindingBean" bean with this method:
> {code}
> public void bodyBinding(InputStream in) throws IOException {
>   int byteCount = 0;
>   int c;
>   while((c = in.read()) != -1)
>     byteCount++;
>   System.out.println("ByteCount: " + byteCount);
> }
> {code}
> And this route:
> {code}
> <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>
> {code}
> And here is a way how I send exchange from test stuff:
> {code}
> ByteArrayInputStream in = new ByteArrayInputStream(
>   "Small body, which I want to bind as InputStream".getBytes("UTF-8")
> );
> Exchange exchange = createExchangeWithBody(in);
> exchange.setPattern(ExchangePattern.InOnly);
> template.send("direct://body-input-stream-binding-in", exchange); 
> {code}
> In this case I got a sysout message: {{ByteCount: 0}}, but when I used the commented variant in the route, I got expected result: {{ByteCount: 47"}}.
> When I change the route and use bean component 2 times (both variant of bean method invocation), then I got:
> {noformat}
> 2013-10-01 12:26:37.259 DEBUG {main} [SendProcessor] >>>> Endpoint[bean://isBodyBindingBean?method=bodyBinding%28%24%7Bbody%7D%29] Exchange[Message: [Body is instance of org.apache.camel.StreamCache]]
> ByteCount: 0
> 2013-10-01 12:26:37.289 DEBUG {main} [SendProcessor] >>>> Endpoint[bean://isBodyBindingBean] Exchange[Message: [Body is instance of org.apache.camel.StreamCache]]
> ByteCount: 47
> 2013-10-01 12:26:37.307 DEBUG {main} [SendProcessor] >>>> Endpoint[mock://body-input-stream-binding-out] Exchange[Message: [Body is instance of org.apache.camel.StreamCache]] 
> {noformat}
> The strange for me is {{MethodInfo}} class, line 526:
> {code}
> // 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) {
>   ...
> }
> {code}
> The line after comment caused that my "InputStream" is transformed into String, what can be a problem in case of "big" InputStream.
> I know that I can use only second variant of "bean method invocation", which is enough for my need, but I only want to point out to this situation.



--
This message was sent by Atlassian JIRA
(v6.1#6144)