Search in sources :

Example 26 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class HystrixAutoConfiguration method defaultHystrixConfigurationDefinition.

@Bean(name = HystrixConstants.DEFAULT_HYSTRIX_CONFIGURATION_ID)
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(name = HystrixConstants.DEFAULT_HYSTRIX_CONFIGURATION_ID)
public HystrixConfigurationDefinition defaultHystrixConfigurationDefinition() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    IntrospectionSupport.getProperties(config, properties, null, false);
    HystrixConfigurationDefinition definition = new HystrixConfigurationDefinition();
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), definition, properties);
    return definition;
}
Also used : HashMap(java.util.HashMap) HystrixConfigurationDefinition(org.apache.camel.model.HystrixConfigurationDefinition) 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)

Example 27 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class GoraComponentAutoConfiguration method configureGoraComponent.

@Lazy
@Bean(name = "gora-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(GoraComponent.class)
public GoraComponent configureGoraComponent(CamelContext camelContext) throws Exception {
    GoraComponent component = new GoraComponent();
    component.setCamelContext(camelContext);
    return component;
}
Also used : GoraComponent(org.apache.camel.component.gora.GoraComponent) Lazy(org.springframework.context.annotation.Lazy) 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)

Example 28 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class GsonDataFormatAutoConfiguration method configureGsonDataFormatFactory.

@Bean(name = "json-gson-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(GsonDataFormat.class)
public DataFormatFactory configureGsonDataFormatFactory(final CamelContext camelContext, final GsonDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            GsonDataFormat dataformat = new GsonDataFormat();
            if (CamelContextAware.class.isAssignableFrom(GsonDataFormat.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) GsonDataFormat(org.apache.camel.component.gson.GsonDataFormat) 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)

Example 29 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class HBaseComponentAutoConfiguration method configureHBaseComponent.

@Lazy
@Bean(name = "hbase-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(HBaseComponent.class)
public HBaseComponent configureHBaseComponent(CamelContext camelContext, HBaseComponentConfiguration configuration) throws Exception {
    HBaseComponent component = new HBaseComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HBaseComponent(org.apache.camel.component.hbase.HBaseComponent) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) 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)

Example 30 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class HdfsComponentAutoConfiguration method configureHdfsComponent.

@Lazy
@Bean(name = "hdfs-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(HdfsComponent.class)
public HdfsComponent configureHdfsComponent(CamelContext camelContext, HdfsComponentConfiguration configuration) throws Exception {
    HdfsComponent component = new HdfsComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) HdfsComponent(org.apache.camel.component.hdfs.HdfsComponent) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) 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

ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)295 Bean (org.springframework.context.annotation.Bean)295 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)294 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)289 Lazy (org.springframework.context.annotation.Lazy)223 HashMap (java.util.HashMap)183 Map (java.util.Map)106 CamelContextAware (org.apache.camel.CamelContextAware)69 RuntimeCamelException (org.apache.camel.RuntimeCamelException)45 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)45 Scope (org.springframework.context.annotation.Scope)24 JavaScriptLanguage (org.apache.camel.builder.script.JavaScriptLanguage)1 PhpLanguage (org.apache.camel.builder.script.PhpLanguage)1 PythonLanguage (org.apache.camel.builder.script.PythonLanguage)1 RubyLanguage (org.apache.camel.builder.script.RubyLanguage)1 CoAPComponent (org.apache.camel.coap.CoAPComponent)1 AhcComponent (org.apache.camel.component.ahc.AhcComponent)1 WsComponent (org.apache.camel.component.ahc.ws.WsComponent)1 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)1 ApnsComponent (org.apache.camel.component.apns.ApnsComponent)1