This content has been marked as final.
Show 3 replies
-
1. Re: Catching validation exception
trohovsky Aug 31, 2015 4:15 AM (in response to maciavelli)Hi Kuat,
it's not possible to do error handling in SubscribeRoute component in this case, because validation is done before the massage reaches the component. Creating of a custom message composer (Message Composition - SwitchYard - Project Documentation Editor) could be the way how to do it.
Cheers,
Tomas
-
2. Re: Catching validation exception
maciavelli Sep 23, 2015 12:09 AM (in response to trohovsky)Thank you, Tomas. Yeah, your post helped.
And below is my code, may be it helps to some developers:
public class SubscribeComposer extends RESTEasyMessageComposer { private Logger LOG = LoggerFactory.getLogger(this.getClass().getName()); public String stan; public String project; public String name; @Override public Message compose(RESTEasyBindingData source, Exchange exchange) throws Exception { Message target = super.compose(source, exchange); kz.atf.types.SubscribeRqu rqu = target.getContent(kz.atf.types.SubscribeRqu.class); stan = rqu.getMethod().getStan(); project = rqu.getMethod().getProject(); name = rqu.getMethod().getName(); return target; } @Override public RESTEasyBindingData decompose(Exchange exchange, RESTEasyBindingData target) throws Exception { LOG.info("state: " + exchange.getState()); kz.atf.types.common.Response r = new kz.atf.types.common.Response<SubscribeRspParams>(); SubscribeRspParams prm = new SubscribeRspParams(); SubscribeRsp rsp = new SubscribeRsp(); r.setStan(stan); r.setProject(project); r.setName(name); if (exchange.getContext().getProperty("exCaused") != null) { prm.setResponseCode("-1"); prm.setStatus((String) exchange.getContext().getProperty("exCaused").getValue()); } else { if (exchange.getState().equals(ExchangeState.FAULT)) { if (exchange.getMessage().getContent() instanceof HandlerException) { if (exchange.getMessage().getContent(String.class).contains("XmlValidator")) { HandlerException he = exchange.getMessage().getContent(HandlerException.class); String message = he.getMessage().substring(he.getMessage().indexOf("SAXParseException"), he.getMessage().length()); prm.setResponseCode("-1"); prm.setStatus(message); r.setParameters(prm); rsp.setMethod(r); throw new WebApplicationException( Response .status(Response.Status.FORBIDDEN) .entity(rsp) .type(MediaType.TEXT_XML) .build()); } } } else { prm.setResponseCode("00"); prm.setStatus("OK"); } } r.setParameters(prm); rsp.setMethod(r); exchange.getMessage().setContent(rsp); target = super.decompose(exchange, target); return target; } }
-
3. Re: Catching validation exception
igarashitm Sep 23, 2015 10:08 PM (in response to maciavelli)The another option would be to invoke XmlValidator programatically as opposed to use it in a declarative way. You can get a ValidationResult object directly in that way.