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/01/12 13:28:31 UTC

[jira] [Comment Edited] (CAMEL-5953) Java DSL: unmarshal() inside choice() blocks adding more conditions

    [ https://issues.apache.org/jira/browse/CAMEL-5953?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13551900#comment-13551900 ] 

Claus Ibsen edited comment on CAMEL-5953 at 1/12/13 12:27 PM:
--------------------------------------------------------------

See this FAQ
http://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html

You can do this
{code}
from("direct:abc")
    .choice()
        .when(simple("${body} == 'Please do not fail'"))
            .to("log:test")
            .unmarshal(new XStreamDataFormat())
        .otherwise()
            .to("log:test")
        .end();
{code}
                
      was (Author: davsclaus):
    See this FAQ
http://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html

You can do this
{code}
from("direct:abc")
    .choice()
        .when(simple("${body} == 'Please do not fail'"))
            .to("log:test")
            .unmarshal("xstream")
        .otherwise()
            .to("log:test")
        .end();
{code}
                  
> Java DSL: unmarshal() inside choice() blocks adding more conditions
> -------------------------------------------------------------------
>
>                 Key: CAMEL-5953
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5953
>             Project: Camel
>          Issue Type: Bug
>    Affects Versions: 2.10.3
>            Reporter: Raul Kripalani
>
> This routing code leads to the exception below:
> {code}
> from("direct:abc")
>     .choice()
>         .when(simple("${body} == 'Please do not fail'"))
>             .to("log:test")
>             .unmarshal().xstream().endChoice()
>         .otherwise()
>             .to("log:test")
>         .end();
> {code}
> Exception:
> {code}
> Caused by: java.lang.ClassCastException: org.apache.camel.model.RouteDefinition cannot be cast to org.apache.camel.model.ChoiceDefinition
> 	at org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1256)
> 	at com.mycompany.MyRoute.configure(MyRoute.java:40)
> 	at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
> 	at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)
> 	at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)
> 	[...]
> {code}
> Also happens if we try to add another when instead of an otherwise.
> Tried using end(), endParent(), but they all lead to the same exception. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira