I'm using Apache Camel 2.20.0 and deploying a REST service using REST DSL with a HTTP scheme.
I'm referencing sslContextParameters with hard coded values and all works just fine.
I can't find a way of externalizing the resource into a properties file. So far I've tried with Camel PropertiesComponent and also Spring PropertyPlaceholderConfigurer and BridgePropertyPlaceholderConfigurer and I want to be able to do the following in the config:
<camel:sslContextParameters camelContextId="camelContext1" id="routeSSLContextParameters">
<camel:keyManagers keyPassword="{{mypassword}}">
<camel:keyStore password="{{mypassword}}"
resource="{{mykeystore}}" type="JKS"/>
</camel:keyManagers>
<camel:trustManagers>
<camel:keyStore password="{{mypassword}}"
resource="{{mykeystore}}" type="JKS"/>
</camel:trustManagers>
</camel:sslContextParameters>
I've also tried putting ${} as per Spring properties, this also does not work.
Would it be possible to tell me where I'm going wrong?
Try adding the BridgePropertyPlaceholderConfigurer to your Spring Context and use the ${} placeholder:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- bridge spring property placeholder with Camel -->
<!-- you must NOT use the <context:property-placeholder at the same time,
only this bridge bean -->
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="location" value="classpath:com/stackoverflow/camel/labs/keys.properties" />
</bean>
<camel:camelContext id="exampleSsl" />
<camel:keyStoreParameters id="ksp" camelContextId="exampleSsl" resource="${keyStoreParameters.resource}" type="${keyStoreParameters.type}" provider="${keyStoreParameters.provider}" password="${keyStoreParamerers.password}" />
</beans>
The properties file:
keyStoreParameters.resource=/users/home/server/keystore.jks
keyStoreParameters.type=jks
keyStoreParameters.provider=jks
keyStoreParamerers.password=test
And the unit test:
public class SSLPlaceholderCamelTest extends CamelSpringTestSupport {
@Test
public void test() {
assertNotNull(super.context);
KeyStoreParameters ksp = (KeyStoreParameters)super.applicationContext.getBean("ksp");
assertThat(ksp.getType(), is("jks"));
assertThat(ksp.getProvider(), is("jks"));
assertThat(ksp.getResource(), is("/users/home/server/keystore.jks"));
assertThat(ksp.getPassword(), is("test"));
}
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("com/stackoverflow/camel/labs/SSLPlaceholderCamelTest.xml");
}
}
EDIT:
Yeah, I've tested with camel:sslContextParameters and the properties weren't bidden. You could access it via context and set programmatic (Setting Client Authentication On the Server Side):
KeyStoreParameters ksp = (KeyStoreParameters)context.getBean("keystore");
KeyStoreParameters tsp = (KeyStoreParameters)context.getBean("truststore");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword("keyPassword");
SSLContextServerParameters scsp = new SSLContextServerParameters();
scsp.setClientAuthentication(ClientAuthentication.REQUIRE);
SSLContextParameters scp = (SSLContextParameters)context.getBean("sslContext");
scp.setServerParameters(scsp);
scp.setKeyManagers(kmp);
SSLContext context = scp.createSSLContext();
SSLEngine engine = scp.createSSLEngine();
The context:
<camel:keyStoreParameters id="keystore"
camelContextId="exampleSsl" resource="${keyStoreParameters.resource}"
type="${keyStoreParameters.type}" provider="${keyStoreParameters.provider}"
password="${keyStoreParamerers.password}" />
<camel:keyStoreParameters id="trustsore"
camelContextId="exampleSsl" resource="${keyStoreParameters.resource}"
type="${keyStoreParameters.type}" provider="${keyStoreParameters.provider}"
password="${keyStoreParamerers.password}" />
<camel:sslContextParameters id="sslContext" camelContextId="exampleSsl" />
Just "autowire" it in your Camel Context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With