/**
* {@inheritDoc}
*/
@Override
public RESTEasyBindingData decompose(Exchange exchange, RESTEasyBindingData target) throws Exception {
Message sourceMessage = exchange.getMessage();
Object content = sourceMessage.getContent();
if (exchange.getContract().getProviderOperation() != null) {
target.setOperationName(exchange.getContract().getProviderOperation().getName());
} else if (exchange.getContract().getConsumerOperation() != null) {
target.setOperationName(exchange.getContract().getConsumerOperation().getName());
}
if (exchange.getState().equals(ExchangeState.FAULT)) {
if (content instanceof WebApplicationException) {
throw (WebApplicationException)content;
} else if (content instanceof HandlerException) {
Throwable throwable = ((HandlerException)content).getCause();
if (throwable != null) {
if (throwable instanceof WebApplicationException) {
throw (WebApplicationException)throwable;
} else {
throw new WebApplicationException(throwable);
}
} else {
throw new WebApplicationException((HandlerException)content);
}
} else if (content instanceof Throwable) {
throw new WebApplicationException((Throwable)content);
} else {
throw new WebApplicationException(new Exception(sourceMessage.getContent(String.class)));
}
}
if (content != null) {
target.setParameters(new Object[]{content});
}