Oracle9i Application Server Web Services Developer's Guide Release 2 (9.0.2) Part Number A95453-01 |
|
This chapter describes the procedures you use 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:
Oracle9iAS Web Services can be implemented as any of the following:
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, C/C++. These stored procedures can be exposed as Web Services using PL/SQL interfaces.
Writing PL/SQL Stored Procedure based 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 with Oracle9iAS Web Services in the directory $ORACLE_HOME/j2ee/home/demo/web_services/stored_procedure
on UNIX or in %ORACLE_HOME%\j2ee\home\demo\web_services\stored_procedure
on Windows.
Developing a Stored Procedure Web Service consists of the following steps:
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 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 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 PL/SQL package:
sqlplus scott/tiger@db_service_name @create
where db_service_name is the net service name for the Oracle database server.
Stored Procedure Web Services do not support OUT or IN/OUT parameters.
See Also:
|
After a PL/SQL stored procedure or function is available to support Stored Procedure Web Services, you need to generate the Java class to access the PL/SQL package. In this step you run Apache ant
using the buildfile supplied in the directory $ORACLE_HOME/j2ee/home/bin/spbuild.xml
, and setting Java properties to control the generation process. The Apache ant
command calls the Oracle database server JPublisher tool and generates a Java class and methods to access the stored procedure (this step prepares a Jar file for use with Stored Procedure Web Services).
JPublisher generates a Java class that provides a mapping between a PL/SQL package name, including all PL/SQL types that the stored procedures in the package use, and Java classes with methods corresponding to the PL/SQL package and procedures or functions (and mapped Java types for each PL/SQL type).
To generate Stored Procedure Web Services using a PL/SQL package as the source, use the ant
command as follows:
%ant -buildfile spbuild.xml Java_properties
Table 5-1 lists the Java properties that control the generation command. You can set the properties shown in Table 5-1 as system properties by using the -D
flag at the Java command line.
For example, the following command generates the company.jar
file using the COMPANY
package as the PL/SQL stored procedure:
cd $ORACLE_HOME/j2ee/demo/web_services/stored_procedure ant -buildfile spbuild.xml -Dschema=scott/tiger -Durl="jdbc:oracle:thin:@system1.us.oracle.com:1521:db817" -Dpackage=Company -DserviceJar=company.jar -Dprefix=sp.company -DOracleHome=/private2/oracleDBClient817/
This generates the Jar file company.jar
that contains the Java source and class files to access the PL/SQL procedure (and supports Stored Procedure Web Services).
See Also:
|
The Java classes that are placed in the Jar file output from ant
contain both support methods for accessing the PL/SQL stored procedure and JPublisher generated support methods that cannot be exposed as Oracle9iAS Web Services without generating errors. To limit the exposed methods to those that you want to expose from the PL/SQL package, you need to supply a public interface. The public interface limits the methods exposed as Stored Procedure Web Services.
To create the public interface expand the generated Jar file and examine the public methods in the generated Java source file (Company.java
). Add the method signatures for the methods that you want to expose to the public interface that you create. You do not need to implement any of the interfaces that are added to the public interface, since the public interface just identifies the method names and signatures for Stored Procedure Web Services.
For example, if you are implementing a Stored Procedure Web Service using the COMPANY
package and the generated Jar file from the supplied company sample, then create a public interface using the methods in the generated file Company.java
as a guide for identifying method signatures. For the sample, the Company.java
file is in the Jar file under sp/company/Company.java
. The public interface CompanyInterface.java
is shown in Example 5-1.
import java.sql.*; public interface CompanyInterface { public void addemp ( java.math.BigDecimal id, String firstname, String lastname, String addr, double salary) throws SQLException; public void removeemp ( java.math.BigDecimal id) throws SQLException; public void changesalary ( java.math.BigDecimal id, double newsalary[]) throws SQLException; public double getempinfo ( java.math.BigDecimal id, String firstname[], String lastname[]) throws SQLException; }
You need to compile the interface file using the Oracle9iAS Web Services standard Java compiler, as shown:
javac CompanyInterface.java
This generates CompanyInterface.class
. This class that needs to be added to the J2EE .war file to support the deployment of the new Stored Procedure Web Service.
This step is optional when writing a Stored Procedure based Web Service. If you do not perform this step, the Oracle9iAS Web Services runtime generates a WSDL file and the client-side proxies for deployed Web Services. These files allow Oracle9iAS Web Services to supply a Web Service client with the WSDL or the client-side proxies that a client-side developer can use to build an application that uses a Web Service.
When you do not want to use the Oracle9iAS Web Services generated WSDL file or client-side proxies, perform the following steps:
.wsdl
extension. The client-side proxy Jar must have an _proxy.jar
extension.The extension is placed after the service name.
For example,
simpleservice.wsdl simpleservice_proxy.jar
WEB-INF/classes
. For example, if simpleservice.wsdl
describes a service that is part of the demo package, place the file in the following directory:
WEB-INF/classes/demo/simpleservice.wsdl
WEB-INF/lib
component of the .war file that is added to the .ear file and deployed as a Web Service.
For example, the file simpeservice_proxy.jar
could be added to simpleservice.jar
and placed in WEB-INF/lib
, or added to namex.jar
in WEB-INF/lib
(
where namex is a file name).
Note:
The Jar file containing the proxy stubs, and optionally the proxy source must be a Jar component of a Jar file in |
This section describes the procedures you use to prepare a PL/SQL procedure as a Stored Procedure Web Service. The Jar file generated using ant
must be packaged with an appropriate interface class and web.xml
file into a .war file.
After the PL/SQL package, the JPublisher generated Jar file and the interface file are available, you need to create a J2EE .war file that includes the configuration file, web.xml
, and the generated Jar file. The Stored Procedure .war file is then assembled into an application .ear file to be deployed into Oracle9iAS Containers for J2EE (OC4J).
This section contains the following topics:
The Oracle9iAS Web Services assembly tool, WebServicesAssembler
, assists in assembling Oracle9iAS Web Services. The Web Services assembly tool takes a configuration file which describes the location of the Java classes, Jar files, and interface files and produces a J2EE .ear file that can be deployed under Oracle9iAS Web Services. This section describes how to assemble Oracle9iAS Web Services implemented as PL/SQL Stored Procedures manually, without using the assembly tool, WebServicesAssembler
.
To use Stored Procedure Web Services you need to add a <servlet>
entry and a corresponding <servlet-mapping>
entry in the web.xml
file for each PL/SQL package that is deployed as a Web Service. The resulting web.xml
file is assembled as part of a .war file that is included in the .ear file that defines the Web Service.
To modify web.xml
to support Web Services implemented as Stored Procedures, perform the following steps:
To add Web Services based on PL/SQL Stored Procedures you need to modify the <servlet>
tag in the web.xml
file. This tag supports using the Oracle9iAS Web Services Servlet to access the PL/SQL Stored Procedure implementation for the Web Service. Table 5-2 describes the <servlet>
tag and the values to include in the tag to add a Web Service based on a PL/SQL Stored Procedure.
Example 5-2 shows the <servlet> tag for the sample Stored Procedure Web Service extracted from the web.xml
file (to view this file, expand spexample.ear
).
Servlet Tag | Description |
---|---|
|
The
class-name: The Stored Procedure Web Services Servlet definition requires at least one
interface-name: A
datasource-JNDI-name: The Stored Procedure Web Services Servlet definition requires at least one |
|
This is always oracle.j2ee.ws.StatelessStoredProcRpcWebService for all stateless stored procedure Web Services. |
|
This tag specifies the name for the Servlet that runs the Web Service. |
<servlet> <servlet-name>stateless Stored Procedure web service example</servlet-name> <servlet-class>oracle.j2ee.ws.StatelessStoredProcRpcWebService</servlet-class> <init-param> <param-name>class-name</param-name> <param-value>sp.company.Company</param-value> </init-param> <init-param> <param-name>datasource-JNDI-name</param-name> <param-value>jdbc/OracleCoreDS</param-value> </init-param> <init-param> <param-name>interface-name</param-name> <param-value>CompanyInterface</param-value> </init-param> </servlet>
To add Web Services based on PL/SQL Stored Procedures you need to modify the <servlet-mapping>
tag in the web.xml
file. This tag specifies the URL for the Servlet that implements a Web Service.
Example 5-3 shows a sample <servlet-mapping>
entry corresponding to the servlet entry shown in Example 5-2.
<servlet-mapping> <servlet-name>stateless Stored Procedure web service example</servlet-name> <url-pattern>/statelessSP</url-pattern> </servlet-mapping>
To add Web Services based on PL/SQL Stored Procedures you need to modify the <resource-ref>
tag in the web.xml
file. This tag specifies the data source for running the PL/SQL Stored Procedure.
Example 5-4 shows a sample <resource-ref>
entry corresponding to the <servlet>
tag's datasource-JNDI-name
parameter shown in Example 5-2.
<resource-ref> <res-ref-name>jdbc/OracleCoreDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Application</res-auth> </resource-ref>
Stored Procedure Web Services use a standard .war file to define J2EE Servlet configuration and deployment information. After modifying the web.xml
file in the WEB-INF
directory to support the Stored Procedure Web Service, add the implementation classes and any required support classes or Jar files either under WEB-INF/classes
, or under WEB-INF/lib
(or in a classpath location available to OC4J). Be sure to add the compiled interface classes and the generated Jar file to support the Stored Procedure Web Service.
To add Web Services based on PL/SQL Stored Procedures you need to include an application.xml
file and package the application.xml
and .war file containing the interface class and generated Jar file into a J2EE .ear file.
The Oracle9iAS Web Services assembly tool, WebServicesAssembler
, assists in assembling Oracle9iAS Web Services.
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 .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 an .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)
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.
|
Copyright © 2002 Oracle Corporation. All Rights Reserved. |
|