Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Integrate Cocoon with PostgreSQL for XML-driven Apps : Page 2

XML and relational databases are a natural fit. Learn how to access PostgreSQL data from Cocoon, so you can develop robust XML-driven applications with a relational backend.




Application Security Testing: An Integral Part of DevOps

Integrate PostgreSQL
To integrate PostgreSQL 8.0.0 and Cocoon 2.1.6, simply install a JDBC driver in Tomcat. Tomcat is the container for Cocoon, so a globally accessible driver in Tomcat will be accessible by the Tomcat servlet container, Cocoon, and any other servlets you place within the Tomcat container. Download the latest JDBC driver. The one you want is in the row labeled "8.0" and the column labeled "JDBC 3". (It is build 309 as of the writing of this article.) The file should be called postgresql-8.0.309.jdbc3.jar or something similar (the build number might differ). Place the file in $TOMCAT_HOME/common/lib.

Copying the JAR file to $TOMCAT_HOME/common/lib provides a JDBC interface to PostgreSQL, but it does not actually tell Tomcat or Cocoon that a PostgreSQL database is installed. In order to do that, you have to configure a database connection pool. As the name implies, a database connection pool is an object (a "pool") that returns database connections. You can either set up the connection pool in Tomcat or in Cocoon—you should not do both. If you want to set it up in Tomcat, consult this Web page. You then just access the JNDI binding from within Cocoon to fetch the DataSource object (which gives you Connection objects upon request). Since this article focuses on Cocoon and not Tomcat, I describe how to set up the connection pool in Cocoon:

  1. Open $COCOON_HOME/WEB-INF/cocoon.xconf in a text editor.
  2. Search for the section that contains the following text:

    <!—..... Start configuration from 'datasources' —> <datasources> <jdbc logger="core.datasources.personnel" name="personnel"> <!— If you have an Oracle database, and are using the pool-controller below, you should add the attribute "oradb" and set it to true: <pool-controller min="5" max="10" oradb="true"/> That way, the test to see if the server has disconnected the JdbcConnection will function properly. —> <pool-controller max="10" min="5"/> <!— If you need to ensure an autocommit is set to true or false, then create the following "auto-commit" element: <auto-commit>false</auto-commit> The default is true. —> <dburl>jdbc:hsqldb:hsql://localhost:9002</dburl> <user>sa</user> <password/> </jdbc> </datasources> <!—..... End configuration from 'datasources' —>

  3. In the preceding XML excerpt, the <datasources> line is shaded green. The <jdbc> line is shaded turquoise. Right after the <datasources> tag but before the <jdbc logger="…" name="…"> tag, insert the following XML code:

    <jdbc name="mytestdb" logger="core.datasources.mytestdb"> <pool-controller min="5" max="10"/> <dburl>jdbc:postgresql://localhost/mytestdb</dburl> <user>wchao</user> <password/> </jdbc>

    In the excerpt above, you can change the database name from mytestdb to anything you would like. If you change the database name, you should change the name and logger attributes of the <jdbc> tag and the value of the <dburl> tag. You can also specify a different username and password. In the example above, I do not have a password associated with the username "wchao" because I have password-less access in my test database. Normally, you should assign a password. I omitted one only for simplicity.

  4. Save the cocoon.xconf file and exit your editor.
  5. Open $COCOON_HOME/WEB-INF/web.xml in your text editor.
  6. Look for the following section of XML code:

    <init-param> <param-name>load-class</param-name> <param-value> <!— For parent ComponentManager sample: org.apache.cocoon.samples.parentcm.Configurator —> <!— For IBM WebSphere: com.ibm.servlet.classloader.Handler —> <!— For Database Driver: —> org.hsqldb.jdbcDriver </param-value> </init-param>

  7. After the line that says "org.hsqldb.jdbc.Driver" (shaded in green), insert this line: "org.postgresql.Driver". The <init-param> section of the web.xml file should now appear as follows:

    <init-param> <param-name>load-class</param-name> <param-value> <!— For parent ComponentManager sample: org.apache.cocoon.samples.parentcm.Configurator —> <!— For IBM WebSphere: com.ibm.servlet.classloader.Handler —> <!— For Database Driver: —> org.hsqldb.jdbcDriver org.postgresql.Driver </param-value> </init-param>

  8. Save the web.xml file and exit your editor.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date