You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Launcelot <dr...@standard.com> on 2016/02/19 23:38:23 UTC

Usage of properties in datasource definition - Please help

I have a property file defined as follows
<camelContext trace="true"
		id="context-c2d439e2-f530-4c6d-8480-86f290cbf297"
xmlns="http://camel.apache.org/schema/spring">
		
		<propertyPlaceholder id="properties" location="db.properties"
propertyPrefix="${" propertySuffix="}"/>
		<route>
db.properties has a property in it which contains
db.pass=valuesnipped


I have a datasource definition as under
<bean id="myDataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"
/>
		<property name="url" value="jdbc:oracle:thin:@seq1:1521:sfgd" />
		<property name="username" value="valuesnipped" />
		<property name="password" value="${db.pass}" />
		<property name="maxWait" value="1000" />
		<property name="validationQueryTimeout" value="3" />
		<property name="initialSize" value="8" />
		<property name="maxIdle" value="32" />
		<property name="removeAbandoned" value="true" />
		<property name="removeAbandonedTimeout" value="60" />
		<property name="logValidationErrors" value="true" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnBorrow" value="true" />
		<property name="testOnConnect" value="true" />
		<property name="testOnReturn" value="false" />
		<property name="validationQuery" value="/* Oracle Health Check */ SELECT 1
FROM DUAL" />
		
	</bean>                

I get exceptions connecting to the database indicating invalid
user/password. I have tried using {{db.pass}} which also does not work,
probably because it is literally assigning the value as {{db.pass}}. If i
just use the actual password above it works fine. The aim is ultimately to
use jasypt but that is a problem for another day.

Any help indicating how I can accomplish setting the password from a
property file is appreciated.

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Usage-of-properties-in-datasource-definition-Please-help-tp5777954.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Usage of properties in datasource definition - Please help

Posted by Launcelot <dr...@standard.com>.
Thanks to both of you Grzegorz  as well as Claus!

This problem was solved and I got jasypt to work as well.

To help people who might come along and read this post because they have the
same problem am providing some sample code .. attached to this post are my
pom file, camel config and db.properties (Useless without the password which
is being set in env but will give an idea)

pom.xml <http://camel.465427.n5.nabble.com/file/n5778022/pom.xml>  

db.properties
<http://camel.465427.n5.nabble.com/file/n5778022/db.properties>  

camel-context.xml
<http://camel.465427.n5.nabble.com/file/n5778022/camel-context.xml>  

Please note this 'app' is just for poc and does nothing useful , it reads
the same record over and over.




--
View this message in context: http://camel.465427.n5.nabble.com/Usage-of-properties-in-datasource-definition-Please-help-tp5777954p5778022.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Usage of properties in datasource definition - Please help

Posted by Grzegorz Grzybek <gr...@gmail.com>.
HI Launcelot

I see you're using Spring XML. Camel's <propertyPlaceholder> element
is used to resolve placeholders in Camel elements (like URIs).
However, in order to have your ${db.pass} replaced, you have to enable
Spring's own property placeholder. See here:
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#xsd-config-body-schemas-context-pphc

Just add <context:property-placeholder> in your XML.

regards
Grzegorz

2016-02-19 23:38 GMT+01:00 Launcelot <dr...@standard.com>:
> I have a property file defined as follows
> <camelContext trace="true"
>                 id="context-c2d439e2-f530-4c6d-8480-86f290cbf297"
> xmlns="http://camel.apache.org/schema/spring">
>
>                 <propertyPlaceholder id="properties" location="db.properties"
> propertyPrefix="${" propertySuffix="}"/>
>                 <route>
> db.properties has a property in it which contains
> db.pass=valuesnipped
>
>
> I have a datasource definition as under
> <bean id="myDataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
>                 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"
> />
>                 <property name="url" value="jdbc:oracle:thin:@seq1:1521:sfgd" />
>                 <property name="username" value="valuesnipped" />
>                 <property name="password" value="${db.pass}" />
>                 <property name="maxWait" value="1000" />
>                 <property name="validationQueryTimeout" value="3" />
>                 <property name="initialSize" value="8" />
>                 <property name="maxIdle" value="32" />
>                 <property name="removeAbandoned" value="true" />
>                 <property name="removeAbandonedTimeout" value="60" />
>                 <property name="logValidationErrors" value="true" />
>                 <property name="testWhileIdle" value="true" />
>                 <property name="testOnBorrow" value="true" />
>                 <property name="testOnConnect" value="true" />
>                 <property name="testOnReturn" value="false" />
>                 <property name="validationQuery" value="/* Oracle Health Check */ SELECT 1
> FROM DUAL" />
>
>         </bean>
>
> I get exceptions connecting to the database indicating invalid
> user/password. I have tried using {{db.pass}} which also does not work,
> probably because it is literally assigning the value as {{db.pass}}. If i
> just use the actual password above it works fine. The aim is ultimately to
> use jasypt but that is a problem for another day.
>
> Any help indicating how I can accomplish setting the password from a
> property file is appreciated.
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Usage-of-properties-in-datasource-definition-Please-help-tp5777954.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Usage of properties in datasource definition - Please help

Posted by Claus Ibsen <cl...@gmail.com>.
The <bean> is spring handling those, so setup spring property
placeholders to let it does its work there.
Camel's property placeholder is from whats inside <camelContext>.
You can bridge the two of them.

See more details in the camel website

On Fri, Feb 19, 2016 at 11:38 PM, Launcelot <dr...@standard.com> wrote:
> I have a property file defined as follows
> <camelContext trace="true"
>                 id="context-c2d439e2-f530-4c6d-8480-86f290cbf297"
> xmlns="http://camel.apache.org/schema/spring">
>
>                 <propertyPlaceholder id="properties" location="db.properties"
> propertyPrefix="${" propertySuffix="}"/>
>                 <route>
> db.properties has a property in it which contains
> db.pass=valuesnipped
>
>
> I have a datasource definition as under
> <bean id="myDataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
>                 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"
> />
>                 <property name="url" value="jdbc:oracle:thin:@seq1:1521:sfgd" />
>                 <property name="username" value="valuesnipped" />
>                 <property name="password" value="${db.pass}" />
>                 <property name="maxWait" value="1000" />
>                 <property name="validationQueryTimeout" value="3" />
>                 <property name="initialSize" value="8" />
>                 <property name="maxIdle" value="32" />
>                 <property name="removeAbandoned" value="true" />
>                 <property name="removeAbandonedTimeout" value="60" />
>                 <property name="logValidationErrors" value="true" />
>                 <property name="testWhileIdle" value="true" />
>                 <property name="testOnBorrow" value="true" />
>                 <property name="testOnConnect" value="true" />
>                 <property name="testOnReturn" value="false" />
>                 <property name="validationQuery" value="/* Oracle Health Check */ SELECT 1
> FROM DUAL" />
>
>         </bean>
>
> I get exceptions connecting to the database indicating invalid
> user/password. I have tried using {{db.pass}} which also does not work,
> probably because it is literally assigning the value as {{db.pass}}. If i
> just use the actual password above it works fine. The aim is ultimately to
> use jasypt but that is a problem for another day.
>
> Any help indicating how I can accomplish setting the password from a
> property file is appreciated.
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Usage-of-properties-in-datasource-definition-Please-help-tp5777954.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2