You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by wxkevin <ke...@collabraspace.com> on 2013/01/09 13:15:54 UTC

How can I tell if Apache Camel Splitter didn't split anything?

I have an Apache Camel Splitter such as the following:

...
from("{{direct.split}}")
  .split().method(splitter, "iterate").streaming()
     .stopOnException()
     .setHeader("{{header.index}}", simple("${property.CamelSplitIndex}++"))

     // Other processing

     .choice
     .when(property(Exchange.SPLIT_COMPLETE).isEqualTo(true))
        .setHeader("{{header.total}}", property(Exchange.SPLIT_SIZE))
        .to("{{bean.myService.update}}")
        .end()
     .end()
  .end()

...

where splitter in the call to "method()" is a custom iterator used to parse
the particular data I am dealing with.

Everything is fine when the XML data received has at least 1 element to
parse. My issue is when there are no elements to parse, which is legal since
there can be 0 to many elements. I want the call to "bean.myService.update"
to be called even in the cases where there are no elements to parse. In the
above code this call is not made in the case of 0 elements.

Any suggestions?




--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-tell-if-Apache-Camel-Splitter-didn-t-split-anything-tp5725181.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I tell if Apache Camel Splitter didn't split anything?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 9, 2013 at 3:33 PM, wxkevin <ke...@collabraspace.com> wrote:
> So I ended up using a class variable which is initially set to 0. If there
> are elements to parse then when the splitter is complete it will update the
> class variable through the use of a processor. Then after the splitter logic
> I call another processor to get the number of elements parsed. If still 0
> then I know nothing was parsed.
>
> It would be nice if the splitter provided a function to perform if there are
> no elements parsed. Is there a JIRA site or something similar for Apache
> Camel that I could propose this new functionality?
>

I guess you have a bit special use case. Even if some option is being
added to the splitter
to send out a empty/dummy message if no data, then you would need to
filter/content based router
to detect this , to deal with that specially.

The JIRA tracker is where you can add tickets for new ideas etc. Link from here
http://camel.apache.org/support


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-tell-if-Apache-Camel-Splitter-didn-t-split-anything-tp5725181p5725185.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How can I tell if Apache Camel Splitter didn't split anything?

Posted by wxkevin <ke...@collabraspace.com>.
So I ended up using a class variable which is initially set to 0. If there
are elements to parse then when the splitter is complete it will update the
class variable through the use of a processor. Then after the splitter logic
I call another processor to get the number of elements parsed. If still 0
then I know nothing was parsed.

It would be nice if the splitter provided a function to perform if there are
no elements parsed. Is there a JIRA site or something similar for Apache
Camel that I could propose this new functionality?



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-tell-if-Apache-Camel-Splitter-didn-t-split-anything-tp5725181p5725185.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I tell if Apache Camel Splitter didn't split anything?

Posted by wxkevin <ke...@collabraspace.com>.
It doesn't appear that Exchange.SPLIT_COMPLETE, Exchange.SPLIT_SIZE,
etc...are available outside the .splitter block. My original thought was to
use those provided properties.

I can try the always return 1 approach.



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-tell-if-Apache-Camel-Splitter-didn-t-split-anything-tp5725181p5725183.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I tell if Apache Camel Splitter didn't split anything?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 9, 2013 at 1:15 PM, wxkevin <ke...@collabraspace.com> wrote:
> I have an Apache Camel Splitter such as the following:
>
> ...
> from("{{direct.split}}")
>   .split().method(splitter, "iterate").streaming()
>      .stopOnException()
>      .setHeader("{{header.index}}", simple("${property.CamelSplitIndex}++"))
>
>      // Other processing
>
>      .choice
>      .when(property(Exchange.SPLIT_COMPLETE).isEqualTo(true))
>         .setHeader("{{header.total}}", property(Exchange.SPLIT_SIZE))
>         .to("{{bean.myService.update}}")
>         .end()
>      .end()
>   .end()
>
> ...
>
> where splitter in the call to "method()" is a custom iterator used to parse
> the particular data I am dealing with.
>
> Everything is fine when the XML data received has at least 1 element to
> parse. My issue is when there are no elements to parse, which is legal since
> there can be 0 to many elements. I want the call to "bean.myService.update"
> to be called even in the cases where there are no elements to parse. In the
> above code this call is not made in the case of 0 elements.
>
> Any suggestions?
>

You can either
- always return at least 1 in the iterator, and eg if you have empty,
then return a special response, and then
in the inlined content based router, you can detect this empty
response and call your bean.

Or you can after the splitter, see if there was any split complete
property on the exchange. The splitter ought to only set those if
there
was some splitter done. Then you can have filter that checks for this
and call your bean.

Though I think possible its cleaner to ensure there is always 1 data.




>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-tell-if-Apache-Camel-Splitter-didn-t-split-anything-tp5725181.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen