Creating Database Web Services for Invoking Server-side Java Code

Contents

Overview

This example demonstrates publishing of a database server-side Java class as a Web Service.

To run this demo you need to ensure that you have installed the required software and set up your environment. In addition, an installation of the Oracle database is required.

Step By Step

Step 1. Prepare the Database

If you use a database prior to Oracle 10i production release, you need to load ${ORACLE_HOME}/sqlj/lib/sqljutl.jar into the database. One way to determine whether you need to load sqljutl.jar is to see whether the class "oracle/jpub/reflect/Client" exists in SYS. If you see the following response, then you can skip to the next step:
SQL> conn / as sysdba
Connected.
SQL> select owner#, dbms_java.longname(name), status from obj$ where dbms_java.longname(name)='oracle/jpub/reflect/Client';

    OWNER#      DBMS_JAVA.LONGNAME(NAME)        STATUS
    ---------------------------------------------------------------------------------------
    0                      oracle/jpub/reflect/Client                                     1

To load the jar file into the server, perform the following steps.
  1. Make sure the database has java_pool_size and shared_pool_size equal or greater than 96M and 80M respectively. If not, modify the database pfile, e.g., init.ora, for the two entries, and restart the database.
  2. Go to the directory ORACLE_HOME
  3. Run the script sql/initdbws9.sql under SYS:

  4. SQL>conn / as sysdba
    SQL>@initdbws9
  5. Run the script [ORACLE_HOME]/sqlj/lib/sqljutl.sql under SYS, i.e.,

  6. SQL> conn / as sysdba
    SQL> @sqljutl.sql

Step 2. Prepare the OC4J Instance

If the database is not running locally, modify the
J2EE_HOME/data-sources.xml file so that the data-source
"jdbc/OracleDS" points to the running database, for instance,
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="OracleDS"
location="jdbc/OracleCoreDS"
xa-location="jdbc/xa/OracleXADS"
ejb-location="jdbc/OracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@<host>:<port>:<sid>"
inactivity-timeout="30"
/>

Step 3. Start OC4J

Go to the J2EE_HOME directory and start the OC4J instance standalone.
java -jar oc4j.jar

Step 4. Prepare service-config.xml

If the database is not running locally, modify the file
service-config.xml, so that the <db-conn/> element points
to the running database, in the format of
jdbc:oracle:thin:@<host>:<port>:<sid>

Step 5. Run the Demo with ANT

Run the command
ant
in the current directory. The last target "run-client" should give the following result:
[java] *** JdbcVersion in the server returns: Oracle JDBC driver 10.1, ojdbc14
This step accomplish several tasks including assembling, deploying, binding the application and then running the client. In the next section, Step 5a (Alternative to Step 5), we will detail how this step is implemented with separate commands.

Step 5a (Alternative to Step 5). Run the Demo with Separate Commands

The section provides a detaiedl view of the previous section. The user should run either Step 5 or Step 5a but not both.

Step 5a(1) Assembly

Run the WebServices assembler as following.
java -jar $ORACLE_HOME/webservices/wsa.jar -config service-config.xml


This step publishes a PL/SQL package into a Webservices application.  The following files will be generated.

Step 5a(2) Deploy

Deploy the generated WebServices application.
java -jar $J2EE_HOME/admin.jar ormi://localhost admin welcome -deploy -file dist/javacallin.ear -deploymentName javacallin

Step 5a(3) Bind

Bind the application to http-web-site.
java -jar $J2EE_HOME/admin.jar ormi://localhost admin welcome -bindWebApp javacallin javacallin-web http-web-site /javacallin

Step 5a(4) Generate the Client Proxy

Run the WebServices assembler to generate the client proxy.
java -jar $ORACLE_HOME/webservices/wsa.jar -config client-config.xml
The client proxy will be generated in the subdirectory build/classes/client.

Step 5a(5) Run the Client

The client program,
src/client/oracle/demo/db/javacallin/DBJavaClient.java
, uses the client proxy, generated in Step 5a(5), to invoke the WebServices operations.

Compile and run the client program using the ANT commands:

ant compile-client
ant run-client
The target "run-client" will give the result described in Section 5.

Step 6. Access the Services via Web Browser

The services can also be accessed via the URL
http://localhost:8888/javacallin/javacallin