I 'm trying to use camel for redirecting an http request based on the contents of the request body.
I 've created an endpoint for receiving http requests and I 'm able to successfully redirect my request to a different URL, using the following route;
<route>
<from uri="servlet:myapptest2?matchOnUriPrefix=true"/>
<to uri="http://sampleurl/test?bridgeEndpoint=true&throwExceptionOnFailure=false" />
</route>
But I 'm not able to figure out a way to check the http request body. My HTTP request will be having a JSON body similar to this;
{
"testLoginRequest": {
"sampleData1": [{
"key1": "val1",
"key2": "val2"
}],
"sampleData2": [{
"key1": "val1",
"key2": "val2"
}]
}
}
I want to redirect the request to a specific URL if the JSON contains the value "testLoginRequest". I read that this should be possible like ;
from("direct:test").
choice().
when(body().contains("javainuse1"))
.to("jms:queue:javainuse1").
otherwise().
to("jms:queue:otherwise");
Since I have to use the XML DSL, I tried implementing the following route, but it doesn't seem to work;
<route>
<from uri="servlet:myapptest3?matchOnUriPrefix=true" />
<choice>
<when>
<simple>${body} contains 'testLoginRequest' </simple>
<to uri="http://sampleurlforlogin/test?bridgeEndpoint=true&throwExceptionOnFailure=false" />
</when>
</choice>
</route>
Am I following the right approach. What am I doing wrong here?