Reputation: 2820
I have a simple Camel route with a Netty 4 part as client to a socket. If the socket is not reachable, an java.net.ConnectException is thrown correctly but is not caught in the onException configured part but delivered as Exchange body. Is there any chance to catch this one?
Routebuilder
public void configure() throws Exception {
if (faultProcessor != null) {
onException(Exception.class).handled(true).process(faultProcessor).stop();
}
from(from)
.routeId(routeId)
.process(preProcessor)
.loadBalance()
.failover(attempts, false, true, java.io.IOException.class)
.to("netty4:tcp://server:port?clientMode=true&sync=true&allowDefaultCodec=false&clientInitializerFactory=#clientInitializerFactory&disconnect=true&usingExecutorService=false&workerGroup=#sharedPool")
.end()
.process(postProcessor)
.to(to);
}
Stacktrace
java.net.ConnectException: Cannot connect to server:port
at org.apache.camel.component.netty4.NettyProducer.openChannel(NettyProducer.java:419)
at org.apache.camel.component.netty4.NettyProducer$NettyProducerPoolableObjectFactory.makeObject(NettyProducer.java:487)
at org.apache.camel.component.netty4.NettyProducer$NettyProducerPoolableObjectFactory.makeObject(NettyProducer.java:482)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)
at org.apache.camel.component.netty4.NettyProducer.process(NettyProducer.java:201)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.loadbalancer.FailOverLoadBalancer.processExchange(FailOverLoadBalancer.java:277)
at org.apache.camel.processor.loadbalancer.FailOverLoadBalancer.process(FailOverLoadBalancer.java:232)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
Upvotes: 2
Views: 730
Reputation: 6853
You happen to configure the load balancer step to not inherit the error handler of the route. The error handler should fire if you use
.failover(java.io.IOException.class)
or
.failover(attempts, true, true, java.io.IOException.class)
Upvotes: 1