org.apache.camel.spi.DataFormat Java Examples

The following examples show how to use org.apache.camel.spi.DataFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroDataFormatTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #2
Source File: BindyIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #3
Source File: BindyIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #4
Source File: BeanIOIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #5
Source File: BeanIOIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #6
Source File: NormalizerRoute.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #7
Source File: CamelMainSupport.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: ReverseDataFormatTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@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");
        }
    };
}
 
Example #9
Source File: JaxbRoute.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #10
Source File: CsvRoute.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: DataFormatTestCommand.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #12
Source File: CamelRegistryTest.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #13
Source File: JsonDataformatsRoute.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source File: Any23DataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "any23-dataformat-factory")
@ConditionalOnMissingBean(Any23DataFormat.class)
public DataFormatFactory configureAny23DataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            Any23DataFormat dataformat = new Any23DataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(Any23DataFormat.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<Any23DataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.any23.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.any23.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #15
Source File: JsonApiDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "jsonApi-dataformat-factory")
@ConditionalOnMissingBean(JsonApiDataFormat.class)
public DataFormatFactory configureJsonApiDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            JsonApiDataFormat dataformat = new JsonApiDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(JsonApiDataFormat.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<JsonApiDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.jsonapi.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.jsonapi.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #16
Source File: TarFileDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "tarfile-dataformat-factory")
@ConditionalOnMissingBean(TarFileDataFormat.class)
public DataFormatFactory configureTarFileDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            TarFileDataFormat dataformat = new TarFileDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(TarFileDataFormat.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<TarFileDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.tarfile.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.tarfile.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #17
Source File: JsonDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "json-xstream-dataformat-factory")
@ConditionalOnMissingBean(JsonDataFormat.class)
public DataFormatFactory configureJsonDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            JsonDataFormat dataformat = new JsonDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(JsonDataFormat.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<JsonDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.json-xstream.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.json-xstream.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #18
Source File: XStreamDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "xstream-dataformat-factory")
@ConditionalOnMissingBean(XStreamDataFormat.class)
public DataFormatFactory configureXStreamDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            XStreamDataFormat dataformat = new XStreamDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(XStreamDataFormat.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<XStreamDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.xstream.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.xstream.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #19
Source File: ZipDeflaterDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "zipdeflater-dataformat-factory")
@ConditionalOnMissingBean(ZipDeflaterDataFormat.class)
public DataFormatFactory configureZipDeflaterDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            ZipDeflaterDataFormat dataformat = new ZipDeflaterDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(ZipDeflaterDataFormat.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<ZipDeflaterDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.zipdeflater.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.zipdeflater.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #20
Source File: GzipDeflaterDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "gzipdeflater-dataformat-factory")
@ConditionalOnMissingBean(GzipDeflaterDataFormat.class)
public DataFormatFactory configureGzipDeflaterDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            GzipDeflaterDataFormat dataformat = new GzipDeflaterDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(GzipDeflaterDataFormat.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<GzipDeflaterDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.gzipdeflater.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.gzipdeflater.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #21
Source File: BarcodeDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "barcode-dataformat-factory")
@ConditionalOnMissingBean(BarcodeDataFormat.class)
public DataFormatFactory configureBarcodeDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            BarcodeDataFormat dataformat = new BarcodeDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(BarcodeDataFormat.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<BarcodeDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.barcode.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.barcode.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #22
Source File: TidyMarkupDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "tidyMarkup-dataformat-factory")
@ConditionalOnMissingBean(TidyMarkupDataFormat.class)
public DataFormatFactory configureTidyMarkupDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            TidyMarkupDataFormat dataformat = new TidyMarkupDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(TidyMarkupDataFormat.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<TidyMarkupDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.tidymarkup.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.tidymarkup.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #23
Source File: XMLSecurityDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "secureXML-dataformat-factory")
@ConditionalOnMissingBean(XMLSecurityDataFormat.class)
public DataFormatFactory configureXMLSecurityDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            XMLSecurityDataFormat dataformat = new XMLSecurityDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(XMLSecurityDataFormat.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<XMLSecurityDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.securexml.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.securexml.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #24
Source File: JacksonXMLDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "jacksonxml-dataformat-factory")
@ConditionalOnMissingBean(JacksonXMLDataFormat.class)
public DataFormatFactory configureJacksonXMLDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            JacksonXMLDataFormat dataformat = new JacksonXMLDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(JacksonXMLDataFormat.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<JacksonXMLDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.jacksonxml.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.jacksonxml.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #25
Source File: BindyFixedLengthDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "bindy-fixed-dataformat-factory")
@ConditionalOnMissingBean(BindyFixedLengthDataFormat.class)
public DataFormatFactory configureBindyFixedLengthDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            BindyFixedLengthDataFormat dataformat = new BindyFixedLengthDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(BindyFixedLengthDataFormat.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<BindyFixedLengthDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-fixed.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-fixed.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #26
Source File: BindyKeyValuePairDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "bindy-kvp-dataformat-factory")
@ConditionalOnMissingBean(BindyKeyValuePairDataFormat.class)
public DataFormatFactory configureBindyKeyValuePairDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            BindyKeyValuePairDataFormat dataformat = new BindyKeyValuePairDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(BindyKeyValuePairDataFormat.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<BindyKeyValuePairDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-kvp.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-kvp.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #27
Source File: BindyCsvDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "bindy-csv-dataformat-factory")
@ConditionalOnMissingBean(BindyCsvDataFormat.class)
public DataFormatFactory configureBindyCsvDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            BindyCsvDataFormat dataformat = new BindyCsvDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(BindyCsvDataFormat.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<BindyCsvDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-csv.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.bindy-csv.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #28
Source File: LZFDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "lzf-dataformat-factory")
@ConditionalOnMissingBean(LZFDataFormat.class)
public DataFormatFactory configureLZFDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            LZFDataFormat dataformat = new LZFDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(LZFDataFormat.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<LZFDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.lzf.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.lzf.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #29
Source File: BeanIODataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "beanio-dataformat-factory")
@ConditionalOnMissingBean(BeanIODataFormat.class)
public DataFormatFactory configureBeanIODataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            BeanIODataFormat dataformat = new BeanIODataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(BeanIODataFormat.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<BeanIODataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.beanio.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.beanio.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}
 
Example #30
Source File: ThriftDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "thrift-dataformat-factory")
@ConditionalOnMissingBean(ThriftDataFormat.class)
public DataFormatFactory configureThriftDataFormatFactory() throws Exception {
    return new DataFormatFactory() {
        @Override
        public DataFormat newInstance() {
            ThriftDataFormat dataformat = new ThriftDataFormat();
            if (CamelContextAware.class
                    .isAssignableFrom(ThriftDataFormat.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<ThriftDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.thrift.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.thrift.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}