Java Code Examples for org.apache.camel.support.IntrospectionSupport#setProperties()

The following examples show how to use org.apache.camel.support.IntrospectionSupport#setProperties() . 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: DnsCloudAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory != null) {
        Map<String, Object> parameters = new HashMap<>();

        for (Map.Entry<String, DnsServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
            // clean up params
            parameters.clear();

            // The instance factory
            DnsServiceDiscoveryFactory factory = new DnsServiceDiscoveryFactory();

            try {
                IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);

                beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
            } catch (Exception e) {
                throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
            }
        }
    }
}
 
Example 2
Source File: RibbonCloudAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory != null) {
        Map<String, Object> parameters = new HashMap<>();

        for (Map.Entry<String, RibbonServiceCallServiceLoadBalancerConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
            // clean up params
            parameters.clear();

            // The instance factory
            RibbonServiceLoadBalancerFactory factory = new RibbonServiceLoadBalancerFactory();

            try {
                IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);

                beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
            } catch (Exception e) {
                throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
            }
        }
    }
}
 
Example 3
Source File: KubernetesServiceDiscoveryAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory != null) {
        Map<String, Object> parameters = new HashMap<>();

        for (Map.Entry<String, KubernetesServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
            // clean up params
            parameters.clear();

            // The instance factory
            KubernetesServiceDiscoveryFactory factory = new KubernetesServiceDiscoveryFactory();

            try {
                IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);

                beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
            } catch (Exception e) {
                throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
            }
        }
    }
}
 
Example 4
Source File: ConsulServiceDiscoveryAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory != null) {
        Map<String, Object> parameters = new HashMap<>();

        for (Map.Entry<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
            // clean up params
            parameters.clear();

            // The instance factory
            ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();

            try {
                IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);

                beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
            } catch (Exception e) {
                throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
            }
        }
    }
}
 
Example 5
Source File: Olingo4IntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private CamelContext createCamelContext() throws Exception {

        final CamelContext context = new DefaultCamelContext();

        Map<String, Object> options = new HashMap<String, Object>();
        options.put("serviceUri", getRealServiceUrl(TEST_SERVICE_BASE_URL));
        options.put("contentType", "application/json;charset=utf-8");

        final Olingo4Configuration configuration = new Olingo4Configuration();
        IntrospectionSupport.setProperties(configuration, options);

        // add OlingoComponent to Camel context
        final Olingo4Component component = new Olingo4Component(context);
        component.setConfiguration(configuration);
        context.addComponent("olingo4", component);

        return context;
    }
 
Example 6
Source File: SalesforceIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSalesforceCreateJob() throws Exception {

    Assume.assumeTrue(hasSalesforceEnvVars());

    SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
    IntrospectionSupport.setProperties(loginConfig, salesforceOptions);

    SalesforceComponent component = new SalesforceComponent();
    component.setPackages("org.wildfly.camel.test.salesforce.dto");
    component.setLoginConfig(loginConfig);

    JobInfo jobInfo = new JobInfo();
    jobInfo.setOperation(OperationEnum.QUERY);
    jobInfo.setContentType(ContentType.CSV);
    jobInfo.setObject(Opportunity.class.getSimpleName());

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addComponent("salesforce",  component);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("salesforce:createJob");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        JobInfo result = template.requestBody("direct:start", jobInfo, JobInfo.class);

        Assert.assertNotNull("Expected JobInfo result to not be null", result);
        Assert.assertNotNull("Expected JobInfo result ID to not be null", result.getId());
    } finally {
        camelctx.close();
    }
}
 
Example 7
Source File: RibbonCloudAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "ribbon-load-balancer")
@ConditionalOnClass(CamelContext.class)
public ServiceLoadBalancer configureLoadBalancerFactory() throws Exception {
    RibbonServiceLoadBalancerFactory factory = new RibbonServiceLoadBalancerFactory();

    IntrospectionSupport.setProperties(
        camelContext,
        camelContext.getTypeConverter(),
        factory,
        IntrospectionSupport.getNonNullProperties(configuration));

    return factory.newInstance(camelContext);
}
 
Example 8
Source File: ConsulClusterServiceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = "consul-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService consulClusterService() throws Exception {
    ConsulClusterService service = new ConsulClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 9
Source File: ConsulServiceRegistryAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = "consul-service-registry")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public ConsulServiceRegistry consulServiceRegistry(ConsulServiceRegistryConfiguration configuration) throws Exception {
    ConsulServiceRegistry service = new ConsulServiceRegistry();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 10
Source File: BraintreeIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testBraintreeClientTokenGateway() throws Exception {

    Map<String, Object> braintreeOptions = createBraintreeOptions();

    Assume.assumeTrue("[#1679] Enable Braintree testing in Jenkins",
            braintreeOptions.size() == BraintreeOption.values().length);

    final CountDownLatch latch = new CountDownLatch(1);
    final CamelContext camelctx = new DefaultCamelContext();
    final BraintreeConfiguration configuration = new BraintreeConfiguration();
    configuration.setHttpLogLevel(Level.WARNING);
    IntrospectionSupport.setProperties(configuration, braintreeOptions);

    // add BraintreeComponent to Camel context
    final BraintreeComponent component = new BraintreeComponent(camelctx);
    component.setConfiguration(configuration);
    camelctx.addComponent("braintree", component);

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("timer://braintree?repeatCount=1")
                .to("braintree:clientToken/generate")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        latch.countDown();
                    }})
                .to("mock:result");
        }
    });

    camelctx.start();
    try {
        Assert.assertTrue("Countdown reached zero", latch.await(5, TimeUnit.MINUTES));
    } finally {
        camelctx.close();
    }
}
 
Example 11
Source File: DnsCloudAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "dns-service-discovery")
@ConditionalOnClass(CamelContext.class)
public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
    DnsServiceDiscoveryFactory factory = new DnsServiceDiscoveryFactory();

    IntrospectionSupport.setProperties(
        camelContext,
        camelContext.getTypeConverter(),
        factory,
        IntrospectionSupport.getNonNullProperties(configuration));

    return factory.newInstance(camelContext);
}
 
Example 12
Source File: ResilienceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory == null) {
        return;
    }

    Map<String, Object> properties = new HashMap<>();

    for (Map.Entry<String, Resilience4jConfigurationDefinitionCommon> entry : config.getConfigurations().entrySet()) {

        // clear the properties map for reuse
        properties.clear();

        // extract properties
        IntrospectionSupport.getProperties(entry.getValue(), properties, null, false);

        try {
            Resilience4jConfigurationDefinition definition = new Resilience4jConfigurationDefinition();
            IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), definition, properties);

            // Registry the definition
            beanFactory.registerSingleton(entry.getKey(), definition);

        } catch (Exception e) {
            throw new BeanCreationException(entry.getKey(), e);
        }
    }
}
 
Example 13
Source File: ResilienceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = ResilienceConstants.DEFAULT_RESILIENCE_CONFIGURATION_ID)
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(name = ResilienceConstants.DEFAULT_RESILIENCE_CONFIGURATION_ID)
public Resilience4jConfigurationDefinition defaultResilienceConfigurationDefinition() throws Exception {
    Map<String, Object> properties = new HashMap<>();

    IntrospectionSupport.getProperties(config, properties, null, false);
    Resilience4jConfigurationDefinition definition = new Resilience4jConfigurationDefinition();
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), definition, properties);

    return definition;
}
 
Example 14
Source File: KubernetesClusterServiceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = "kubernetes-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService kubernetesClusterService() throws Exception {
    KubernetesClusterService service = new KubernetesClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 15
Source File: KubernetesServiceDiscoveryAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Lazy
@Bean(name = "kubernetes-service-discovery")
public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
    KubernetesServiceDiscoveryFactory factory = new KubernetesServiceDiscoveryFactory();

    IntrospectionSupport.setProperties(
        camelContext,
        camelContext.getTypeConverter(),
        factory,
        IntrospectionSupport.getNonNullProperties(configuration));

    return factory.newInstance(camelContext);
}
 
Example 16
Source File: JGroupsLockClusterServiceAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = "jgroups-lock-cluster-service")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public CamelClusterService zookeeperClusterService() throws Exception {
    JGroupsLockClusterService service = new JGroupsLockClusterService();

    IntrospectionSupport.setProperties(
        service,
        IntrospectionSupport.getNonNullProperties(configuration)
    );

    return service;
}
 
Example 17
Source File: HystrixAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void postConstruct() {
    if (beanFactory == null) {
        return;
    }

    Map<String, Object> properties = new HashMap<>();

    for (Map.Entry<String, HystrixConfigurationDefinitionCommon> entry : config.getConfigurations().entrySet()) {

        // clear the properties map for reuse
        properties.clear();

        // extract properties
        IntrospectionSupport.getProperties(entry.getValue(), properties, null, false);

        try {
            HystrixConfigurationDefinition definition = new HystrixConfigurationDefinition();
            IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), definition, properties);

            // Registry the definition
            beanFactory.registerSingleton(entry.getKey(), definition);

        } catch (Exception e) {
            throw new BeanCreationException(entry.getKey(), e);
        }
    }
}
 
Example 18
Source File: HystrixAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 19
Source File: SalesforceIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
public void testSalesforceQueryProducer() throws Exception {

    Assume.assumeTrue(hasSalesforceEnvVars());

    SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
    IntrospectionSupport.setProperties(loginConfig, salesforceOptions);

    SalesforceComponent component = new SalesforceComponent();
    component.setPackages("org.wildfly.camel.test.salesforce.dto");
    component.setLoginConfig(loginConfig);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addComponent("salesforce",  component);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:opportunity")
            .to("salesforce:query?sObjectQuery=SELECT Id,Name from Opportunity&sObjectClass=" + QueryRecordsOpportunity.class.getName());

            from("direct:account")
            .to("salesforce:query?sObjectQuery=SELECT Id,AccountNumber from Account&sObjectClass=" + QueryRecordsAccount.class.getName());
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();

        QueryRecordsOpportunity oppRecords = template.requestBody("direct:opportunity", null, QueryRecordsOpportunity.class);
        Assert.assertNotNull("Expected query records result to not be null", oppRecords);
        Assert.assertTrue("Expected some records", oppRecords.getRecords().size() > 0);

        Opportunity oppItem = oppRecords.getRecords().get(0);
        Assert.assertNotNull("Expected Oportunity Id", oppItem.getId());
        Assert.assertNotNull("Expected Oportunity Name", oppItem.getName());

        QueryRecordsAccount accRecords = template.requestBody("direct:account", null, QueryRecordsAccount.class);
        Assert.assertNotNull("Expected query records result to not be null", accRecords);
        Assert.assertTrue("Expected some records", accRecords.getRecords().size() > 0);

        Account accItem = accRecords.getRecords().get(0);
        Assert.assertNotNull("Expected Account Id", accItem.getId());
        Assert.assertNotNull("Expected Account Number", accItem.getAccountNumber());
    } finally {
        camelctx.close();
    }
}
 
Example 20
Source File: BoxIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
public void testBoxComponent() throws Exception {
    Map<String, Object> boxOptions = createBoxOptions();

    // Do nothing if the required credentials are not present
    Assume.assumeTrue(boxOptions.size() == BoxOption.values().length);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").
            to("box://folders/createFolder");
        }
    });

    BoxConfiguration configuration = new BoxConfiguration();
    configuration.setAuthenticationType(BoxConfiguration.STANDARD_AUTHENTICATION);
    IntrospectionSupport.setProperties(configuration, boxOptions);

    BoxComponent component = new BoxComponent(camelctx);
    component.setConfiguration(configuration);
    camelctx.addComponent("box", component);

    BoxFolder folder = null;

    camelctx.start();
    try {
        Map<String, Object> headers = new HashMap<>();
        headers.put("CamelBox.parentFolderId", "0");
        headers.put("CamelBox.folderName", "TestFolder");

        ProducerTemplate template = camelctx.createProducerTemplate();
        folder = template.requestBodyAndHeaders("direct:start", null, headers, BoxFolder.class);

        Assert.assertNotNull("Folder was null", folder);
        Assert.assertEquals("Expected folder name to be TestFolder", "TestFolder", folder.getInfo().getName());
    } finally {
        // Clean up
        if (folder != null) {
            folder.delete(true);
        }

        camelctx.close();
    }
}