Search in sources :

Example 1 with StringDataFormat

use of org.apache.camel.impl.StringDataFormat in project camel by apache.

the class HttpAsyncDslTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // START SNIPPET: e1
            // just a unit test but imaging using your own data format that does complex
            // and CPU heavy processing for decrypting the message
            DataFormat mySecureDataFormat = new StringDataFormat("iso-8859-1");
            // list on the JMS queue for new orders
            from("jms:queue:order").to("bean:validateOrder").to("mock:validate").threads(20).unmarshal(mySecureDataFormat).delay(500).to("bean:handleOrder").to("mock:order");
        // END SNIPPET: e1
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) StringDataFormat(org.apache.camel.impl.StringDataFormat) StringDataFormat(org.apache.camel.impl.StringDataFormat)

Example 2 with StringDataFormat

use of org.apache.camel.impl.StringDataFormat in project camel by apache.

the class StringDataFormatAutoConfiguration method configureStringDataFormatFactory.

@Bean(name = "string-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(StringDataFormat.class)
public DataFormatFactory configureStringDataFormatFactory(final CamelContext camelContext, final StringDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            StringDataFormat dataformat = new StringDataFormat();
            if (CamelContextAware.class.isAssignableFrom(StringDataFormat.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;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) StringDataFormat(org.apache.camel.impl.StringDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

StringDataFormat (org.apache.camel.impl.StringDataFormat)2 HashMap (java.util.HashMap)1 CamelContextAware (org.apache.camel.CamelContextAware)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DataFormat (org.apache.camel.spi.DataFormat)1 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1