You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sujin sr <su...@gmail.com> on 2019/07/26 08:51:36 UTC

ClassCast Exception while using nested split

I am getting ClassCastException while trying to execute camel route

from("timer://messageSplitterTest?repeatCount=1")
        .process(exchange -> {
            Message message = exchange.getMessage();
            List<Message> ongoingMessages = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                Message listMessage = message.copy();
                listMessage.setHeader("count", String.valueOf(i));
                ongoingMessages.add(listMessage);
            }
            exchange.getIn().setBody(ongoingMessages);
            exchange.getIn().setHeader("primary", "true");
        })
        .choice()
            .when(header("primary").isEqualTo("true"))
                .split(body())
                .process(exchange -> {
                    Message msg = exchange.getMessage();
                    System.out.println("After Split, count=" +
msg.getHeader("count", String.class));
                })
                .split(body())
                .to("stream:out")
            .endChoice()
            .otherwise()
                .to("stream:out")
        .end()
;

I got below error

Exception in thread "main" java.lang.ClassCastException:
org.apache.camel.model.SplitDefinition cannot be cast to
org.apache.camel.model.ChoiceDefinition
	at org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1415)
	at com.temenos.tti.test.utils.camel.MessageSplitCamelTest4$1.configure(MessageSplitCamelTest4.java:40)


Kindly Help me to fix this error.

Re: ClassCast Exception while using nested split

Posted by sujin sr <su...@gmail.com>.
Thanks Claus. After adding end before endchoice my route is working now.

    .to("stream:out")
.end()
.endChoice()

My understanding about end & endchoice is that, end() will close the
choice() clause, endchoice() will close the when() clause. Then why do
we need another end() before endChoice in 2 split?

Correct me if my understanding is wrong.


On Fri, 26 Jul 2019 at 14:23, Claus Ibsen <cl...@gmail.com> wrote:

> You have 2 splits, so you need and end before the end choice
>
> On Fri, Jul 26, 2019 at 10:51 AM sujin sr <su...@gmail.com> wrote:
> >
> > I am getting ClassCastException while trying to execute camel route
> >
> > from("timer://messageSplitterTest?repeatCount=1")
> >         .process(exchange -> {
> >             Message message = exchange.getMessage();
> >             List<Message> ongoingMessages = new ArrayList<>();
> >             for (int i = 0; i < 10; i++) {
> >                 Message listMessage = message.copy();
> >                 listMessage.setHeader("count", String.valueOf(i));
> >                 ongoingMessages.add(listMessage);
> >             }
> >             exchange.getIn().setBody(ongoingMessages);
> >             exchange.getIn().setHeader("primary", "true");
> >         })
> >         .choice()
> >             .when(header("primary").isEqualTo("true"))
> >                 .split(body())
> >                 .process(exchange -> {
> >                     Message msg = exchange.getMessage();
> >                     System.out.println("After Split, count=" +
> > msg.getHeader("count", String.class));
> >                 })
> >                 .split(body())
> >                 .to("stream:out")
> >             .endChoice()
> >             .otherwise()
> >                 .to("stream:out")
> >         .end()
> > ;
> >
> > I got below error
> >
> > Exception in thread "main" java.lang.ClassCastException:
> > org.apache.camel.model.SplitDefinition cannot be cast to
> > org.apache.camel.model.ChoiceDefinition
> >         at
> org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1415)
> >         at
> com.temenos.tti.test.utils.camel.MessageSplitCamelTest4$1.configure(MessageSplitCamelTest4.java:40)
> >
> >
> > Kindly Help me to fix this error.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: ClassCast Exception while using nested split

Posted by Claus Ibsen <cl...@gmail.com>.
You have 2 splits, so you need and end before the end choice

On Fri, Jul 26, 2019 at 10:51 AM sujin sr <su...@gmail.com> wrote:
>
> I am getting ClassCastException while trying to execute camel route
>
> from("timer://messageSplitterTest?repeatCount=1")
>         .process(exchange -> {
>             Message message = exchange.getMessage();
>             List<Message> ongoingMessages = new ArrayList<>();
>             for (int i = 0; i < 10; i++) {
>                 Message listMessage = message.copy();
>                 listMessage.setHeader("count", String.valueOf(i));
>                 ongoingMessages.add(listMessage);
>             }
>             exchange.getIn().setBody(ongoingMessages);
>             exchange.getIn().setHeader("primary", "true");
>         })
>         .choice()
>             .when(header("primary").isEqualTo("true"))
>                 .split(body())
>                 .process(exchange -> {
>                     Message msg = exchange.getMessage();
>                     System.out.println("After Split, count=" +
> msg.getHeader("count", String.class));
>                 })
>                 .split(body())
>                 .to("stream:out")
>             .endChoice()
>             .otherwise()
>                 .to("stream:out")
>         .end()
> ;
>
> I got below error
>
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.camel.model.SplitDefinition cannot be cast to
> org.apache.camel.model.ChoiceDefinition
>         at org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1415)
>         at com.temenos.tti.test.utils.camel.MessageSplitCamelTest4$1.configure(MessageSplitCamelTest4.java:40)
>
>
> Kindly Help me to fix this error.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2