This content has been marked as final.
Show 1 reply
-
1. Re: Exception handling using Switchyard
maciavelli Jul 29, 2015 6:05 AM (in response to horyna)Hello, Pavel. If I correctly understand you can do that in your camel Route by catching required type of Exceptions.
public void configure() { onException(Exception.class) .handled(true) .to("direct://createRsp") .end();
Then you can customize response depending on Exception:
from("direct://createRsp") .process( exchange -> { Response r = new Response<SubscribeRspParams>(); SubscribeRspParams prm = new SubscribeRspParams(); Exception caused = exchange.getProperty( exchange.EXCEPTION_CAUGHT, Exception.class); if (caused != null) { prm.setResponseCode("-1"); prm.setStatus(caused.toString()); log.error("error: " + caused); } else { prm.setResponseCode("00"); prm.setStatus("OK"); } SubscribeRsp rsp = new SubscribeRsp(); r.setStan(stan); r.setProject(project); r.setName(name); r.setParameters(prm); rsp.setMethod(r); SwitchYardMessage out = new SwitchYardMessage(); out.setBody(rsp); exchange.setOut(out); log.info("Output message: " +exchange.getOut().getBody(String.class) ); });