意外的宾迪行为 - 骆驼

时间:2013-02-21 14:23:36

标签: apache-camel

使用bindy时,我创建了一个提供无效CSV输入的测试。 查看文档(http://camel.apache.org/bindy.html)时,它指出:

If this field is not present in the record, than an error will be raised by the parser with the following information :
Some fields are missing (optional or mandatory), line :

但是当我运行测试时,只会忽略无效行,不会引发错误。我声明了三个必填字段,所以我预计会出错...我做错了什么?

百里

以下是一些澄清的代码片段

路线

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {

            JaxbDataFormat xmlFormat = new JaxbDataFormat();
            xmlFormat.setContextPath("be.smals.dp.asktutor.response");
            BindyCsvDataFormat csvFormat = new BindyCsvDataFormat ("be.smals.dp.asktutor.response");
            context.setTracing(true);

            from("direct:marshall")
                    .wireTap("log:test")
                    .unmarshal(csvFormat)
                    .to("mock:marshall");

            from("direct:unmarshall")
                    .marshal(xmlFormat)
                    .wireTap("log:test")
                    .to("mock:unmarshall");

        }
    };
}

我的部分考试

@Test
public void testTransformFromCSVToXML() throws Exception {

    // Create CSV input and process it
    String payload = AskTutorResponseCSVMother.getInvalidCSVLines();
    template.sendBody("direct:marshall", payload);

    AskTutorsResponse askTutorsResponse = 
        ExchangeToObjectHelper.getAskTutorsResponseObjectFromExchange(
            mockMarshall.getExchanges().get(0));
    assertEquals("00000000123", askTutorsResponse.getAskTutorResponses().get(0).getSsinChild());

输入csv字符串

public static String getInvalidCSVLines () {
    String payload = "";
    payload += "00000000321;20121212" + NEWLINE;
    payload += "10000000123;10000000321;20131010" + NEWLINE;
    payload += "20000000123;20000000321;20100909" + NEWLINE;
    return payload;        
}

我的(直接)绑定:

@XmlType
@XmlAccessorType(XmlAccessType.NONE)
@CsvRecord(separator = ";", skipFirstLine = false)
public class AskTutorResponse {

    @DataField(pos = 1, required = true)
    @XmlElement(name = "SINNChild", required = true)
    private String ssinChild;

    @DataField(pos = 2)
    @XmlElement(name = "SINNTutor", required = true)
    private String ssinTutor;

    @DataField(pos = 3)
    @XmlElement(name = "date", required = true)
    private String date;

1 个答案:

答案 0 :(得分:1)

我遇到过在同一个包中有多个带有bindy注释的类无法正确解组的问题。原因是bindy试图将每个CSV行解组为每个带注释的类的实例。我的第一个修复是将每个bindy类放入自己的包中。我已经编写了自己的bindy数据格式,允许将单个类指定为unmarshal目标。 Here is the code.