Context.xml

From Plex-XML
Jump to: navigation, search
The context.xml is telling your servlet engine
  • where the application can be found
  • which database connections it has
  • how the application should be started and run


Hints
  • The context.xml -file should be copied into the folder <tomcathome>/conf/Catalina/localhost.
  • It has to be renamed as <name_of_your_application>.xml
  • The name of the datasource has to be: 'jdbc/....'


Example for Tomcat >= 5.5

The context.xml for Tomcat 5.5 or later needs a different structure than earlier versions. Any entry inside the <ResourceParms> tags have to be set as attributes within the <Resource> tag.
 <?xml version="1.0" encoding="UTF-8" ?> 
 <Context path="/LogMan" reloadable="false" privileged="false" debug="0">
  <Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="2" /> 
  <Resource name="jdbc/AS400" type="javax.sql.DataSource" maxWait="15000" maxActive="100" password="the_password"   
    url="jdbc:as400://172.20.128.12;date format=iso;naming=system;libraries=,LM_SECURE,PRD_ACTDTA" 
    driverClassName="com.ibm.as400.access.AS400JDBCDriver" maxIdle="30" username="actobjown" validationQuery="SELECT
    COUNT(*) FROM S2SOFTF" /> 
  <Resource name="jdbc/Account" type="javax.sql.DataSource" maxWait="15000" maxActive="10" maxIdle="30"
    password="the_acc_password" username="acc_transfer_prod"
    url="jdbc:oracle:thin:acc_transfer_prod/acc_transfer_prod@//ham-easy-2:1521/gmt" 
    driverClassName="oracle.jdbc.OracleDriver" validationQuery="SELECT COUNT(*) FROM NAME_OF_YOUR_TABLE" /> 
 </Context>


What is this?
  • Plex-XML can use a validation query in the context.xml like: validationQuery="SELECT COUNT(*) FROM NAME_OF_YOUR_TABLE"
    • SQL query that can be used to validate connections before they are returned to the application.
    • If specified, this query MUST be an SQL SELECT statement that returns at least one row.
    • Plex-XML will return a database connection error page to the user if the database connection is not valid.



Example for Tomcat < 5.5

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/@projectname@" docBase="@projectname@" privileged="false" debug="0">
<Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="2"/>
 <Resource name="jdbc/Financial" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/Financial">
   <parameter>
    <name>maxWait</name>
    <value>15000</value>
   </parameter>
   <parameter>
    <name>maxActive</name>
     <value>10</value>
   </parameter>
   <parameter>
    <name>password</name>
    <value>@jdbc-password@</value>
   </parameter>
   <parameter>
    <name>url</name>
    <value>@jdbc-datasource@</value>
   </parameter>
   <parameter>
    <name>driverClassName</name>
    <value>@jdbc-driver@</value>
   </parameter>
   <parameter>
    <name>maxIdle</name>
    <value>30</value>
   </parameter>
   <parameter>
    <name>username</name>
    <value>@jdbc-user@</value>
   </parameter>
 </ResourceParams>
</Context>
Personal tools