Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public RESTEasyBindingData decompose(Exchange exchange, RESTEasyBindingData target)
      throws Exception {
    Object content = exchange.getMessage().getContent();
    if (exchange.getState().equals(ExchangeState.FAULT)) {
      if (content instanceof HandlerException) {
        HandlerException he = (HandlerException) content;
        if (he.getCause() instanceof ItemNotFoundException) {
          throw (Exception) he.getCause();
        }
        if (he.getMessage() != null && he.getMessage().startsWith("SWITCHYARD014014")) {
          UnauthorizedException ue = new UnauthorizedException("Unauthorized");
          throw (Exception) ue;
        }
      }
    }

    target = super.decompose(exchange, target);

    if (target.getOperationName().equals("addItem")
        && (content != null)
        && (content instanceof Item)) {
      // Unwrap the parameters
      target.setParameters(new Object[] {((Item) content).getItemId(), ((Item) content).getName()});
    }
    return target;
  }
Ejemplo n.º 2
0
 protected static void assertCause(String message, Exchange exchange) {
   assertEquals(ExchangeState.FAULT, exchange.getState());
   HandlerException exception = exchange.getMessage().getContent(HandlerException.class);
   assertTrue(exception.isWrapper());
   assertNotNull("Cause should not be null", exception.getCause());
   assertEquals(message, exception.getCause().getMessage());
 }