private Throwable detectHandlerException(Throwable throwable) { if (throwable instanceof HandlerException) { return (HandlerException) throwable; } return new HandlerException(throwable); }
private Object unwrapFault(Object fault) { if (fault instanceof HandlerException) { Throwable cause = ((HandlerException)fault).getCause(); if (cause != null) { return unwrapFault(cause); } } if (fault instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException)fault).getCause(); if (cause != null) { return unwrapFault(cause); } } return fault; }
@Override public ReferenceInvocation invoke() throws Exception { if (!isNew()) { throw new IllegalStateException( "Repeated calls to invoke() on ExchangeInvocation are not permitted"); } _exchange.send(_inMessage); if (_replyHandler.isFault()) { Object error = _replyHandler.getExchange().getMessage().getContent(); // Handling case where fault content is not an exception if (!Throwable.class.isAssignableFrom(error.getClass())) { throw createException(_replyHandler.getExchange()); } // Unwrap HandlerException instances if appropriate if (error instanceof HandlerException) { HandlerException haEx = (HandlerException)error; error = haEx.isWrapper() ? haEx.getCause() : haEx; } // Time to throw up! if (error instanceof Exception) { throw (Exception)error; } else { throw new Exception((Throwable)error); } } return this; }
@Override public void handleMessage(Exchange exchange) { HandlerRef handlerRef = null; try { for (HandlerRef ref : listHandlers()) { handlerRef = ref; if (_logger.isDebugEnabled()) { _logger.debug("Executing ExchangeHandler (" + ref + ") on message Exchange instance (" + System.identityHashCode(exchange) + ")."); } ref.getHandler().handleMessage(exchange); if (exchange.getState() == ExchangeState.FAULT) { // Exchange state has changed to FAULT. // Stop executing handlers.... break; } } } catch (HandlerException handlerEx) { StringBuilder errorMsg = new StringBuilder(handlerEx.getClass().getName() + " was thrown by handler(" + handlerRef.getName() + "): " + handlerEx.getMessage()); Throwable cause = handlerEx; while ((cause = cause.getCause()) != null) { errorMsg.append(" --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage()); } _logger.error(errorMsg.toString()); _logger.debug("", handlerEx); Message faultMessage = exchange.createMessage().setContent(handlerEx); exchange.sendFault(faultMessage); } }
/** * {@inheritDoc} */ @Override public void compose(Object obj, Graph graph) { super.compose(obj, graph); Throwable throwable = (Throwable)obj; setMessage(throwable.getMessage()); setCause(NodeBuilder.build(throwable.getCause(), graph)); setStackTrace(NodeBuilder.build(throwable.getStackTrace(), graph)); if (throwable instanceof HandlerException) { setWrapper(((HandlerException)throwable).isWrapper()); } }
@Override public ReferenceInvocation invoke() throws Exception { if (!isNew()) { throw new IllegalStateException( "Repeated calls to invoke() on ExchangeInvocation are not permitted"); } _exchange.send(_inMessage); if (_replyHandler.isFault()) { Object error = _replyHandler.getExchange().getMessage().getContent(); // Handling case where fault content is not an exception if (!Throwable.class.isAssignableFrom(error.getClass())) { throw createException(_replyHandler.getExchange()); } // Unwrap HandlerException instances if appropriate if (error instanceof HandlerException) { HandlerException haEx = (HandlerException)error; error = haEx.isWrapper() ? haEx.getCause() : haEx; } // Time to throw up! if (error instanceof Exception) { throw (Exception)error; } else { throw new Exception((Throwable)error); } } return this; }
@Override public void handleMessage(Exchange exchange) { HandlerRef handlerRef = null; try { for (HandlerRef ref : listHandlers()) { handlerRef = ref; if (_logger.isDebugEnabled()) { _logger.debug("Executing ExchangeHandler (" + ref + ") on message Exchange instance (" + System.identityHashCode(exchange) + ")."); } ref.getHandler().handleMessage(exchange); if (exchange.getState() == ExchangeState.FAULT) { // Exchange state has changed to FAULT. // Stop executing handlers.... break; } } } catch (HandlerException handlerEx) { StringBuilder errorMsg = new StringBuilder(handlerEx.getClass().getName() + " was thrown by handler(" + handlerRef.getName() + "): " + handlerEx.getMessage()); Throwable cause = handlerEx; while ((cause = cause.getCause()) != null) { errorMsg.append(" --- Caused by " + cause.getClass().getName() + ": " + cause.getMessage()); } _logger.error(errorMsg.toString()); _logger.debug("", handlerEx); Message faultMessage = exchange.createMessage().setContent(handlerEx); exchange.sendFault(faultMessage); } }
private Throwable detectHandlerException(Throwable throwable) { if (throwable instanceof HandlerException) { return (HandlerException) throwable; } return new HandlerException(throwable); }
private Object unwrapFault(Object fault) { if (fault instanceof HandlerException) { Throwable cause = ((HandlerException)fault).getCause(); if (cause != null) { return unwrapFault(cause); } } if (fault instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException)fault).getCause(); if (cause != null) { return unwrapFault(cause); } } return fault; }
Assert.assertTrue(content instanceof HandlerException); String testString = "Transformations not applied. Required payload type of 'toB'. Actual payload type is 'fromA'. You must define and register a Transformer to transform between these types."; boolean transformsApplied = ((HandlerException)content).getMessage().contains(testString); Assert.assertTrue(transformsApplied);
private HandlerException createHandlerException(Object content) { HandlerException ex; if (content == null) { ex = SCAMessages.MESSAGES.runtimeFaultOccurredWithoutExceptionDetails(); } else if (content instanceof HandlerException) { ex = (HandlerException)content; } else if (content instanceof Throwable) { ex = new HandlerException((Throwable)content); } else { ex = new HandlerException(content.toString()); } return ex; }
throw (WebApplicationException)content; } else if (content instanceof HandlerException) { Throwable throwable = ((HandlerException) content).getCause(); if (throwable != null) { if (throwable instanceof WebApplicationException) {
Assert.assertTrue(content instanceof HandlerException); boolean failed = ((HandlerException)content).getMessage().contains("Validator 'org.switchyard.tests.ValidationTest$2' failed: validation fail test"); Assert.assertTrue(failed);
private HandlerException createHandlerException(Object content) { HandlerException ex; if (content == null) { ex = SCAMessages.MESSAGES.runtimeFaultOccurredWithoutExceptionDetails(); } else if (content instanceof HandlerException) { ex = (HandlerException)content; } else if (content instanceof Throwable) { ex = new HandlerException((Throwable)content); } else { ex = new HandlerException(content.toString()); } return ex; }
throw (WebApplicationException)content; } else if (content instanceof HandlerException) { Throwable throwable = ((HandlerException) content).getCause(); if (throwable != null) { if (throwable instanceof WebApplicationException) {
@Override public void handleMessage(Exchange exchange) throws HandlerException { throw new HandlerException("explode"); } };
@Override public void handleMessage(Exchange exchange) throws HandlerException { throw new HandlerException("Fault With No Handler!"); } };
@Override public void handleMessage(Exchange exchange) throws HandlerException { throw new HandlerException("explode"); } };
/** * Will extract the message content from the SwitchYard exchange and insert * it into the Camel Exchange's In body. * * @param switchYardExchange SwitchYards Exchange from which the payload will be extracted. * @throws HandlerException If there was an exception while trying to extract the payload from * the SwitchYard Exchange. */ @Override public void handleMessage(final Exchange switchYardExchange) throws HandlerException { try { compose(switchYardExchange); } catch (Exception e) { throw new HandlerException(e); } }
/** * Will extract the message content from the SwitchYard exchange and insert * it into the Camel Exchange's In body. * * @param switchYardExchange SwitchYards Exchange from which the payload will be extracted. * @throws HandlerException If there was an exception while trying to extract the payload from * the SwitchYard Exchange. */ @Override public void handleMessage(final Exchange switchYardExchange) throws HandlerException { try { compose(switchYardExchange); } catch (Exception e) { throw new HandlerException(e); } }