Java源码示例:org.apache.camel.spi.DataFormat
示例1
@Test
public void testMarshal() throws Exception {
DataFormat beanio = new BeanIODataFormat(MAPPINGS_XML, "customerStream");
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(beanio);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer customer = new Customer("Peter", "Post", "Street", "12345");
String result = producer.requestBody("direct:start", customer, String.class);
Assert.assertEquals("Peter,Post,Street,12345", result.trim());
} finally {
camelctx.close();
}
}
示例2
@Test
public void testUnmarshal() throws Exception {
DataFormat beanio = new BeanIODataFormat(MAPPINGS_XML, "customerStream");
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal(beanio);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
List<?> result = producer.requestBody("direct:start", "Peter,Post,Street,12345", List.class);
Assert.assertEquals(1, result.size());
Customer customer = (Customer) result.get(0);
Assert.assertEquals("Peter", customer.getFirstName());
Assert.assertEquals("Post", customer.getLastName());
Assert.assertEquals("Street", customer.getStreet());
Assert.assertEquals("12345", customer.getZip());
} finally {
camelctx.close();
}
}
示例3
@Test
public void testMarshal() throws Exception {
final DataFormat bindy = new BindyCsvDataFormat(Customer.class);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.marshal(bindy);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
Assert.assertEquals("John,Doe", result.trim());
} finally {
camelctx.close();
}
}
示例4
@Test
public void testUnmarshal() throws Exception {
final DataFormat bindy = new BindyCsvDataFormat(Customer.class);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.unmarshal(bindy);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer result = producer.requestBody("direct:start", "John,Doe", Customer.class);
Assert.assertEquals("John", result.getFirstName());
Assert.assertEquals("Doe", result.getLastName());
} finally {
camelctx.close();
}
}
示例5
@Test
public void testMarshalUnmarshal() throws Exception {
DataFormat avro = new AvroDataFormat(getSchema());
GenericRecord input = new GenericData.Record(getSchema());
input.put("name", "Kermit");
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(avro).unmarshal(avro);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
GenericRecord result = producer.requestBody("direct:start", input, GenericRecord.class);
Assert.assertEquals("Kermit", result.get("name").toString());
} finally {
camelctx.close();
}
}
示例6
private DataFormat lookupAndInstantiateDataformat(String dataformatName) {
DataFormat df = camel.resolveDataFormat(dataformatName);
if (df == null) {
df = camel.createDataFormat(dataformatName);
final String prefix = CAMEL_DATAFORMAT_PROPERTIES_PREFIX + dataformatName + ".";
final Properties props = camel.getPropertiesComponent().loadProperties(k -> k.startsWith(prefix));
CamelContextAware.trySetCamelContext(df, camel);
if (!props.isEmpty()) {
PropertyBindingSupport.build()
.withCamelContext(camel)
.withOptionPrefix(prefix)
.withRemoveParameters(false)
.withProperties((Map) props)
.withTarget(df)
.bind();
}
}
//TODO: move it to the caller?
if (df == null) {
throw new UnsupportedOperationException("No DataFormat found with name " + dataformatName);
}
return df;
}
示例7
public void configureJsonRoutes(JsonLibrary library, DataFormat dummyObjectDataFormat, DataFormat pojoADataFormat,
DataFormat pojoBDataFormat) {
fromF("direct:%s-in", library)
.wireTap("direct:" + library + "-tap")
.setBody(constant("ok"));
fromF("direct:%s-tap", library)
.unmarshal(dummyObjectDataFormat)
.toF("log:%s-out", library)
.split(body())
.marshal(dummyObjectDataFormat)
.convertBodyTo(String.class)
.toF("vm:%s-out", library);
fromF("direct:%s-in-a", library)
.wireTap("direct:" + library + "-tap-a")
.setBody(constant("ok"));
fromF("direct:%s-tap-a", library)
.unmarshal().json(library, PojoA.class)
.toF("log:%s-out", library)
.marshal(pojoADataFormat)
.convertBodyTo(String.class)
.toF("vm:%s-out-a", library);
fromF("direct:%s-in-b", library)
.wireTap("direct:" + library + "-tap-b")
.setBody(constant("ok"));
fromF("direct:%s-tap-b", library)
.unmarshal().json(library, PojoB.class)
.toF("log:%s-out", library)
.marshal(pojoBDataFormat)
.convertBodyTo(String.class)
.toF("vm:%s-out-b", library);
}
示例8
@Test
public void testLookupCustomServices() {
assertThat(registry.lookupByNameAndType("my-df", DataFormat.class)).isNotNull();
assertThat(registry.lookupByNameAndType("my-language", Language.class)).isNotNull();
assertThat(registry.lookupByNameAndType("my-component", Component.class)).isNotNull();
assertThat(registry.lookupByNameAndType("my-predicate", Predicate.class)).isNotNull();
assertThat(registry.lookupByNameAndType("my-processor", Processor.class)).isNotNull();
}
示例9
@Override
public Boolean executeTest(ITestConfig config, String dataFormat) throws Exception {
logger.info("Getting Camel dataFormat: {}", dataFormat);
DataFormat df = context.resolveDataFormat(dataFormat);
assertNotNull("Cannot get dataformat with name: " + dataFormat, df);
logger.info("Found Camel dataformat: {} instance: {} with className: {}", dataFormat, df, df.getClass());
return true;
}
示例10
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
DataFormat format = new ReverseDataFormat();
from("direct:in").marshal(format);
from("direct:back").unmarshal(format).to("mock:reverse");
}
};
}
示例11
@Override
public void configure() throws Exception {
final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);
final DataFormat jaxb = new JaxbDataFormat("org.camelcookbook.transformation.myschema");
final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setRootName("bookstore");
xmlJsonFormat.setElementName("book");
xmlJsonFormat.setExpandableProperties(Arrays.asList("author", "author"));
from("direct:start")
.choice()
.when(header(Exchange.FILE_NAME).endsWith(".csv"))
.unmarshal(bindy)
.bean(MyNormalizer.class, "bookModelToJaxb")
.to("mock:csv")
.when(header(Exchange.FILE_NAME).endsWith(".json"))
.unmarshal(xmlJsonFormat)
.to("mock:json")
.when(header(Exchange.FILE_NAME).endsWith(".xml"))
.unmarshal(jaxb)
.to("mock:xml")
.otherwise()
.to("mock:unknown")
.stop()
.end()
.to("mock:normalized");
}
示例12
@Override
public void configure() throws Exception {
DataFormat myJaxb = new JaxbDataFormat("org.camelcookbook.transformation.myschema");
from("direct:marshal")
.marshal(myJaxb)
.to("mock:marshalResult");
from("direct:unmarshal")
.unmarshal(myJaxb)
.to("mock:unmarshalResult");
}
示例13
@Override
public void configure() throws Exception {
final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);
from("direct:unmarshal").unmarshal(bindy);
from("direct:marshal").marshal(bindy);
}
示例14
@Path("/main/describe")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject describeMain() {
final ExtendedCamelContext camelContext = main.getCamelContext().adapt(ExtendedCamelContext.class);
JsonArrayBuilder listeners = Json.createArrayBuilder();
main.getMainListeners().forEach(listener -> listeners.add(listener.getClass().getName()));
JsonArrayBuilder routeBuilders = Json.createArrayBuilder();
main.configure().getRoutesBuilders().forEach(builder -> routeBuilders.add(builder.getClass().getName()));
JsonArrayBuilder routes = Json.createArrayBuilder();
camelContext.getRoutes().forEach(route -> routes.add(route.getId()));
JsonObjectBuilder collector = Json.createObjectBuilder();
collector.add("type", main.getRoutesCollector().getClass().getName());
if (main.getRoutesCollector() instanceof CamelMainRoutesCollector) {
CamelMainRoutesCollector crc = (CamelMainRoutesCollector) main.getRoutesCollector();
collector.add("type-registry", crc.getRegistryRoutesLoader().getClass().getName());
collector.add("type-xml", crc.getXmlRoutesLoader().getClass().getName());
}
JsonObjectBuilder dataformatsInRegistry = Json.createObjectBuilder();
camelContext.getRegistry().findByTypeWithName(DataFormat.class)
.forEach((name, value) -> dataformatsInRegistry.add(name, value.getClass().getName()));
JsonObjectBuilder languagesInRegistry = Json.createObjectBuilder();
camelContext.getRegistry().findByTypeWithName(Language.class)
.forEach((name, value) -> languagesInRegistry.add(name, value.getClass().getName()));
JsonObjectBuilder componentsInRegistry = Json.createObjectBuilder();
camelContext.getRegistry().findByTypeWithName(Component.class)
.forEach((name, value) -> componentsInRegistry.add(name, value.getClass().getName()));
JsonObjectBuilder factoryClassMap = Json.createObjectBuilder();
FactoryFinderResolver factoryFinderResolver = camelContext.getFactoryFinderResolver();
if (factoryFinderResolver instanceof FastFactoryFinderResolver) {
((FastFactoryFinderResolver) factoryFinderResolver).getClassMap().forEach((k, v) -> {
factoryClassMap.add(k, v.getName());
});
}
return Json.createObjectBuilder()
.add("xml-loader", camelContext.getXMLRoutesDefinitionLoader().getClass().getName())
.add("xml-model-dumper", camelContext.getModelToXMLDumper().getClass().getName())
.add("routes-collector", collector)
.add("listeners", listeners)
.add("routeBuilders", routeBuilders)
.add("routes", routes)
.add("lru-cache-factory", LRUCacheFactory.getInstance().getClass().getName())
.add("autoConfigurationLogSummary", main.getMainConfigurationProperties().isAutoConfigurationLogSummary())
.add("config", Json.createObjectBuilder()
.add("rest-port",
camelContext.getRestConfiguration().getPort())
.add("resilience4j-sliding-window-size",
camelContext.adapt(ModelCamelContext.class)
.getResilience4jConfiguration(null)
.getSlidingWindowSize()))
.add("registry", Json.createObjectBuilder()
.add("components", componentsInRegistry)
.add("dataformats", dataformatsInRegistry)
.add("languages", languagesInRegistry))
.add("factory-finder", Json.createObjectBuilder()
.add("class-map", factoryClassMap))
.build();
}
示例15
@Bean(name = "cbor-dataformat-factory")
@ConditionalOnMissingBean(CBORDataFormat.class)
public DataFormatFactory configureCBORDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
CBORDataFormat dataformat = new CBORDataFormat();
if (CamelContextAware.class
.isAssignableFrom(CBORDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<CBORDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.cbor.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.cbor.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例16
@Bean(name = "crypto-dataformat-factory")
@ConditionalOnMissingBean(CryptoDataFormat.class)
public DataFormatFactory configureCryptoDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
CryptoDataFormat dataformat = new CryptoDataFormat();
if (CamelContextAware.class
.isAssignableFrom(CryptoDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<CryptoDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.crypto.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.crypto.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例17
@Bean(name = "pgp-dataformat-factory")
@ConditionalOnMissingBean(PGPDataFormat.class)
public DataFormatFactory configurePGPDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
PGPDataFormat dataformat = new PGPDataFormat();
if (CamelContextAware.class
.isAssignableFrom(PGPDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<PGPDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.pgp.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.pgp.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例18
@Bean(name = "json-jackson-dataformat-factory")
@ConditionalOnMissingBean(JacksonDataFormat.class)
public DataFormatFactory configureJacksonDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
JacksonDataFormat dataformat = new JacksonDataFormat();
if (CamelContextAware.class
.isAssignableFrom(JacksonDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<JacksonDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.json-jackson.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.json-jackson.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例19
@Bean(name = "mime-multipart-dataformat-factory")
@ConditionalOnMissingBean(MimeMultipartDataFormat.class)
public DataFormatFactory configureMimeMultipartDataFormatFactory()
throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
MimeMultipartDataFormat dataformat = new MimeMultipartDataFormat();
if (CamelContextAware.class
.isAssignableFrom(MimeMultipartDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<MimeMultipartDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.mime-multipart.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.mime-multipart.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例20
@Bean(name = "rss-dataformat-factory")
@ConditionalOnMissingBean(RssDataFormat.class)
public DataFormatFactory configureRssDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
RssDataFormat dataformat = new RssDataFormat();
if (CamelContextAware.class
.isAssignableFrom(RssDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<RssDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.rss.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.rss.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例21
@Bean(name = "csv-dataformat-factory")
@ConditionalOnMissingBean(CsvDataFormat.class)
public DataFormatFactory configureCsvDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
CsvDataFormat dataformat = new CsvDataFormat();
if (CamelContextAware.class
.isAssignableFrom(CsvDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<CsvDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.csv.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.csv.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例22
@Bean(name = "asn1-dataformat-factory")
@ConditionalOnMissingBean(ASN1DataFormat.class)
public DataFormatFactory configureASN1DataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
ASN1DataFormat dataformat = new ASN1DataFormat();
if (CamelContextAware.class
.isAssignableFrom(ASN1DataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<ASN1DataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.asn1.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.asn1.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例23
@Bean(name = "syslog-dataformat-factory")
@ConditionalOnMissingBean(SyslogDataFormat.class)
public DataFormatFactory configureSyslogDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
SyslogDataFormat dataformat = new SyslogDataFormat();
if (CamelContextAware.class
.isAssignableFrom(SyslogDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<SyslogDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.syslog.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.syslog.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例24
@Bean(name = "flatpack-dataformat-factory")
@ConditionalOnMissingBean(FlatpackDataFormat.class)
public DataFormatFactory configureFlatpackDataFormatFactory()
throws Exception {
return new DataFormatFactory() {
@Override
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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<FlatpackDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.flatpack.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.flatpack.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例25
@Bean(name = "ical-dataformat-factory")
@ConditionalOnMissingBean(ICalDataFormat.class)
public DataFormatFactory configureICalDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
ICalDataFormat dataformat = new ICalDataFormat();
if (CamelContextAware.class
.isAssignableFrom(ICalDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<ICalDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.ical.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.ical.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例26
@Bean(name = "json-fastjson-dataformat-factory")
@ConditionalOnMissingBean(FastjsonDataFormat.class)
public DataFormatFactory configureFastjsonDataFormatFactory()
throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
FastjsonDataFormat dataformat = new FastjsonDataFormat();
if (CamelContextAware.class
.isAssignableFrom(FastjsonDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<FastjsonDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.json-fastjson.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.json-fastjson.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例27
@Bean(name = "jaxb-dataformat-factory")
@ConditionalOnMissingBean(JaxbDataFormat.class)
public DataFormatFactory configureJaxbDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
JaxbDataFormat dataformat = new JaxbDataFormat();
if (CamelContextAware.class
.isAssignableFrom(JaxbDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<JaxbDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.jaxb.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.jaxb.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例28
@Bean(name = "yaml-snakeyaml-dataformat-factory")
@ConditionalOnMissingBean(SnakeYAMLDataFormat.class)
public DataFormatFactory configureSnakeYAMLDataFormatFactory()
throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
SnakeYAMLDataFormat dataformat = new SnakeYAMLDataFormat();
if (CamelContextAware.class
.isAssignableFrom(SnakeYAMLDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<SnakeYAMLDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.yaml-snakeyaml.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.yaml-snakeyaml.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例29
@Bean(name = "protobuf-dataformat-factory")
@ConditionalOnMissingBean(ProtobufDataFormat.class)
public DataFormatFactory configureProtobufDataFormatFactory()
throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
ProtobufDataFormat dataformat = new ProtobufDataFormat();
if (CamelContextAware.class
.isAssignableFrom(ProtobufDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<ProtobufDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.protobuf.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.protobuf.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}
示例30
@Bean(name = "zipfile-dataformat-factory")
@ConditionalOnMissingBean(ZipFileDataFormat.class)
public DataFormatFactory configureZipFileDataFormatFactory() throws Exception {
return new DataFormatFactory() {
@Override
public DataFormat newInstance() {
ZipFileDataFormat dataformat = new ZipFileDataFormat();
if (CamelContextAware.class
.isAssignableFrom(ZipFileDataFormat.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);
CamelPropertiesHelper.setCamelProperties(camelContext,
dataformat, parameters, false);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
if (ObjectHelper.isNotEmpty(customizers)) {
for (DataFormatCustomizer<ZipFileDataFormat> customizer : customizers) {
boolean useCustomizer = (customizer instanceof HasId)
? HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.zipfile.customizer",
((HasId) customizer).getId())
: HierarchicalPropertiesEvaluator.evaluate(
applicationContext.getEnvironment(),
"camel.dataformat.customizer",
"camel.dataformat.zipfile.customizer");
if (useCustomizer) {
LOGGER.debug(
"Configure dataformat {}, with customizer {}",
dataformat, customizer);
customizer.customize(dataformat);
}
}
}
return dataformat;
}
};
}