DB Prism

Now we’re going to move away from Java GUIs and into the realm of one of the most astonishing success stories of Java, Oracle, and open source cooperation. This is DB Prism, created by Marcelo F. Ochoa. DB Prism was originally built on Version 3.0 of an earlier product, OWSKiller, itself created by Martin Kuzela. Marcelo took this project over and changed its name (partially in response to a suggestion from Steve Muench of Oracle Corporation). The application has since gone from strength to strength, riding on the Apache JServ web server system (before iAS itself got there).

DB Prism is an open source framework designed to generate dynamic XML from an Oracle database (other databases are expected to be supported in the future). The DB Prism servlet engine works in two different modes: it can be run as a standalone servlet, or it can be plugged into the Cocoon publishing framework. When used with Cocoon, DB Prism provides a new way to make Internet applications work with technologies like XML and XSLT.

DB Prism can also be used both to emulate the old Oracle Web Application Server PL/SQL cartridge, and to work with the latest Oracle iAS products, in conjunction with the mod_plsql Apache module (which extends Apache to handle PL/SQL web content).

DB Prism is also a fully open source project, with Apache style licensing. You can use it to drive web output via either Oracle PL/SQL or Oracle8i Java stored procedures. The most exciting avenue for DB Prism is perhaps the Oracle database support it provides for the emerging XML-based Cocoon CMS (Content Management System). We’ll describe Cocoon, a very exciting open source project from the Java Apache Project, later in this section. Look for this 100% Java project to ultimately change the way that XML content is managed and displayed over the Web.

DB Prism is a triumph. It is, however, a fairly complicated triumph, because it relies necessarily upon so many different elements. In this chapter, we’ll try to provide an outline of how to hook up those elements. Fortunately, we installed the difficult parts in the last chapter: the Java JDK and JSDK modules and the Apache JServ web server. What remains here is to set up the correct environment and install DB Prism itself.

You can find out much more about DB Prism and related software from the following web sites:

http://www.plenix.com/dbprism/doc/Home.html

The main DB Prism home page.

http://xml.apache.org/cocoon/

The main Cocoon web page.

http://jakarta.apache.org/tomcat/

The home page for Tomcat, which is described in Chapter 7. Version 1.1.1 of DB Prism will make much more use of Tomcat, as the switch from Apache JServ accelerates.

Installing DB Prism

The DB Prism site itself provides excellent documentation covering all its application areas, which extend well beyond the Oracle database. We’ll concentrate on one of its main areas of most relevance to Oracle developers, the emulation of the PL/SQL cartridge in use with the older OWS/OWAS products and the more recent iAS. Once we’ve got this running, we’ll then tackle Cocoon integration.

DB Prism is itself undergoing rapid advancement. Version 2.0 is expected to take much larger steps towards taking full advantage of Cocoon; this version will also greatly enhance the use of the Tomcat Java web server technology, following from its DB Prism 1.1.1 introduction, as we mentioned previously, in order to supplement JServ. For up-to-date information on all these exciting projects, we recommend that you check out the main DB Prism web site at regular intervals.

Required HTP, HTF, and OWA packages

Before you can run DB Prism with Oracle PL/SQL, your target database schema needs to have access to the Oracle HTML Toolkit Procedures, including the HTP, HTF, and OWA packages. Those packages usually come with OWS, OWAS, and iAS installations, so you may already have them installed in your Oracle database for use with current PL/SQL web content production. If they are not already installed, you need to install them in order for DB Prism to be able to run Oracle PL/SQL web programs. For installation details, refer to the online documentation at http://technet.oracle.com.

Version 8.1.7 of the Oracle database should have these HTP packages already pre-installed under the SYS user. In our example, however, we’ll use an Oracle 8.1.5 database in order to show that it’s possible to use DB Prism with slightly older databases.

Installing DB Prism on Unix

As we said earlier, we’ve already carried out the most difficult part of getting DB Prism running on Apache JServ. This section describes the installation of DB Prism itself on top of JServ on Unix systems. For Windows, the installation is almost identical except for the differing full file path names:

  1. Assuming you have already installed the necessary, interrelated HTP packages, download the latest version of DB Prism. As well as the all-important Prism.jar file, all the .java source code files are downloaded too. Once you have upacked the download, you can find these under .. /src/com/prism, with the important Oracle classes under .. /src/com/prism/oracle. We downloaded DB Prism 1.1.0 and unpacked it to form the /home/oos/apache/prism base directory (following on from our Unix Apache JServ install in the last chapter).

  2. Shut down Apache JServ if it is currently running:

    $ apachectl stop
  3. Make sure that the following lines exist in the /home/oos/apache/conf/jserv.conf file, both to pick up jserv.properties later and to set up our servlet zones, which we’ll be using to drive our PL/SQL programs:

    ApJServProperties
    /home/oos/apache/conf/jserv.properties
    ApJServMount /servlets /root
    ApJServMount /servlet /root
  4. Similarly, ensure that the root zone itself is covered in jserv.properties, with its own properties file pointer:

    zones=root
    root.properties=/home/oos/apache/conf/root.properties
  5. In jserv.properties, you also need to ensure that the new Prism.jar servlets file is properly accessed by CLASSPATH, to get hold of the main ServletWrapper.class embedded file later (that program encapsulates our PL/SQL):

    wrapper.classpath=/home/oos/apache/prism/bin/Prism.jar
  6. Next, we move on to the root.properties file, which we’ve just pointed to. Create this by copying it from a default servlets.properties file (or the example.properties file from the last chapter), and then make sure that the following line occurs somewhere within it:

    servlet.plsql.code=com.prism.ServletWrapper

    This will wrap up the intended database PL/SQL output within the ServletWrapper.class file (which resides in Prism.jar).

  7. Also, point to another file, which we’re just about to create. The prism.properties entry will shortly hold the PL/SQL DADs (Database Access Descriptors). These are the sets of configured information used to direct DB Prism to the correct schema of a target database:

    servlet.plsql.initArgs=properties=/home/oos/apache/conf/prism.properties
  8. Copy a default prism.properties file from the DB Prism install directories. This creates your new prism.properties file in your own local Apache JServ setup:

    $ cd /homs/oos
    $ cp apache/prism/conf/prism.properties apache/conf/prism.properties
  9. Edit this new prism.properties file, first setting three highly important global variables, as we’ll describe below.

    First, any Java error reporting should go to yourself, rather than to Marcelo Ochoa (this gets you extra bonus points, especially, we suspect, from Marcelo Ochoa):

    global.webmaster=my_name@my_corp.com

    Second, set the global.behavior variable to zero:

    global.behavior=0

    Later on, if you should experience connection problems with your PL/SQL DADs, you may want to change global.behavior to either 1 or 2. This makes DB Prism parse your web addresses slightly differently and look for different DADs as a result. For example, with a web address of .. /servlet/plsql/myprocedure and a global.behavior setting of 1, DB Prism may extract a connection descriptor of “servlet”, which then returns a database connection error (because we won’t be creating a DAD for it). On the other hand, with a global.behavior value of 0, parsing the same web address can return a connection descriptor of “plsql”, which is exactly what we are after. Different systems will vary in their response to this flag, so just try the full range of the three variable values (0, 1, or 2), until one of them works out for you.

    Third, set global.alias to point DB Prism at the soon-to-be-created “plsql” DAD values:

    global.alias=plsql
  10. Having created the “plsql” alias listing, we now need to fill in the actual DAD database details for it. The following paired value sets, aimed at our usual target database, worked for us:

    plsql.dbusername=scott
    plsql.dbpassword=tiger
    plsql.connectString=jdbc:oracle:thin:@localhost:1521:ORCL
    plsql.errorLevel=2
    plsql.errorPage=http://localhost:8080/error.html
    plsql.toolkit=4x
    plsql.compat=8i
    plsql.producerarg=pass
    plsql.dbcharset=8859_1
    plsql.clientcharset=8859_1

    We note the most important of these here:

    • The plsql.connectString is our familiar JDBC URL.

    • The plsql.errorPage setting is the location where DB Prism will return any errors, either from the servlets or from the database itself. Getting this information back is an invaluable aid in configuring DB Prism correctly.

    • Our PL/SQL toolkit was OWAS Version 4. The other main OWS alternative for plsql.toolkit is “3x”.

    • The plsql.compat is important. This can be either “7x” or “8i”. Again, the prism.properties comments will help clarify this, but basically, if your target is not an Oracle8i database, use “7x”.

    • On every other plsql.* value, we either accepted the defaults or left the values commented out, as in the original file.

  11. Finally, start up Apache JServ again:

    $ apachectl start

Using DB Prism

DB Prism should now be fully up, running, and ready to respond to your PL/SQL requests. To test this, either run one of the current PL/SQL web packages from within your target database, or compile Example 8-2 within your target schema. (Note the use of the HTP package in this example.)

Example 8-2. The HelloDBPrism.sql Procedure

create or replace procedure HelloDBPrism as
   cursor emp_c is
      select a.ename,
             a.job,
             a.sal,
             b.dname 
      from emp a, dept b
      where a.deptno = b.deptno
      order by a.ename;
   emp_r emp_c%ROWTYPE;
begin
   htp.p('<html><head><title>'),
   htp.p('DB Prism, Oracle and Open Source PL/SQL Web Server'),
   htp.p('</title></head><body><center>'),
   htp.p('<h1>Hello DB Prism!</h1>'),
   htp.p('<hr>'),

   htp.p('<table border="1" frame="box"><tr>'),
   htp.p('<th>Name</th><th>Job</th>'),
   htp.p('<th>Salary</th><th>Department</th>'),
   htp.p('</tr>'),

   open emp_c;
   loop
      fetch emp_c into emp_r;
      exit when emp_c%NOTFOUND;

      htp.p('<tr>'),
      htp.p('<td>'||emp_r.ename||'</td>'),
      htp.p('<td>'||emp_r.job||'</td>'),
      htp.p('<td align="right">'||emp_r.sal||'</td>'),
      htp.p('<td>'||emp_r.dname||'</td>'),
      htp.p('</tr>'),

   end loop;
   close emp_c;

   htp.p('</table><hr></center></body>'),
end;
/

This test procedure creates a simple HTML table filled with selected employee information from the SCOTT/TIGER schema. Once HelloDBPrism.sql is compiled into your schema, you can call it with the following web address:

http://localhost:8080/servlet/plsql/hellodbprism

If you’re going through a proxy server, you may have to switch this proxy service off, or alternatively use your network-aware host name to replace localhost. This should bring up a screen similar to the one displayed in Figure 8-10.

DB Prism directing PL/SQL to the Web

Figure 8-10. DB Prism directing PL/SQL to the Web

Oracle Adapters for DB Prism

The source code that arrives with DB Prism is the real treasure, carefully crafted according to a rigorous architectural concept. Some of the more important Java classes for use with Oracle are the “adapters” linking DB Prism’s Java to the Oracle database. Standard Oracle adapters are the following:

DBConnPLSQL

Initially connects DB Prism to your schema-targeted PL/SQL and removes any database version dependency problems.

SPProcPLSQL

Gathers all the information relating to a particular stored procedure just before the required screen is generated. This is also where many of the plsql.* variables covered previously become crucially important.

DBConnJava

Similar to DBConnPLSQL. Carries out a similar function for Java stored procedures.

The following are the Oracle8i adapters:

DB8iFactory

Supports Oracle8i PL/SQL objects.

DBConn8i

Deals with Oracle stored procedures within Oracle8i.

Cocoon

Cocoon is a 100% pure Java publishing framework that relies upon various new World Wide Web Consortium (W3C) technologies (e.g., DOM, XML, and XSL) to provide web content. The Cocoon project aims to change the way web information is created, rendered, and served. Its paradigm is based on the fact that document content, style, and logic are often created by different individuals or working groups. Cocoon aims for a complete separation of these three layers, to allow them to be independently designed, created, and managed. The goal of all this is to make the whole web content delivery process much easier to manage.

Cocoon can also be made to rely upon a database provider backbone driven by DB Prism. To demonstrate this, we’ll install Cocoon over DB Prism to show you what it might be capable of.

Installing Cocoon

Download the latest Cocoon version from the Apache Software Foundation:

http://xml.apache.org/cocoon/index.html

We downloaded the following tarball into our local Apache install directory:

/home/oos/apache/Cocoon-1.8.2.tar.gz

Cocoon is quite a large download, because it contains many leading edge .jar and other related files from various XML/Java Apache projects. Once our own download had completed after a few minutes, we unpacked Cocoon within our Apache JServ development directory structure as follows:

$ cd /home/oos/apache
$ gzip -d Cocoon-1.8.2.tar.gz
$ tar xvf Cocoon-1.8.2.tar
$ cd cocoon-1.8.2

Configuring Cocoon

What follows is another rather complex configuration exercise, and another large step onward from our original Apache JServ installation. Although this process may seem complex, we think it’s worth going through so you can appreciate what Cocoon is all about. Here goes:

  1. First of all, shut down Apache JServ again:

    $ apachectl stop
  2. In /home/oos/apache/conf/jserv.conf, find the following line:

    #ApJServAction .xml /dev/org.apache.cocoon.Cocoon

    Add the following lines. These point Cocoon at the right web addresses, including its XSL content generation:

    Action cocoon /servlet/org.apache.cocoon.Cocoon
    AddHandler cocoon xml
    Alias /xsl/ /home/oos/apache/prism/xsl/
  3. Edit the jserv.properties file, adding the following lines to CLASSPATH (watch out for version number changes between different versions of Cocoon, especially on fop_0_15_0.jar). Also make sure the Xerces .jar file comes before cocoon.jar (this works around certain DOM presentation-level problems caused by having these the wrong way around):

    wrapper.classpath=/home/oos/apache/cocoon-1.8.2/lib/xerces_1_2.jar
    wrapper.classpath=/home/oos/apache/cocoon-1.8.2/bin/cocoon.jar
    wrapper.classpath=/home/oos/apache/cocoon-1.8.2/lib/fop_0_15_0.jar
    wrapper.classpath=/home/oos/apache/cocoon-1.8.2/lib/xalan_1_2_D02.jar
    wrapper.classpath=/home/oos/apache/cocoon-1.8.2/lib/turbine-pool.jar
  4. Next, edit /home/oos/apache/cocoon-1.8.2/conf/cocoon.properties and add the following lines to link up Cocoon to its database content access via DB Prism (for this book, we’ve had to split the longer lines across two, but each should be specified on one long line):

    producer.type.db = com.prism.CocoonWrapper
    producer.db.properties = /home/oos/apache/conf/prism.properties
    processor.type.http = com.prism.HeaderProcessor
    formatter.type.application/vnd.ms-excel =
        org.apache.cocoon.formatter.TextFormatter
    formatter.application/vnd.ms-excel.MIME-type =
    application/vnd.ms-excel
    processor.xsp.logicsheet.connection.java =
        resource://com/prism/xsp/connection.xsl
  5. Also change the following line:

    producer.default = file

    to:

    producer.default = db
  6. Now that we’ve altered cocoon.properties, we need to pick it up in the DB Prism/JServ system. Do this by editing /home/oos/apache/conf/root.properties. Look for the following line:

    #servlet.org.apache.cocoon.Cocoon.initArgs=properties=
    /usr/local/prism/conf/cocoon.properties

    Replace this with:

    servlet.org.apache.cocoon.Cocoon.initArgs=properties=
    /home/oos/apache/cocoon-1.8.2/conf/cocoon.properties
  7. Also in this root.properties file, find the line:

    servlet.plsql.code=com.prism.ServletWrapper

    Beneath this, to run the DB Prism XML demos later, add the following:

    servlet.demo.code=com.prism.ServletWrapper
    servlet.xml.code=org.apache.cocoon.Cocoon
    servlet.xmld.code=org.apache.cocoon.Cocoon
  8. Also look for the line we added earlier in the basic DB Prism install:

    servlet.plsql.initArgs=properties=
        /home/oos/apache/conf/prism.properties

    Beneath this, add the following lines:

    servlet.demo.initArgs=properties=/home/oos/apache/conf/prism.properties
    servlet.xml.initArgs=properties=
    /home/oos/apache/cocoon-1.8.2/conf/cocoon.properties
    servlet.xmld.initArgs=properties=
    /home/oos/apache/cocoon-1.8.2/conf/cocoon.properties
  9. We now need to move on to the prism.properties file and add some new DADs. First, update the global.alias value from:

    global.alias=plsql

    to:

    global.alias=plsql demo xml xmld org.apache.cocoon.Cocoon
  10. Once this is done, add in the new DADs. The following are the lines we used; they are essentially copies of the “plsql” DAD set up earlier, with one or two slight amendments (you’ll find most of these already preset, except for the JDBC URLs):

    #DAD demo
    demo.dbusername=scott
    demo.dbpassword=tiger
    demo.connectString=jdbc:oracle:thin:@localhost:1521:ORCL
    demo.errorLevel=2
    demo.errorPage=http://localhost:8080/error.html
    demo.compat=8i
    demo.toolkit=4x
    demo.producerarg=pass
    demo.StateLess=false
    
    #DAD xml
    xml.dbusername=scott
    xml.dbpassword=tiger
    xml.connectString=jdbc:oracle:thin:@localhost:1521:ORCL
    xml.errorLevel=2
    xml.errorPage=http://localhost:8080/error.html
    xml.compat=8i
    xml.toolkit=4x
    xml.producerarg=ignore
    
    #DAD xmld, use with demos to show dynamic login
    xmld.connectString=jdbc:oracle:thin:@localhost:1521:ORCL
    xmld.errorLevel=2
    xmld.errorPage=http://localhost:8080/error.html
    xmld.compat=8i
    xmld.producerarg=ignore
    xmld.toolkit=4x
  11. Getting away from JServ configuration for a short while, edit the /home/oos/apache/prism/plsql/demo.sql program, making sure that the final few lines contain the URL you require. In our case, this is:

    BEGIN
      -- where can I find xml stylesheets
      url_server := 'http://localhost:8080';
    END demo;

    You may also want to alter the modifiable authorize( ) function to be something simpler, like this:

    function authorize return boolean is
    begin
       return true;
    end;

    You can modify this to something more rigorous when you move into production.

  12. We now need to add some new tables under the SCOTT/TIGER schema. If you can’t find the Oracle Corporation summit2.sql demo script under your own Oracle OWAS/iAS distribution, get hold of a similar SQL script from the following site:

    http://www.telecomrg.com/darylcollins/prism/
  13. Download this SUMMIT2.SQL file to provide the database object and insert statements required by a DB Prism demonstration later. Once you’ve checked that the SQL in this file is acceptable, install summit2.sql (or SUMMIT2.SQL) onto the SCOTT/TIGER schema.

  14. Now we run an xtp.sql SQL file, also provided by DB Prism within its .. /prism/plsql directory. This installs the XML procedures required by DB Prism. This is followed, in turn, by demo.sql (recently altered), which makes immediate use of the XTP calls provided by xtp.sql:[50]

    SQL> @xtp
    Installing DB Prism Xml Toolkit Procedures (xtp)
    Package created.
    Package created.
    Package body created.
    Package body created.
    SQL> @demo
    Installing DB Prism Xml Demos
    Package created.
    Package body created.
    SQL>
  15. The penultimate step is to fire up Apache JServ (the ultimate step is to enjoy a well-deserved drink!):

    $ apachectl start

Testing Cocoon

The first thing you’ll want to do is make sure Cocoon is up and running. To do this, simply enter the following address into your browser:

http://localhost:8080/Cocoon.xml

A screen similar to Figure 8-11 should appear.

Checking that Cocoon is running properly

Figure 8-11. Checking that Cocoon is running properly

Demonstrating Cocoon and DB Prism

Now we get to the money (and as Woody Allen said, money is good, if only for financial reasons). Let’s run the demo thoughtfully provided by Marcelo Ochoa. To do this, enter the following address into your browser:

http://localhost:8080/servlets/demo/demo.startup

This should provide a range of example items. You can check this menu out in Figure 8-12. We’ve also shown some of the available drill-downs in Figure 8-13; these are generated directly from the target Oracle database.

The Prism-Cocoon collaboration demo

Figure 8-12. The Prism-Cocoon collaboration demo

Just some of the Prism-Cocoon demo examples

Figure 8-13. Just some of the Prism-Cocoon demo examples

We hope this coverage of DB Prism has whetted your appetite for more. DB Prism is heading towards the eagerly awaited 2.0 version and is definitely an application worth watching. In linked combination with something like the J2EE Enterprise Java Beans (EJB) server framework, provided by the open source JBoss project (http://www.jboss.org), it could help supply all your future Enterprise Java Oracle requirements.



[50] An alternative file, xtp_ public.sql, is supplied; it installs the XTP calls under a user such as SYS and then makes these accessible to all via public synonyms. See the DB Prism downloaded installation instructions for more details on this approach.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset