Sorry my question was incomplete. Below the complete message:
----------------
Hi,
I would like to implement the following route with Camel 1.6 :
from("direct:endpointA")
.setHeader(HttpProducer.HTTP_URI).simple("http://myAddressA")
.to("http://xxxxxx")
.to("direct:endPointB")
from("direct:endpointB")
.setHeader(HttpProducer.HTTP_URI).simple("http://myAddressB")
.to("http://xxxxxx")
.to("direct:endPointC")
from("direct:endPointC")
.to("xquery:response.xml");
This route works fine if both URLs : http://myAddressA and
http://myAddressBare accessible and no error occurs during the
invocation.
Unfortunately, sometimes these services become unreachable and I would like
to try other URLs until getting valid answer:
If an exception happens when calling the URL http:/:myAddressA, I would like
to attempt other URLs : myAddressA1, myAddressA2, ...until getting valid
HTTP response.
The same thing with myAddressB ==> myAddressB1, myAddressB2, ...
With java this could be simply coded like following :
try
{
call_http(myAddressA)
}
catch(Throwable th)
{
try
{
call_http(myAddressA1)
}
catch(Exception x)
{
//Call addressA2
....
}
}
I've tried the Camel onException() mechanism and the deadLetterChannel EIP
processor but I never get working my route.
Below the code I've tried :
//Declare Deadletter processor
errorHandler(deadLetterChannel("direct:letter").onRedelivery(myProcessor));
//Declare global exception
onException(Exception.class).maximumRedeliveries(5) //5 : because I have 5
address maximum to call
final Processor myProcessor = new Processor()
{
public void process(Exchange exchange) throws Exception {
try
{
String uri =
exchange.getIn().getHeader(HttpProducer.HTTP_URI).toString();
if(uri.equals("http://myAddressA"))
uri="http://myAddressA1";
else if(uri.equals("http://myAddressA1"))
uri="http://myAddressA2";
else if(uri.equals("http://myAddressA2"))
uri="http://myAddressA3";
//etc
exchange.getIn().setHeader(HttpProducer.HTTP_URI, uri);
}
catch(Throwable error)
{
error.printStackTrace);
}
}
Your help will be appreciated.
Thanks