You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Jostein Gogstad (JIRA)" <ji...@apache.org> on 2016/01/04 15:28:40 UTC
[jira] [Created] (CAMEL-9476) camel-bindy doesn't pad fixed length
records
Jostein Gogstad created CAMEL-9476:
--------------------------------------
Summary: camel-bindy doesn't pad fixed length records
Key: CAMEL-9476
URL: https://issues.apache.org/jira/browse/CAMEL-9476
Project: Camel
Issue Type: Bug
Components: camel-bindy
Affects Versions: 2.16.1
Reporter: Jostein Gogstad
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");
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)