/** {@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;
  }
 /** {@inheritDoc} */
 @Override
 public Message compose(RESTEasyBindingData source, Exchange exchange) throws Exception {
   final Message message = super.compose(source, exchange);
   if (message.getContent() instanceof BaseClientResponse) {
     BaseClientResponse<?> clientResponse = (BaseClientResponse<?>) message.getContent();
     if (clientResponse.getResponseStatus() == Response.Status.NOT_FOUND) {
       throw new ItemNotFoundException("Item not found");
     }
   } else if (source.getOperationName().equals("addItem")
       && (source.getParameters().length == 2)) {
     // Wrap the parameters
     Item item = new Item((Integer) source.getParameters()[0], (String) source.getParameters()[1]);
     message.setContent(item);
   }
   return message;
 }
Esempio n. 3
0
 /** {@inheritDoc} */
 @Override
 public void mapTo(Context context, RESTEasyBindingData target) throws Exception {
   // delegate to parent to pick up existing context mapping logic for RESTEasy
   super.mapTo(context, target);
   // add a custom header
   target.addHeader("foo", "123");
 }