Search in sources :

Example 1 with GooglePubsubComponent

use of org.apache.camel.component.google.pubsub.GooglePubsubComponent in project camel by apache.

the class GooglePubsubComponentAutoConfiguration method configureGooglePubsubComponent.

@Lazy
@Bean(name = "google-pubsub-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(GooglePubsubComponent.class)
public GooglePubsubComponent configureGooglePubsubComponent(CamelContext camelContext, GooglePubsubComponentConfiguration configuration) throws Exception {
    GooglePubsubComponent component = new GooglePubsubComponent();
    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) GooglePubsubComponent(org.apache.camel.component.google.pubsub.GooglePubsubComponent) 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)

Example 2 with GooglePubsubComponent

use of org.apache.camel.component.google.pubsub.GooglePubsubComponent in project camel by apache.

the class PubsubComponentTest method testComponentConfiguration.

@Test
public void testComponentConfiguration() throws Exception {
    Component contextComponent = context.hasComponent("google-pubsub");
    assertNotNull(contextComponent);
    assertTrue(contextComponent instanceof GooglePubsubComponent);
    GooglePubsubComponent pubsubComponent = (GooglePubsubComponent) contextComponent;
    assertEquals(SERVICE_ACCOUNT, pubsubComponent.getConnectionFactory().getServiceAccount());
    assertEquals(SERVICE_KEY, pubsubComponent.getConnectionFactory().getServiceAccountKey());
}
Also used : GooglePubsubComponent(org.apache.camel.component.google.pubsub.GooglePubsubComponent) Component(org.apache.camel.Component) GooglePubsubComponent(org.apache.camel.component.google.pubsub.GooglePubsubComponent) Test(org.junit.Test)

Aggregations

GooglePubsubComponent (org.apache.camel.component.google.pubsub.GooglePubsubComponent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Component (org.apache.camel.Component)1 Test (org.junit.Test)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 Lazy (org.springframework.context.annotation.Lazy)1