Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop route in otherwise

Tags:

apache-camel

hi have a route like this

<route id="route1">
<from uri="activemq:queuer1"/>
    <choice>
        <when>
            <simple>${header.urn} regex '^user*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/user.xsl"/>
        </when>
        <when>
            <simple>${header.urn} regex '^userdata:.*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/userdata.xsl"/>
        </when>
        ....
        <otherwise>
            <setHeader headerName="errorMsg ">
                <constant>no xsl file for this type</constant>
            </setHeader>
            <to uri="activemq:error"/>
        </otherwise> 
    </choice>
    <process ref="importer"/>
</route>

Now if the route goes into the otherwise part, the message should not be processed. Can I somehow stop the route if message goes into the otherwise ?

On possibility would be I add the process part in all the when parts and delete it at the end. But we have already several when parts and more to come.

Other solution would be prefered.

like image 451
mjspier Avatar asked Jul 26 '11 13:07

mjspier


1 Answers

You can add a <stop/> to stop continue routing the message.

In Java code:

exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);

In Java DSL:

.when(simple("${in.header.CamelHttpResponseCode} == 404"))
    .stop()
.otherwise()
    ...
like image 150
Claus Ibsen Avatar answered Oct 07 '22 02:10

Claus Ibsen