Hello all, I'm getting up to speed on Apache Camel and trying to replace a "message flow" that was originally written for IBM Message Broker 6.1. The flow involves receiving input from a SOAP service, looking up a value in a database, and returning that to the client (again, via SOAP). I have a route that works and now I'm trying to add exception handling to it. Ideally, an email can be generated when an exception occurs.
Here's my Route: public class FooRoute extends RouteBuilder { private String uri = "cxf:/foo?serviceClass=" + FooService.class.getName(); private Log log = LogFactory.getLog(FooRoute.class); @Autowired private MailSender mailSender; @Autowired private SimpleMailMessage mailMessage; @Override public void configure() throws Exception { onException(Exception.class) .process(new Processor() { public void process(Exchange exchange) throws Exception { Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); // email error mailMessage.setTo("mrai...@apache.org"); mailMessage.setSubject("ERROR!!"); mailMessage.setText("WTF?!\n\n " + exception.getMessage()); mailSender.send(mailMessage); } }); from(uri) .to("log:input") // send the request to the route to handle the operation // the name of the operation is in that header .recipientList(simple("direct:${header.operationName}")); from("direct:findById") .process(new Processor() { public void process(Exchange exchange) throws Exception { // get the id from the input String id = exchange.getIn().getBody(FooRequest.class).getId(); exchange.getOut().setBody(id); } }) .to("sql:select value from table where id = #?dataSource=ds") .to("log:output") .process(new Processor() { public void process(Exchange exchange) throws Exception { // get the value from the input List<HashMap> data = (ArrayList<HashMap>) exchange.getIn().getBody(); // todo: handle value is empty FooResponse response = new FooResponse(); response.setGpi(String.valueOf(data.get(0).get("value"))); exchange.getOut().setBody(response); } }).end(); } } The problem that I'm experiencing is that the Autowired dependencies from Spring are not getting set. Do I need to do something special to allow Spring dependencies in my route or is there an easier way to send exception emails? Here's how I have my routes configured using Spring's JavaConfig: @Configuration @ImportResource("classpath:META-INF/cxf/cxf.xml") public class CamelConfig extends CamelConfiguration implements InitializingBean { /** * Returns the CamelContext which support Spring */ @Override protected CamelContext createCamelContext() throws Exception { return new SpringCamelContext(getApplicationContext()); } @Override public List<RouteBuilder> routes() { List<RouteBuilder> routes = new ArrayList<>(); routes.add(new FooRoute()); return routes; } public void afterPropertiesSet() throws Exception {} } Thanks, Matt