Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9476

camel-bindy doesn't pad fixed length records

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.16.1
    • Fix Version/s: 2.18.0
    • Component/s: camel-bindy
    • Labels:
      None
    • Estimated Complexity:
      Novice

      Description

      Reading CAMEL-6039 one gets the impression that camel-bindy will pad fixed length records if the input record is smaller than the fixed length.

      https://camel.apache.org/bindy.html:

      When the size of the data does not fill completely the length of the field, we can then add 'padd' characters.

      This is not the case as the following test demonstrates. It fails with

      java.lang.IllegalArgumentException: Size of the record: 5 is not equal to the value provided in the model: 10
      	at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.createModel(BindyFixedLengthDataFormat.java:248)
      	at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.unmarshal(BindyFixedLengthDataFormat.java:209)
      	at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69)
      
      import org.apache.camel.EndpointInject;
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.component.mock.MockEndpoint;
      import org.apache.camel.dataformat.bindy.annotation.DataField;
      import org.apache.camel.dataformat.bindy.annotation.FixedLengthRecord;
      import org.apache.camel.model.dataformat.BindyType;
      import org.apache.camel.test.junit4.CamelTestSupport;
      import org.junit.Test;
      
      public class BindyTest extends CamelTestSupport {
      
          public static final String URI_DIRECT_UNMARSHAL = "direct:unmarshall";
          public static final String URI_MOCK_UNMARSHAL_RESULT = "mock:unmarshal_result";
      
          @EndpointInject(uri = URI_MOCK_UNMARSHAL_RESULT)
          private MockEndpoint unmarhsalResult;
      
          @Override
          protected RouteBuilder createRouteBuilder() throws Exception {
              return new RouteBuilder() {
                  @Override
                  public void configure() throws Exception {
                      from(URI_DIRECT_UNMARSHAL)
                          .unmarshal().bindy(BindyType.Fixed, MyBindyModel.class)
                          .to(URI_MOCK_UNMARSHAL_RESULT);
                  }
              };
          }
      
          @Test
          public void testUnmarshal() throws Exception {
              unmarhsalResult.expectedMessageCount(1);
              template.sendBody(URI_DIRECT_UNMARSHAL, "foo  \r\n");
      
              unmarhsalResult.assertIsSatisfied();
              MyBindyModel myBindyModel = unmarhsalResult.getReceivedExchanges().get(0).getIn().getBody(MyBindyModel.class);
              assertEquals("foo  ", myBindyModel.foo);
      
          }
      
          @FixedLengthRecord(length = 10)
          public class MyBindyModel {
              @DataField(pos = 0, length = 5)
              String foo;
      
              @DataField(pos = 5, length = 5)
              String bar;
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              anoordover Arno Noordover
              Reporter:
              jgogstad Jostein Gogstad
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: