Camel Property-Placeholder: Not able to configure `camel:sslContextParameters` with nested properties

StackOverflow https://stackoverflow.com/questions/22814272

Question

I am using Camel-HTTP4 2.10.4 component for calling remote REST services from my application. This communication requires SSL configuration. I successfully tested my configuration with hard coded values for resource and password.

Now I need to configure the same using camel's Property-Placeholder. I am using nested properties in spring configuration. ex:

${${env:${default.fallback.env}}.path.to.keystore} 

I followed Using PropertyPlaceholder and defined

<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <ref bean="confgPath1" />
            <ref bean="configPath2" />
        </list>
    </property>
</bean>

and sslContextParameters as follows

<camel:sslContextParameters id="sslContextParameters">
    <camel:trustManagers>
        <camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
            password="{{{{default.fallback.env}}.keystore.password}}" />
    </camel:trustManagers>
    <camel:keyManagers keyPassword="{{{{default.fallback.env}}.keystore.password}}">
        <camel:keyStore resource="{{{{default.fallback.env}}.keystore.file}}"
            password="{{{{default.fallback.env}}.keystore.password}}" />
    </camel:keyManagers>
    <camel:clientParameters>
        <camel:cipherSuitesFilter>
            <camel:include>.*</camel:include>
        </camel:cipherSuitesFilter>
    </camel:clientParameters>
</camel:sslContextParameters>

My application loads spring context successfully at start up. But after hitting the endpoint I am getting Error:

Failed to resolve endpoint <<My remote service URL>> due to: Error parsing property value: {{{{default.fallback.env}}.keystore.password}}.

I am able to use Camel's property placeholder for simple properties. For ex

{{default.fallback.env}}

But, when I try to use nested properties it is giving me above specified Error. Help me find out the proper way to solve this.

Was it helpful?

Solution

Current camel property component doesn't support the nested properties, so I just fill a JIRA for it.

As Camel property doesn't support the nested properties in the first place, you can define just define the property file like this, and set the environment from the system property and use {{someproperty}} to reference the properties.

someproperty={{{{environment}}.someproperty}}

# LOCAL SERVER
junit.someproperty=junit

# LOCAL SERVER
local.someproperty=local

# TEST
test.someproperty=test

# PROD
prod.someproperty=prod

OTHER TIPS

I just used the Spring way to create Camel SSL configuration:

  <bean id="sslContextParameters" class="org.apache.camel.util.jsse.SSLContextParameters">
    <property name="keyManagers">
      <bean class="org.apache.camel.util.jsse.KeyManagersParameters">
        <property name="keyPassword" value="${dsi.key.password}" />
        <property name="keyStore">
          <bean class="org.apache.camel.util.jsse.KeyStoreParameters">
            <property name="resource" value="${dsi.keystore.file}" />
            <property name="type" value="JKS" />
            <property name="password" value="${dsi.keystore.password}" />
            <property name="camelContext" ref="camelContext" />
          </bean>
        </property>
        <property name="camelContext" ref="camelContext" />
      </bean>
    </property>
    <property name="camelContext" ref="camelContext" />
  </bean>

I believe with Spring's property resolver you can achieve more and you do not need to use the custom bridge resolver.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top