Search code examples
apache-camelognl

SimpleBuilder usage in camel


I have following processor, when I run it from my route I get the following error. I know exchange body is not null and you can see it in logs below. What is wrong with my usage of SimpleBuilder here ?

public class UpdateCustomerProcessor implements Processor {
    public static final Logger log = LoggerFactory.getLogger(UpdateCustomerProcessor.class);

    public void process(Exchange exchng) throws Exception {
        Customer c = (Customer) exchng.getIn().getBody(Object[].class)[0];
        System.out.println("Updating customer " + c.getFirstName() + " " + c.getLastName());
        System.out.println(SimpleBuilder.simple("Hello ${body.getFirstName()}").evaluate(exchng, String.class));
        exchng.getOut().setBody(new Object[] {});
    }

}

log->Updating customer aaa bbb
error-> org.apache.cxf.interceptor.Fault: Failed to invoke method: .getFirstName() on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: getFirstName() on null

Solution

  • I can't make sense of the "null"-exception, since exchange in appears to be filled. Nevertheless, your expression looks incorrect - since your exchange.in seems to hold an array, it should be:

    SimpleBuilder.simple("Hello ${body[0].firstname}").evaluate(exchng, String.class))