Hello Claus!

That's not (in my opinion) how it works currently. At present I work on a
route which looks like this:

errorHandler(
  defaultErrorHandler()
    .retryAttemptedLogLevel(LoggingLevel.DEBUG)
    .retriesExhaustedLogLevel(LoggingLevel.INFO));

onException(IllegalArgumentException.class)
  .handled(true)
  .maximumRedeliveries(0)
  .beanRef("myResultProvider", "failureResponse");

from("cxf:bean:MyCoolService")
  .processRef("myValidator") // validates conditional rules
  .inOut("direct:mySubroute")
  .beanRef("myResultProvider", "successResponse")


If my validator throws a IllegalArgumentException and the result provider
writes the response into the in message, the web service will return null.
But if I write the response into the out message, the web service will
return it. So, I changes my bean to the following "pattern":

if (exchange.getPattern().isOutCapable()) {
  exchange.getOut().setBody(response);
} else {
  exchange.getIn().setBody(response);
}

And that's the same how the org.apache.camel.processor.ConvertBodyProcessor
works (I know you know this, but for the other guys.. :o) )

public class ConvertBodyProcessor implements Processor {
...
    public void process(Exchange exchange) throws Exception {
        Message in = exchange.getIn();
        if (charset != null) {
            exchange.setProperty(Exchange.CHARSET_NAME, charset);
        }
        Object value = in.getMandatoryBody(type);

        if (exchange.getPattern().isOutCapable()) {
            Message out = exchange.getOut();
            out.copyFrom(in);
            out.setBody(value);
        } else {
            in.setBody(value);
        }
    }
...
}

Should our custom processors/beans/.. not work in the same way?

Cheers,
Christian

Reply via email to