package com.sagacloud.route; /* * Author: Jxing * Create Time: 2018/7/12 */ import com.sagacloud.Exceptions.InvalidPostException; import com.sagacloud.utils.VendersUtil; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.http.common.HttpOperationFailedException; public class ExceptionHandlerBaseRoute extends RouteBuilder { @Override public void configure() throws Exception { } protected void configExceptionHandler(){ onException(InvalidPostException.class).handled(true).process(new org.apache.camel.Processor() { @Override public void process(Exchange exchange) throws Exception { Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); exchange.getOut().setBody(VendersUtil.errorJsonMsg(exception.getMessage())); } }); onException(HttpOperationFailedException.class).handled(true).process(new org.apache.camel.Processor() { @Override public void process(Exchange exchange) throws Exception { Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); exchange.getOut().setBody(VendersUtil.errorJsonMsg("连接异常")); } }); } }