org.apache.camel.component.properties.PropertiesComponent Java Examples
The following examples show how to use
org.apache.camel.component.properties.PropertiesComponent.
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: SecuringConfigTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); // create the jasypt properties parser JasyptPropertiesParser jasypt = new JasyptPropertiesParser(); // and set the master password jasypt.setPassword("supersecret"); // we can avoid keeping the master password in plaintext in the application // by referencing a environment variable // export CAMEL_ENCRYPTION_PASSWORD=supersecret // jasypt.setPassword("sysenv:CAMEL_ENCRYPTION_PASSWORD"); // setup the properties component to use the production file PropertiesComponent prop = context.getComponent("properties", PropertiesComponent.class); prop.setLocation("classpath:rider-test.properties"); // and use the jasypt properties parser so we can decrypt values prop.setPropertiesParser(jasypt); return context; }
Example #2
Source File: EncryptedPropertiesPasswordInSystemPropertyTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Override public CamelContext createCamelContext() { // normally this would be set along the lines of -DjasyptMasterPassword=encryptionPassword // in a place appropriate to the runtime System.setProperty("jasyptMasterPassword", "encryptionPassword"); JasyptPropertiesParser propParser = new JasyptPropertiesParser(); propParser.setPassword("sys:jasyptMasterPassword"); PropertiesComponent propComponent = new PropertiesComponent(); propComponent.setLocation("classpath:placeholder.properties"); propComponent.setPropertiesParser(propParser); CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent("properties", propComponent); return camelContext; }
Example #3
Source File: SyndesisContextCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testSyndesisHeaderStrategy() throws Exception { DefaultCamelContext context = new DefaultCamelContext(); Properties properties = new Properties(); properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "syndesis"); PropertiesComponent pc = new PropertiesComponent(); pc.setInitialProperties(properties); context.setPropertiesComponent(pc); RuntimeSupport.configureContextCustomizers(context); context.start(); assertThat(context.getRegistry().findByType(HeaderFilterStrategy.class)).hasSize(1); assertThat(context.getRegistry().lookupByName("syndesisHeaderStrategy")).isInstanceOf(SyndesisHeaderStrategy.class); context.stop(); }
Example #4
Source File: CamelContextMetadataMBeanTest.java From syndesis with Apache License 2.0 | 6 votes |
@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 #5
Source File: IntegrationLoggingEnabledTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testContextConfiguration() throws Exception { DefaultCamelContext context = new DefaultCamelContext(); Properties properties = new Properties(); properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "logging"); PropertiesComponent pc = new PropertiesComponent(); pc.setInitialProperties(properties); context.setPropertiesComponent(pc); RuntimeSupport.configureContextCustomizers(context); context.start(); assertThat(context.getLogListeners()).hasAtLeastOneElementOfType(IntegrationLoggingListener.class); assertThat(context.getUuidGenerator()).isNotInstanceOf(DefaultUuidGenerator.class); assertThat(context.getRegistry().lookupByNameAndType("activityTracker", ActivityTracker.class)).isNotNull().isExactlyInstanceOf(ActivityTracker.SysOut.class); context.stop(); }
Example #6
Source File: IntegrationLoggingDisabledTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testDisabledContextConfiguration() throws Exception { DefaultCamelContext context = new DefaultCamelContext(); Properties properties = new Properties(); PropertiesComponent pc = new PropertiesComponent(); pc.setInitialProperties(properties); context.setPropertiesComponent(pc); RuntimeSupport.configureContextCustomizers(context); context.start(); assertThat(context.getLogListeners()).have(new Condition<LogListener>() { @Override public boolean matches(LogListener value) { return !(value instanceof IntegrationLoggingListener); } }); assertThat(context.getUuidGenerator()).isInstanceOf(DefaultUuidGenerator.class); context.stop(); }
Example #7
Source File: XARollbackAfterDbTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); pc.setLocation("camelinaction/sql.properties"); from("activemq:queue:partners") .transacted() .log("*** transacted ***") .bean(PartnerServiceBean.class, "toMap") .log("*** before SQL ***") .to("sql:{{sql-insert}}?dataSource=#myDataSource") .log("*** after SQL ***") .throwException(new IllegalArgumentException("Forced failure after DB")); } }; }
Example #8
Source File: XACommitTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); pc.setLocation("camelinaction/sql.properties"); from("activemq:queue:partners") .transacted() .log("*** transacted ***") .bean(PartnerServiceBean.class, "toMap") .log("*** before SQL ***") .to("sql:{{sql-insert}}?dataSource=#myDataSource") .log("*** after SQL ***") .to("mock:result"); } }; }
Example #9
Source File: XARollbackBeforeDbTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); pc.setLocation("camelinaction/sql.properties"); from("activemq:queue:partners") .transacted() .log("*** transacted ***") .bean(PartnerServiceBean.class, "toMap") .log("*** before SQL ***") .throwException(new IllegalArgumentException("Forced failure before DB")) .to("sql:{{sql-insert}}?dataSource=#myDataSource") .log("*** after SQL ***"); } }; }
Example #10
Source File: FtpToJMSWithPropertyPlaceholderTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Override protected CamelContext createCamelContext() throws Exception { // create CamelContext CamelContext camelContext = super.createCamelContext(); // connect to embedded ActiveMQ JMS broker ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); // setup the properties component to use the test file PropertiesComponent prop = camelContext.getComponent("properties", PropertiesComponent.class); prop.setLocation("classpath:rider-test.properties"); return camelContext; }
Example #11
Source File: CamelRiderJavaDSLProdTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); // setup the properties component to use the production file PropertiesComponent prop = context.getComponent("properties", PropertiesComponent.class); prop.setLocation("classpath:rider-prod.properties"); return context; }
Example #12
Source File: SimplePropertiesTest.java From camelinaction2 with Apache License 2.0 | 5 votes |
@Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); PropertiesComponent pc = new PropertiesComponent(); pc.setLocations(new String[]{"camel.properties"}); context.addComponent("properties", pc); return context; }
Example #13
Source File: IgniteCamelStreamerTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception */ @Test public void testUserSpecifiedCamelContextWithPropertyPlaceholders() throws Exception { // Create a CamelContext with a custom property placeholder. CamelContext context = new DefaultCamelContext(); PropertiesComponent pc = new PropertiesComponent("camel.test.properties"); context.addComponent("properties", pc); // Replace the context path in the test URL with the property placeholder. url = url.replaceAll("/ignite", "{{test.contextPath}}"); // Recreate the Camel streamer with the new URL. streamer = createCamelStreamer(dataStreamer); streamer.setSingleTupleExtractor(singleTupleExtractor()); streamer.setCamelContext(context); // Subscribe to cache PUT events. CountDownLatch latch = subscribeToPutEvents(50); // Action time. streamer.start(); // Before sending the messages, get the actual URL after the property placeholder was resolved, // stripping the jetty: prefix from it. url = streamer.getCamelContext().getEndpoints().iterator().next().getEndpointUri().replaceAll("jetty:", ""); // Send messages. sendMessages(0, 50, false); // Assertions. assertTrue(latch.await(10, TimeUnit.SECONDS)); assertCacheEntriesLoaded(50); }
Example #14
Source File: CamelRiderJavaDSLTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Override protected CamelContext createCamelContext() throws Exception { CamelContext context = super.createCamelContext(); // setup the properties component to use the test file PropertiesComponent prop = context.getComponent("properties", PropertiesComponent.class); prop.setLocation("classpath:rider-test.properties"); return context; }
Example #15
Source File: HelloConfiguration.java From camelinaction2 with Apache License 2.0 | 5 votes |
/** * Create the Camel properties component using CDI @Produces with the name: properties */ @Produces @Named("properties") PropertiesComponent propertiesComponent() { PropertiesComponent component = new PropertiesComponent(); // load properties file form the classpath component.setLocation("classpath:hello.properties"); return component; }
Example #16
Source File: EncryptedPropertiesTest.java From camel-cookbook-examples with Apache License 2.0 | 5 votes |
@Override public CamelContext createCamelContext() { JasyptPropertiesParser propParser = new JasyptPropertiesParser(); propParser.setPassword("encryptionPassword"); PropertiesComponent propComponent = new PropertiesComponent(); propComponent.setLocation("classpath:placeholder.properties"); propComponent.setPropertiesParser(propParser); CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent("properties", propComponent); return camelContext; }
Example #17
Source File: JasyptIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@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 #18
Source File: HelloConfiguration.java From camelinaction2 with Apache License 2.0 | 5 votes |
/** * Create the Camel properties component using CDI @Produces with the name: properties */ @Produces @Named("properties") PropertiesComponent propertiesComponent() { PropertiesComponent component = new PropertiesComponent(); // load properties file form the classpath component.setLocation("classpath:hello.properties"); return component; }
Example #19
Source File: CartConfiguration.java From camelinaction2 with Apache License 2.0 | 5 votes |
/** * Create the Camel properties component using CDI @Produces with the name: properties */ @Produces @Named("properties") PropertiesComponent propertiesComponent() { PropertiesComponent component = new PropertiesComponent(); // load properties file form the classpath component.setLocation("classpath:cart.properties"); return component; }
Example #20
Source File: CartConfiguration.java From camelinaction2 with Apache License 2.0 | 5 votes |
/** * Create the Camel properties component using CDI @Produces with the name: properties */ @Produces @Named("properties") PropertiesComponent propertiesComponent() { PropertiesComponent component = new PropertiesComponent(); // load properties file form the classpath component.setLocation("classpath:cart.properties"); return component; }
Example #21
Source File: AbstractKuduTest.java From syndesis with Apache License 2.0 | 5 votes |
@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 #22
Source File: AbstractODataTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * 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 #23
Source File: AbstractEmailTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: PropertiesTest.java From camel-k-runtime with Apache License 2.0 | 5 votes |
@Test public void testLoadProperties() throws Exception { System.setProperty(Constants.PROPERTY_CAMEL_K_CONF, "src/test/resources/conf.properties"); System.setProperty(Constants.PROPERTY_CAMEL_K_CONF_D, "src/test/resources/conf.d"); try { ApplicationRuntime runtime = new ApplicationRuntime(); runtime.setInitialProperties(PropertiesSupport.loadApplicationProperties()); runtime.setPropertiesLocations(PropertiesSupport.resolveUserPropertiesLocations()); runtime.addListener(new ContextConfigurer()); runtime.addListener(Runtime.Phase.Started, r -> { final CamelContext context = r.getCamelContext(); final PropertiesComponent pc = (PropertiesComponent)context.getPropertiesComponent(); assertThat(pc.getInitialProperties()).containsExactlyEntriesOf(PropertiesSupport.loadApplicationProperties()); assertThat(pc.getInitialProperties().getProperty("root.key")).isEqualTo("root.value"); assertThat(pc.getInitialProperties().getProperty("a.key")).isEqualTo("a.root"); assertThat(pc.getLocations()).hasSameElementsAs( PropertiesSupport.resolveUserPropertiesLocations().stream() .map(location -> "file:" + location) .distinct() .sorted() .collect(Collectors.toList()) ); assertThat(pc.resolveProperty("root.key")).get().isEqualTo("root.value"); assertThat(pc.resolveProperty("001.key")).get().isEqualTo("001.value"); assertThat(pc.resolveProperty("002.key")).get().isEqualTo("002.value"); assertThat(pc.resolveProperty("a.key")).get().isEqualTo("a.002"); runtime.stop(); }); runtime.run(); } finally { System.getProperties().remove(Constants.PROPERTY_CAMEL_K_CONF); System.getProperties().remove(Constants.PROPERTY_CAMEL_K_CONF_D); } }
Example #25
Source File: CamelAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 4 votes |
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; }
Example #26
Source File: AbstractODataTest.java From syndesis with Apache License 2.0 | 4 votes |
@Bean(destroyMethod = "") public PropertiesComponent properties(PropertiesParser parser) { PropertiesComponent pc = new PropertiesComponent(); pc.setPropertiesParser(parser); return pc; }
Example #27
Source File: AbstractEmailTest.java From syndesis with Apache License 2.0 | 4 votes |
@Bean public PropertiesComponent properties(PropertiesParser parser) { PropertiesComponent pc = new PropertiesComponent(); pc.setPropertiesParser(parser); return pc; }
Example #28
Source File: CamelAutoConfiguration.java From camel-spring-boot with Apache License 2.0 | 4 votes |
@Bean(destroyMethod = "") PropertiesComponent properties(PropertiesParser parser) { PropertiesComponent pc = new PropertiesComponent(); pc.setPropertiesParser(parser); return pc; }