use of org.apache.camel.dataformat.flatpack.FlatpackDataFormat in project camel by apache.
the class FlatpackDataFormatAutoConfiguration method configureFlatpackDataFormatFactory.
@Bean(name = "flatpack-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(FlatpackDataFormat.class)
public DataFormatFactory configureFlatpackDataFormatFactory(final CamelContext camelContext, final FlatpackDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
FlatpackDataFormat dataformat = new FlatpackDataFormat();
if (CamelContextAware.class.isAssignableFrom(FlatpackDataFormat.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
return dataformat;
}
};
}
use of org.apache.camel.dataformat.flatpack.FlatpackDataFormat in project camel by apache.
the class FlatpackFixedLengthWithHeaderAndTrailerDataFormatTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
FlatpackDataFormat df = new FlatpackDataFormat();
df.setDefinition("PEOPLE-HeaderAndTrailer.pzmap.xml");
df.setFixed(true);
from("direct:unmarshal").setHeader("MyFirstHeader", constant("1")).unmarshal(df).setHeader("MySecondHeader", constant("2")).to("mock:unmarshal");
// with the definition
from("direct:marshal").marshal(df).convertBodyTo(String.class).to("mock:marshal");
}
};
}
use of org.apache.camel.dataformat.flatpack.FlatpackDataFormat in project camel by apache.
the class FlatpackDelimitedDataFormatTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
FlatpackDataFormat df = new FlatpackDataFormat();
df.setDefinition("INVENTORY-Delimited.pzmap.xml");
from("direct:unmarshal").unmarshal(df).to("mock:unmarshal");
// with the definition
from("direct:marshal").marshal(df).convertBodyTo(String.class).to("mock:marshal");
// without the definition (will auto add column names from the recieved data)
FlatpackDataFormat df2 = new FlatpackDataFormat();
from("direct:marshal2").marshal(df2).convertBodyTo(String.class).to("mock:marshal2");
}
};
}
use of org.apache.camel.dataformat.flatpack.FlatpackDataFormat in project wildfly-camel by wildfly-extras.
the class FlatpackIntegrationTest method testUnmarshal.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshal() throws Exception {
final FlatpackDataFormat format = new FlatpackDataFormat();
format.setDefinition(FLATPACK_MAPPING_XML);
format.setFixed(true);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal(format);
}
});
camelctx.start();
try (InputStream input = getClass().getClassLoader().getResourceAsStream(FLATPACK_INPUT_TXT)) {
Assert.assertNotNull("Input not null", input);
ProducerTemplate producer = camelctx.createProducerTemplate();
List<Map<String, String>> result = producer.requestBody("direct:start", input, List.class);
Assert.assertEquals("Expected size 4: " + result, 4, result.size());
Assert.assertEquals("JOHN", result.get(0).get("FIRSTNAME"));
Assert.assertEquals("JIMMY", result.get(1).get("FIRSTNAME"));
Assert.assertEquals("JANE", result.get(2).get("FIRSTNAME"));
Assert.assertEquals("FRED", result.get(3).get("FIRSTNAME"));
} finally {
camelctx.stop();
}
}
use of org.apache.camel.dataformat.flatpack.FlatpackDataFormat in project camel by apache.
the class FlatpackFixedLengthDataFormatTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
FlatpackDataFormat df = new FlatpackDataFormat();
df.setDefinition("PEOPLE-FixedLength.pzmap.xml");
df.setFixed(true);
df.setIgnoreFirstRecord(false);
from("direct:unmarshal").unmarshal(df).to("mock:unmarshal");
// with the definition
from("direct:marshal").marshal(df).convertBodyTo(String.class).to("mock:marshal");
}
};
}
Aggregations