Java Code Examples for org.apache.camel.CamelContext#setPropertiesComponent()

The following examples show how to use org.apache.camel.CamelContext#setPropertiesComponent() . 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: CamelContextMetadataMBeanTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilder() throws Exception {
    CamelContext context = new DefaultCamelContext();

    Properties properties = new Properties();
    properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "metadata");

    PropertiesComponent pc  = new PropertiesComponent();
    pc.setInitialProperties(properties);
    context.setPropertiesComponent(pc);

    RuntimeSupport.configureContextCustomizers(context);

    context.start();

    final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    final Set<ObjectInstance> mBeans = mBeanServer.queryMBeans(ObjectName.getInstance("io.syndesis.camel:*"), null);
    assertThat(mBeans).hasSize(1);

    final ObjectName objectName = mBeans.iterator().next().getObjectName();
    final AttributeList attributes = mBeanServer.getAttributes(objectName, ATTRIBUTES);
    assertThat(attributes.asList()).hasSize(ATTRIBUTES.length);

    context.stop();
}
 
Example 2
Source File: AbstractEmailTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a camel context complete with a properties component that handles
 * lookups of secret values such as passwords. Fetches the values from external
 * properties file.
 *
 * @return CamelContext
 */
protected CamelContext createCamelContext() {
    CamelContext ctx = new SpringCamelContext(applicationContext);
    ctx.disableJMX();
    ctx.init();

    PropertiesComponent pc = new PropertiesComponent();
    pc.addLocation(new PropertiesLocation("classpath:mail-test-options.properties"));
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example 3
Source File: AbstractODataTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a camel context complete with a properties component that handles
 * lookups of secret values such as passwords. Fetches the values from external
 * properties file.
 */
protected CamelContext createCamelContext() {
    CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:odata-test-options.properties");
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example 4
Source File: AbstractKuduTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected CamelContext createCamelContext() {
    applicationContext = new AnnotationConfigApplicationContext(MockedKuduConfiguration.class);

    final CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent();
    pc.addLocation("classpath:test-options.properties");
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example 5
Source File: JasyptIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPasswordDecryption() throws Exception {

    // create the jasypt properties parser
    JasyptPropertiesParser jasypt = new JasyptPropertiesParser();
    // and set the master password
    jasypt.setPassword("secret");

    // create the properties component
    PropertiesComponent pc = new PropertiesComponent();
    pc.setLocation("classpath:password.properties");
    // and use the jasypt properties parser so we can decrypt values
    pc.setPropertiesParser(jasypt);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.setPropertiesComponent(pc);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").transform().simple("Hi ${body} the decrypted password is: ${properties:cool.password}");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "John", String.class);
        Assert.assertEquals("Hi John the decrypted password is: tiger", result.trim());
    } finally {
        camelctx.close();
    }
}
 
Example 6
Source File: CamelAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
static CamelContext doConfigureCamelContext(ApplicationContext applicationContext,
                                            CamelContext camelContext,
                                            CamelConfigurationProperties config) throws Exception {

    camelContext.build();

    // initialize properties component eager
    PropertiesComponent pc = applicationContext.getBeanProvider(PropertiesComponent.class).getIfAvailable();
    if (pc != null) {
        pc.setCamelContext(camelContext);
        camelContext.setPropertiesComponent(pc);
    }

    final Map<String, BeanRepository> repositories = applicationContext.getBeansOfType(BeanRepository.class);
    if (!repositories.isEmpty()) {
        List<BeanRepository> reps = new ArrayList<>();
        // include default bean repository as well
        reps.add(new ApplicationContextBeanRepository(applicationContext));
        // and then any custom
        reps.addAll(repositories.values());
        // sort by ordered
        OrderComparator.sort(reps);
        // and plugin as new registry
        camelContext.adapt(ExtendedCamelContext.class).setRegistry(new DefaultRegistry(reps));
    }

    if (ObjectHelper.isNotEmpty(config.getFileConfigurations())) {
        Environment env = applicationContext.getEnvironment();
        if (env instanceof ConfigurableEnvironment) {
            MutablePropertySources sources = ((ConfigurableEnvironment) env).getPropertySources();
            if (sources != null) {
                if (!sources.contains("camel-file-configuration")) {
                    sources.addFirst(new FilePropertySource("camel-file-configuration", applicationContext, config.getFileConfigurations()));
                }
            }
        }
    }

    camelContext.adapt(ExtendedCamelContext.class).setPackageScanClassResolver(new FatJarPackageScanClassResolver());

    if (config.getRouteFilterIncludePattern() != null || config.getRouteFilterExcludePattern() != null) {
        LOG.info("Route filtering pattern: include={}, exclude={}", config.getRouteFilterIncludePattern(), config.getRouteFilterExcludePattern());
        camelContext.getExtension(Model.class).setRouteFilterPattern(config.getRouteFilterIncludePattern(), config.getRouteFilterExcludePattern());
    }

    // configure the common/default options
    DefaultConfigurationConfigurer.configure(camelContext, config);
    // lookup and configure SPI beans
    DefaultConfigurationConfigurer.afterConfigure(camelContext);
    // and call after all properties are set
    DefaultConfigurationConfigurer.afterPropertiesSet(camelContext);

    return camelContext;
}