Oracle9i Application Server Web Services Developer's Guide Release 2 (9.0.3) Part Number B10004-01 |
|
This chapter describes how to write and deploy Oracle9iAS Web Services implemented as stateless PL/SQL Stored Procedures or Functions (Stored Procedure Web Services). Stored Procedure Web Services enable you to export, as services running under Oracle9iAS Web Services, PL/SQL procedures and functions that run on an Oracle database server.
This chapter covers the following topics:
This chapter shows sample code for writing Web Services implemented with stateless PL/SQL stored procedures or functions. The sample is based on a PL/SQL package representing a company that manages employees.
Oracle9iAS Web Services supplies a Servlet to access Java classes that support PL/SQL Stored Procedure Web Services. The Servlet handles requests generated by a Web Service client, runs the Java method that accesses the stored procedure that implements the Web Service, and returns results back to the Web Service client.
The Oracle database server supports procedures implemented in languages other than PL/SQL, including Java and C/C++. These stored procedures can be exposed as Web Services using PL/SQL interfaces.
Writing Stored Procedure Web Services involves creating and installing a PL/SQL package on an Oracle database server that is available as a datasource to Oracle9iAS and generating a Java class that includes one or more methods to access the Stored Procedure.
The code for the sample Stored Procedure Web Service is supplied in the directory $ORACLE_HOME/webservices/demo/basic/stored_procedure
on UNIX or in %ORACLE_HOME%\webservices\demo\basic\stored_procedure
on Windows.
Create a Stored Procedure Web Service by writing and installing a PL/SQL Stored Procedure. To write and install a PL/SQL Stored Procedure, you need to use facilities independent of Oracle9iAS Web Services.
For example, to use the sample COMPANY
package, first create and load the supplied package on the database server using the create.sql
script. This script, along with several other required .sql
scripts are in the stored_procedure
directory. These scripts create several database tables and the sample COMPANY
package.
When the Oracle database server is running on the local system, use the following command to create the sample PL/SQL package:
sqlplus scott/tiger @create
When the Oracle database server is not the local system, use the following command and include a connect identifier to create the sample PL/SQL package:
sqlplus scott/tiger@db_service_name @create
where db_service_name is the net service name for the Oracle database server.
See Also:
|
This section describes how to use the Oracle9iAS Web Services tool WebServicesAssembler
to prepare a J2EE .ear file that supports using a PL/SQL procedure or function as a Stored Procedure Web Service.
This section contains the following topics:
The Oracle9iAS Web Services assembly tool, WebServicesAssembler
, assists in assembling Oracle9iAS Web Services. This section describes how to create a configuration file to use to assemble a Stored Procedure Web Service. The Web Services assembly tool uses an XML configuration file that describes the Stored Procedure Web Service and produces a J2EE .ear file that can be deployed under Oracle9iAS Web Services.
Create WebServicesAssembler
configuration file by adding the following:
Table 5-1 describes the top level WebServicesAssembler
configuration file tags. Add these tags to provide top level information describing the PL/SQL Stored Procedure Web Service.
Example 5-1 shows a complete config.xml
file, including the top level tags.
WebServicesAssembler
Configuration Tags
Tag | Description |
---|---|
|
Specifies the context root of the Web Service. This tag is required. |
|
Specifies the datasource associated with the Web Service. |
|
Provides a simple description of the Web Service. This tag is optional. |
|
Specifies the name of the generated J2EE .ear file output. The dest_path specifies the complete path for the output file. This tag is required. |
|
Specifies the Web Service display name. This tag is optional. |
|
Includes a specified file in the output .ear file. Use this option to include Java resources. The path specifies the path to the file to include. |
|
Use this tag to add stateless stored procedure Web Services. See Table 5-2 and Table 5-4 for a description of valid sub-tags. |
|
Specifies a directory where the assembler can store temporary files. This tag is optional. |
There are two ways to develop Stored Procedure Web Services using the WebServicesAssembler
:
Using a configuration file that includes the <jar-generation>
tag specifies Oracle Database Server connection information that allows the WebServicesAssembler
to run JPublisher to generate the classes to support the Stored Procedure Web Service. The JPublisher generated classes support accessing the PL/SQL procedure or function and also includes classes for mapping Java types to PL/SQL types. The WebServicesAssembler
packages the generated classes into a Jar file that is assembled with the Stored Procedure Web Service.
Table 5-2 describes the <stateless-stored-procedure-java-service>
WebServicesAssembler
configuration file tags used when creating a configuration file that uses Jar generation to create a Stored Procedure Web Service. The <stateless-stored-procedure-java-service>
tag is included within a <web-service>
tag in the configuration file. Add this tag to provide information required for generating the Stored Procedure Web Service J2EE .ear file.
Table 5-3 describes the sub-tags for <jar-generation>
within the <stateless-stored-procedure-java-service>
tag. The <jar-generation>
tags provide information to the WebServicesAssembler
so that it can run JPublisher to generate the Java classes for the Stored Procedure Web Service. The WebServicesAssembler
then uses these classes to generate the Jar file that provides Java mappings for the stored procedure or function.
Example 5-1 shows a complete config.xml
file, including the Stored Procedure Web Service tags shown in Table 5-2 and Table 5-3.
Tag | Description |
---|---|
|
This tag specifies the JNDI name of the backend database.
The |
|
Table 5-3 describes the supported sub-tags for Example: <jar-ge |
|
This tag specifies servlet mapping pattern for the Servlet that implements the Web Service. The path specified as the URI is appended to the |
<web-service> <display-name>Web Services Example</display-name> <description>Java Web Service Example</description> <!-- Specifies the resulting web service archive will be stored in ./spexample.ear --> <destination-path>./spexample.ear</destination-path> <!-- Specifies the temporary directory that web service assembly tool can create temporary files. --> <temporary-directory>/tmp</temporary-directory> <!-- Specifies the web service will be accessed in the servlet context named "/webservices". --> <context>/webservices</context> <!-- Specifies the web service will be stateless --> <stateless-stored-procedure-java-service> <jar-generation> <schema>scott/tiger</schema> <db-url>jdbc:oracle:thin:@system1:1521:orcl</db-url> <prefix>sp.company</prefix> <db-pkg-name>Company</db-pkg-name> </jar-generation> <!-- Specifies the web service will be accessed in the uri named "statelessSP" within the servlet context. --> <uri>/statelessSP</uri> <database-JNDI-name>/jdbc/OracleDataSource</database-JNDI-name> </stateless-stored-procedure-java-service> <wsdl-gen> <wsdl-dir>wsdl</wsdl-dir> <!--force 'true' will write over existing wsdl --> <option name="force">true</option> <!-- change this to point to your soap servers http listener --> <option name="httpServerURL">http://localhost:8888</option> </wsdl-gen> <proxy-gen> <proxy-dir>proxy</proxy-dir> <!-- include-source 'true' will create an additional jar with only the proxy source--> <option name="include-source">true</option> </proxy-gen> </web-service>
Using a configuration file that specifies the stored procedure <class-name>
and <interface-name>
assembly options when a pre-generated Jar file that includes the required classes to support the Web Service is available. The <class-name>
and <interface-name>
tags specified in a configuration file support using a previously generated Jar file that contains the Java classes that provide a mapping between the PL/SQL procedure or function and the Web Service.
Table 5-4 describes the <stateless-stored-procedure-java-service>
WebServicesAssembler
configuration file tags used when creating a configuration file that uses a pre-generated Jar file to create a Stored Procedure Web Service. The <stateless-stored-procedure-java-service>
tag is included within a <web-service>
tag in the configuration file. Add this tag to provide information required for generating the Stored Procedure Web Service J2EE .ear file.
The <class>
and <interface>
tags that are added to the <stateless-stored-procedure-java-service>
only when using a pre-generated Jar file.
Tag | Description |
---|---|
|
The Stored Procedure Web Services Servlet definition requires a
You need to use the configuration file |
|
This tag specifies the JNDI name of the backend database.
The |
|
A Stored Procedure Web Services Servlet definition requires a
The |
|
This is a backwards compatibility tag. See Also: the top level <option name="source-path"> tag in Table 5-1.
The Stored Procedure pre-generated Jar file should be specified using the |
|
This tag specifies servlet mapping pattern for the Servlet that implements the Web Service. The path specified as the URI is appended to the |
See Also:
|
The WebServicesAssembler
configuration file supports the <wsdl-gen>
and <proxy-gen>
tags to allow a Web Service developer to generate Web Service description WSDL files and client-side proxy files. You can add these tags to control whether the WSDL file and the client-side proxy are generated. You can also specify that the WSDL file be assembled with the Stored Procedure Style Web Service J2EE .ear. A client-side developer can then use the WSDL file that is obtained from the deployed Web Service to build an application that uses the Web Service.
After you create the WebServicesAssembler
configuration file, you can generate a J2EE .ear file for the Stored Procedure Web Service. The J2EE .ear file includes Stored Procedure Web Service servlet configuration information, including the file web.xml
, and JPublisher generated classes (the WebServicesAssembler
collects the JPublisher generated classes into a single Jar file that it includes in the generated J2EE .ear).
Run the Oracle9iAS Web Services assembly tool, WebServicesAssembler
as follows:
java -jar WebServicesAssembler.jar -config my_pl_service_config
Where: my_pl_service_config is the configuration file that contains the <stateless-stored-procedure-java-service>
tag.
To add Web Services based on PL/SQL Stored Procedures you need to set up data sources in OC4J by configuring data-sources.xml
. Configuring the data-sources.xml
file points OC4J to a database. The database should contain PL/SQL Stored Procedure packages that implement a Stored Procedure Web Service.
A single database connection is created when OC4J initializes a Web Services Servlet instance. The resulting database connection is destroyed when OC4J removes the Web Services Servlet instance. Each Stored Procedure Web Services Servlet implements a single threaded model. As a result, any Web Services Servlet instance can only service a single client's database connection requests at any given time. OC4J pools the Web Services Servlet instances and assigns instances to Oracle9iAS Web Services clients.
Every invocation of a PL/SQL Web Service is implicitly a separate database transaction. It is not possible to have multiple service method invocations run within a single database transaction. When such semantics are required, the user must write a PL/SQL procedure that internally invokes other procedures and functions, and then expose the new procedure as another method in a Stored Procedure Web Service (but Oracle9iAS Web Services does not provide explicit support or tools to do this).
After creating the J2EE .ear file containing the Stored Procedure Web Service configuration, class, Jar, and support files you can deploy the Web Service as you would any standard J2EE application stored in a J2EE .ear file (to run under OC4J).
This section covers the following topics:
Stored Procedure Web Services support the following PL/SQL features:
JPublisher may map multiple PL/SQL types into the same Java type. For example, different PL/SQL number types may all map to Java int. This means that methods that were considered overloaded in PL/SQL are no longer overloaded in Java. If this is an issue, the user should wrap their PL/SQL code in a new PL/SQL package that does not contain these ambiguity problems.
The following simple types are supported. NULL values are supported for all of the simple types listed below, except NATURALN and POSITIVEN.
The JPublisher documentation provides full details on the mappings for these simple types.
VARCHAR2 (STRING, VARCHAR), LONG, CHAR (CHARACTER), NUMBER (DEC, DECIMAL, DOUBLE PRECISION, FLOAT, INTEGER, INT, NUMERIC, REAL, SMALLINT), PLS_INTEGER, BINARY_INTEGER (NATURAL, NATURALN, POSITIVE, POSITIVEN), BOOLEAN
Stored Procedure Web Services impose the following limitations on PL/SQL functions and procedures:
If your PL/SQL procedures use LOB types as input/output types, then the generated Java translation may not work in all cases. If you see an error, the offending procedures will have to be rewritten before the PL/SQL package can be exported as Stored Procedure Web Services.
java.math.BigDecimal
instead of the Java scalar types---the workaround for this bug is to temporarily use java.math.BigDecimal
as the argument and return types.
Using a Oracle Database Server of Release 9.2.0.1 or earlier, or with a Database Server that is not Java-enabled, then you must install the SYS.SQLJUTIL package into the SYS schema to support PL/SQL BOOLEAN arguments.
The PLSQL script that defines this package is located at the following location on Unix:
${ORACLE_HOME}/sqlj/lib/sqljutil.sql
On Windows systems, this script is located at the following location:
%ORACLE_HOME%\sqlj\lib\sqljutil.sql
|
Copyright © 2002 Oracle Corporation. All Rights Reserved. |
|