[ 
https://issues.apache.org/jira/browse/CAMEL-9476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15353603#comment-15353603
 ] 

Arno Noordover edited comment on CAMEL-9476 at 6/28/16 7:47 PM:
----------------------------------------------------------------

I did the following:
* added a record-level property: ignoreMissingChars, default: false. When this 
is set to true lines which are too short will not throw an error;
* changed the parsing of the lines to support missing field;
* changed the trimming of field to match alignment and paddingCharacter.
This changes the trimming behaviour because default-alignment is right and 
trimming was done using String.trim().

I will do a CS check and push is to asf after rebasing.


was (Author: anoordover):
I did the following:
* added a record-level property: ignoreMissingChars, default: false. When this 
is set to true lines which are too short will not throw an error;
* changed the parsing of the lines to support missing field;
* changed the trimming of field to match alignment and paddingCharacter.
This changes the trimming behaviour because default-alignment is right and 
trimming was done using String.trim().

> camel-bindy doesn't pad fixed length records
> --------------------------------------------
>
>                 Key: CAMEL-9476
>                 URL: https://issues.apache.org/jira/browse/CAMEL-9476
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-bindy
>    Affects Versions: 2.16.1
>            Reporter: Jostein Gogstad
>            Assignee: Arno Noordover
>            Priority: Minor
>         Attachments: CAMEL_9476_Padding_and_trimming.patch
>
>
> 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:
> {quote}
> When the size of the data does not fill completely the length of the field, 
> we can then add 'padd' characters.
> {quote}
> This is not the case as the following test demonstrates. It fails with
> {code:none}
> 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)
> {code}
> {code:java}
> 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;
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to