Saturday, 15 March 2014

java - AWS Elastic Beanstalk: access System variables -



java - AWS Elastic Beanstalk: access System variables -

i've traditional tomcat web app, connects postgres db jndi (reading context.xml). in aws ebs there possibility utilize scheme properties read specific things jdbc connection parameters, , great utilize same bundle different environments (dev, staging, production) without going alter context.xml file. since i'm using jndi datasource, i'm accessing original datasource, , changing url , password, in way:

org.apache.tomcat.jdbc.pool.datasource ds = (datasource) new initialcontext().lookup("java:/comp/env/jdbc/myapp"); string jdbcurl = system.getproperty("jdbc_connection_string"); string username = system.getproperty("param1"); string password = system.getproperty("param2"); if (!stringutils.isempty(jdbcurl)){ ds.seturl(jdbcurl); ds.setusername(username); ds.setpassword(password); }

using tomcat datasource have access setters , getters of connection parameters. tested locally (adding scheme parameters in vm arguments of tomcat, works perfectly. when upload test environment in aws ebs, these parameters empty @ origin (when application loaded), available later on: tested them in jsp page in way

the jdbc_connection_string environment property is: <%= system.getproperty("jdbc_connection_string") %> </p> <p> param1 environment property is: <%= system.getproperty("param1") %> </p> <p>] param2 environment property is: <%= system.getproperty("param2") %> </p>

and right values printed. guess can have scheme properties loaded later on, while set connection database in listener called on application startup (set in web.xml).

any thought why fails so?

thanks,

rohi

edit: i've found problem, not solution: problem when datasource loaded in lookup() method, tried found connection! not succeed cause in context.xml url localhost, , don't have db there when deploy.

anybody knows how not connect immediately, wait till first getconnection() call? context.xml

<resource auth="container" driverclassname="org.postgresql.driver" factory="org.apache.tomcat.jdbc.pool.datasourcefactory" maxactive="1000" maxidle="1000" maxwait="2000" autoreconnect="true" logabandoned="true" name="jdbc/townflix" type="org.apache.tomcat.jdbc.pool.datasource" url="jdbc:postgresql://localhost:5432/mydb?preparethreshold=3" username="user" password="pass"

/>

i don't know why fails, can tell way in personal project.

i generate , overwrite context.xml configuration using .ebextensions/*.config file, setting datasource correctly before container starts.

see: https://github.com/craftware/kornell/blob/master/kornell-api/src/main/webapp/.ebextensions/tomcat7.config

java amazon-web-services tomcat7 elastic-beanstalk

No comments:

Post a Comment