This was quite an issue for me since a while.
There are 3 ways to put in the Data source info into a tomcat.
1- put it in context.xml directly which will save time and effort.
2- put into server.xml as global naming resources and then add an entry into context.xml for global resource link
3- put as variables into catalina.properties and then link them in server.xml and context.xml which is the longest way !
below is a script that changes the variable notation to the server.xml notation.
Also will print out the resource link for context.xml:
below is how the ds info got from catalina.properties look like:
[root@Beren DS]# head ds_info
aaa.conf.datasource1.name=configDataSource
aaa.conf.datasource1.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = orcl_host)(PORT = 1527))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))
aaa.conf.datasource1.username=sherif
aaa.conf.datasource1.password=mydspassword
aaa.conf.datasource2.name=tstDataSource
aaa.conf.datasource2.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl_host)(PORT=1700))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=test)))
aaa.conf.datasource2.username=test
aaa.conf.datasource2.password=test
[root@Beren DS]#
Below is the script:
[root@Beren DS]# cat fix.sh
#set -x
OLD_IFS=${IFS}
IFS='
'
for line in `cat ds_info`
do
VAR=`echo ${line}|cut -d"=" -f1|cut -d"." -f4`
VAL="`echo ${line}|cut -d"=" -f2-`"
if [ "${VAR}" = "name" ]
then
echo '<Resource name="jdbc/'"${VAL}"'"'
echo 'auth="Container" type="javax.sql.DataSource"'
fi
if [ "${VAR}" = "url" ]
then
echo 'url="'"${VAL}"'"'
echo 'driverClassName="oracle.jdbc.driver.OracleDriver"'
echo 'maxActive="80"'
echo 'maxIdle="20"'
echo 'maxWait="10000"'
fi
if [ "${VAR}" = "username" ]
then
echo 'username="'"${VAL}"'"'
fi
if [ "${VAR}" = "password" ]
then
echo 'password="'""${VAL}'"'
echo 'removeAbandoned="true"'
echo 'removeAbandonedTimeout="60"'
echo 'logAbandoned="true"'
echo 'validationQuery="SELECT SYSDATE FROM DUAL"/>'
echo " "
fi
#read
done
echo ""
echo "Context.xml"
echo ""
for line in `cat ds_info|grep "emc.conf.datasource.*\.name"`
do
VAR=`echo ${line}|cut -d"=" -f1|cut -d"." -f4`
VAL="`echo ${line}|cut -d"=" -f2-`"
if [ "${VAR}" = "name" ]
then
echo ' <ResourceLink name="jdbc/'${VAL}'" global="jdbc/'${VAL}'" type="javax.sql.DataSource"/>'
fi
#read
done
[root@Beren DS]#
There are 3 ways to put in the Data source info into a tomcat.
1- put it in context.xml directly which will save time and effort.
2- put into server.xml as global naming resources and then add an entry into context.xml for global resource link
3- put as variables into catalina.properties and then link them in server.xml and context.xml which is the longest way !
below is a script that changes the variable notation to the server.xml notation.
Also will print out the resource link for context.xml:
below is how the ds info got from catalina.properties look like:
[root@Beren DS]# head ds_info
aaa.conf.datasource1.name=configDataSource
aaa.conf.datasource1.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = orcl_host)(PORT = 1527))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))
aaa.conf.datasource1.username=sherif
aaa.conf.datasource1.password=mydspassword
aaa.conf.datasource2.name=tstDataSource
aaa.conf.datasource2.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl_host)(PORT=1700))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=test)))
aaa.conf.datasource2.username=test
aaa.conf.datasource2.password=test
[root@Beren DS]#
Below is the script:
[root@Beren DS]# cat fix.sh
#set -x
OLD_IFS=${IFS}
IFS='
'
for line in `cat ds_info`
do
VAR=`echo ${line}|cut -d"=" -f1|cut -d"." -f4`
VAL="`echo ${line}|cut -d"=" -f2-`"
if [ "${VAR}" = "name" ]
then
echo '<Resource name="jdbc/'"${VAL}"'"'
echo 'auth="Container" type="javax.sql.DataSource"'
fi
if [ "${VAR}" = "url" ]
then
echo 'url="'"${VAL}"'"'
echo 'driverClassName="oracle.jdbc.driver.OracleDriver"'
echo 'maxActive="80"'
echo 'maxIdle="20"'
echo 'maxWait="10000"'
fi
if [ "${VAR}" = "username" ]
then
echo 'username="'"${VAL}"'"'
fi
if [ "${VAR}" = "password" ]
then
echo 'password="'""${VAL}'"'
echo 'removeAbandoned="true"'
echo 'removeAbandonedTimeout="60"'
echo 'logAbandoned="true"'
echo 'validationQuery="SELECT SYSDATE FROM DUAL"/>'
echo " "
fi
#read
done
echo ""
echo "Context.xml"
echo ""
for line in `cat ds_info|grep "emc.conf.datasource.*\.name"`
do
VAR=`echo ${line}|cut -d"=" -f1|cut -d"." -f4`
VAL="`echo ${line}|cut -d"=" -f2-`"
if [ "${VAR}" = "name" ]
then
echo ' <ResourceLink name="jdbc/'${VAL}'" global="jdbc/'${VAL}'" type="javax.sql.DataSource"/>'
fi
#read
done
[root@Beren DS]#
No comments:
Post a Comment