java.lang.IllegalArgumentException: Some fields are missing (optional or mandatory)

和自甴很熟 提交于 2019-12-05 02:28:58

I had a quick look at the camel bindy component tests and I could not find one that combines @FixedLengthRecord(header,footer ) with @Link

One possible workaround to your issue could be to

  1. Remove @Link from your header and footer fields in Order e.g

    
    
     @FixedLengthRecord(length = 4, paddingChar = ' ', header = OrderHeader.class, footer = OrderFooter.class)
        public class Order {
    
    
        private OrderHeader header;
        private  OrderFooter footer;
    } 
    

    2.Then the header and footer are successfully processed by bindy and added in the exchange as headers("CamelBindyFixedLengthHeader","CamelBindyFixedLengthFooter") so with a processor you can set them to the order header,footer fields afterwards e.g

    .unmarshal(bindy).split(body()).process(exchange -> { 
    Order order = exchange.getIn().getBody(Order.class);
    order.setFooter((OrderFooter)exchange.getIn().getHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_FOOTER,Map.class).get(OrderFooter.class.getName())); order.setHeader((OrderHeader)exchange.getIn().getHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_HEADER,Map.class).get(OrderHeader.class.getName())); });

Related camel unit test here

Make sure your POJOs are public classes. Its not your POJO class that instantiate another class, its camel-bindy / camel-core and that code runs in org.apache.camel packages, and cannot rely on package visible access to POJOs. So bottom line, keep it public so its standard Java beans.

The camel-bindy sometimes tries to bind to the wrong model object.

A solution that I found on web was to try to put each model object in a different package.(not a clean solution but good enough to know where the issue lies - with our code or with library)

I was getting a similar exception & although this solution didn't work for me but maybe you can give it a try.

You can see the details, here: Camel-bindy exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!