// and the DONE status is always sent by the consumer (us)
if (exchange.getStatus() == ExchangeStatus.DONE) {
throw new IllegalStateException("Received a DONE status from the transformer");
// Errors must be sent back to the consumer
} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
MessageExchange me = (MessageExchange) store.load(consumerId);
fail(me, exchange.getError());
} else if (exchange.getFault() != null) {
// Faults must be sent to faultsTarget / target
if (faultsTarget != null || sendFaultsToTarget) {
// Retrieve the consumer MEP
URI mep = (URI) exchange.getProperty(CONSUMER_MEP);
if (mep == null) {
throw new IllegalStateException("Exchange does not carry the consumer MEP");
}
MessageExchange me = getExchangeFactory().createExchange(mep);
(faultsTarget != null ? faultsTarget : target).configureTarget(me, getContext());
me.setProperty(correlationConsumer, consumerId);
me.setProperty(correlationTransformer, exchange.getExchangeId());
store.store(exchange.getExchangeId(), exchange);
MessageUtil.transferToIn(exchange.getFault(), me);
send(me);
// Faults must be sent back to the consumer
} else {
MessageExchange me = (MessageExchange) store.load(consumerId);
if (me instanceof InOnly) {
// Do not use the fault has it may contain streams
// So just transform it to a string and send an error
String fault = new SourceTransformer().contentToString(exchange.getFault());
fail(me, new FaultException(fault, null, null));
done(exchange);
} else {
store.store(exchange.getExchangeId(), exchange);
MessageUtil.transferFaultToFault(exchange, me);
send(me);
}
}
// This is the answer from the transformer
} else if (exchange.getMessage("out") != null) {
// Retrieve the consumer MEP
URI mep = (URI) exchange.getProperty(CONSUMER_MEP);
if (mep == null) {
throw new IllegalStateException("Exchange does not carry the consumer MEP");
}
MessageExchange me = getExchangeFactory().createExchange(mep);
target.configureTarget(me, getContext());
me.setProperty(correlationConsumer, consumerId);
me.setProperty(correlationTransformer, exchange.getExchangeId());
store.store(exchange.getExchangeId(), exchange);
MessageUtil.transferOutToIn(exchange, me);
send(me);
// This should not happen
} else {