When().choice() & Filter() DSL not supported together !!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

When().choice() & Filter() DSL not supported together !!

Charles Moulliard
Hi,

I would lie to know why the following route cannot be configurated and if there is a workaround ?

from("")
.choice()
.when.xpath("")
        .setHeader("name").xpath("")
        .filter().xquery("extract a part of the XML")
            .unmarshall()
        .to("queue:A")
        .end()
.otherwise().to("queue:B");

Regards,

charles
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: When().choice() & Filter() DSL not supported together !!

gertv
Charles,

The end() method returns the raw ProcessorType.  You need a ChoiceType
in order to be able to access the otherwise() method.
One option would be to assign the result of from("")....end() to a local
variable of type ChoiceType -- adding the necessary cast.  Afterwards,
you can add the otherwise().  Somthing like:
  ChoiceType choice = (ChoiceType)
from("").choice().when()....to("queue:A").end();
  choice.otherwise.to("queue:A")

Another option would be to extract the routing logic for the first
when() clause in a separate route (starting with e.g. a direct: style
endpoint) and just code
when().xpath().to("direct:when1").otherwise().to("queue:B").

We are currently adding a Scala DSL, which will allow you to use {} to
explicitly define the blocks in your routes (have a look at
http://activemq.apache.org/camel/scala-dsl-eip.html for some examples).

Regards,

Gert

cmoulliard wrote:

> Hi,
>
> I would lie to know why the following route cannot be configurated and if
> there is a workaround ?
>
> from("")
> .choice()
> .when.xpath("")
>         .setHeader("name").xpath("")
>         .filter().xquery("extract a part of the XML")
>             .unmarshall()
>         .to("queue:A")
>         .end()
> .otherwise().to("queue:B");
>
> Regards,
>
> charles
>  

Reply | Threaded
Open this post in threaded view
|

Re: When().choice() & Filter() DSL not supported together !!

Charles Moulliard

Gert Vanthienen wrote
Charles,

The end() method returns the raw ProcessorType.  You need a ChoiceType
in order to be able to access the otherwise() method.
One option would be to assign the result of from("")....end() to a local
variable of type ChoiceType -- adding the necessary cast.  Afterwards,
you can add the otherwise().  Somthing like:
  ChoiceType choice = (ChoiceType)
from("").choice().when()....to("queue:A").end();
  choice.otherwise.to("queue:A")

Another option would be to extract the routing logic for the first
when() clause in a separate route (starting with e.g. a direct: style
endpoint) and just code
when().xpath().to("direct:when1").otherwise().to("queue:B").

We are currently adding a Scala DSL, which will allow you to use {} to
explicitly define the blocks in your routes (have a look at
http://activemq.apache.org/camel/scala-dsl-eip.html for some examples).

Regards,

Gert

cmoulliard wrote:
> Hi,
>
> I would lie to know why the following route cannot be configurated and if
> there is a workaround ?
>
> from("")
> .choice()
> .when.xpath("")
>         .setHeader("name").xpath("")
>         .filter().xquery("extract a part of the XML")
>             .unmarshall()
>         .to("queue:A")
>         .end()
> .otherwise().to("queue:B");
>
> Regards,
>
> charles
>  



-----
---
Gert Vanthienen
http://www.anova.be
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com