Oracle® Application Server Web Services Developer's Guide
10g Release 2 (10.1.2) Part No. B14027-01 |
|
Previous |
Next |
This chapter describes the procedures you use to write and deploy Oracle Application Server Web Services that handle document style messages and are implemented as Java classes.
This chapter covers the following topics:
This chapter describes Document Style Web Services that are implemented with Java classes and describes the difference between writing stateful and stateless Document Style Java Web Services.
The sample code is supplied on the Oracle Technology Network Web site,
http://otn.oracle.com/tech/java/oc4j/demos/1012/index.html
After expanding the Web Services demo.zip
file, the Document Style Web Services samples are in the stateless
and stateful
directories under webservices/demo/basic/java_doc__services
on UNIX or in webservices\demo\basic\java_doc_services
on Windows.
Oracle Application Server supplies Servlets to access the Java classes which you write to implement a Web Service. The Servlets handle messages generated by Web Services clients and dispatch them to run the Java methods that implement Document Style Web Services. After a Web Service is deployed, when a client makes a service request (uses a service) the Oracle Application Server Web Services runtime, using an automatically generated Web Services Servlet invokes the methods that you implement to support the Document Style Web Service.
Writing Document Style Java Web Services involves building a Java class that includes one or more methods using supported method signatures; the java class includes methods that either handle an incoming message or return an outgoing message.
This section covers the following topics:
Table 6-1 shows the supported method signatures for Document Style Web Services. The Oracle Application Server Web Services runtime verifier rejects Document Style Web Services that do not conform to the method signatures listed in Table 6-1.
The Element
input parameter and Element
return value shown in the method signatures in Table 6-1 must conform to the Document Object Model (DOM) as specified by the W3C (org.w3c.dom.Element)
.
Table 6-1 Supported Method Signatures for Document Style Java Web Services
Method Signature | Description |
---|---|
public Element op_Name(Element e_name)
|
The method op_Name is a Document Style Web Service operation implemented as a Java method that takes an Element e_name as an input parameter and returns an Element .
|
public Element get_Name()
|
The method get_Name is a Document Style Web Service operation implemented as a Java method that takes no input parameters and returns an Element .
|
public void set_Name(Element e_name)
|
The method set_Name is a Document Style Web Service operation implemented as a Java method that takes an Element e_name as an input parameter and returns nothing.
|
A null
could be passed as an input Element
or as the Element
that the Document Style Web Service returns.
Oracle Application Server Web Services does not support Element[]
(arrays of org.w3c.dom.Element
).
Oracle Application Server Web Services supports stateful and stateless implementations for Document Style Java classes running as Web Services. For a stateful Java implementation, Oracle Application Server Web Services allows a single Java instance to serve the Web Service requests from an individual client.
For a stateless Java implementation, Oracle Application Server Web Services creates multiple instances of the Java class in a pool, any one of which may be used to service a request. After servicing the request, the object is returned to the pool for use by a subsequent request.
Note: It is the job of the Web Services developer to make the design decision to implement a stateful or stateless Web Service. When packaging Web Services, stateless and stateful Web Services are handled slightly differently. This chapter describes these differences in the section, "Preparing Document Style Web Services". |
Note: Deploying a stateful Java implementation class as a stateless Document Style Web Service could yield unpredictable results. |
Developing a Document Style Java Web Service consists of the following steps:
Create a Document Style Web Service by writing or supplying a Java class with methods that are deployed as a Document Style Web Service. The stateful
and stateless
sample directories contain sample stateless and stateful Document Style Web Services. In the src
directories, the file StatefulDocImpl.java
provides the implementation of the sample stateful Java service and StatelessDocImpl.java
provides the implementation of the stateless Document Style Web Service. These examples use interface classes; the use of interface classes is optional when implementing Document Style Web Services.
A Java class that implements a Document Style Web Service has the following limitations:
The Java class should define public methods that conform to the method signatures shown in Table 6-1. If you use an interface, then only the public methods specified in the interface need to conform to the method signature restrictions. If you do not include an interface, then all the public methods in the class must conform to the method signature restrictions shown in Table 6-1.
The Java class implementation must include a public constructor that takes no arguments.
There are very few restrictions on what actions a Document Style Java class based web service can perform. At a minimum, the service performs some action to handle an incoming message (Element
) or to generate an outgoing message (Element
).
The StatelessDoc
Web Service sample is implemented with StatelessDocImpl
, a public class and the interface StatelessDoc
. The StatelessDocImpl
class defines two public methods: displayElement()
, that displays the incoming message on the server where the web service runs, and processElement()
, that takes an incoming message and returns a transformed message to the client. The private method applyXSLtoXML()
is a helper method that transforms the incoming message, as specified in the converter.xsl
file.
Example 6-1 shows the method signatures for the StatelessDocImpl
class (see the src
directory to view the complete source code for StatelessDocImpl
).
Example 6-1 Defining Java Methods for a Stateless Document Style Web Service
import org.w3c.dom.*; import oracle.xml.parser.v2.*; import java.io.*; public class StatelessDocImpl implements StatelessDoc { public StatelessDocImpl() { } // Display the Element that was sent public void displayElement(Element e) { } //method to process the input xml doc public Element processElement(Element e) { } /** * This Method Transforms an XML Document into another using the provided * Style Sheet: converter.xsl. Note : This Method makes use of XSL * Transformation capabilities of Oracle XML Parser Version 2.0 **/ private Element applyXSLtoXML(Element e) throws Exception {}
The StatefulDoc
Web Service sample is implemented with StatefulDocImpl
, a public class and the interface StatefulDoc
. The StatefulDocImpl
class defines two public methods: startShopping()
that initializes the state of the customer information and makePurchase()
, that modifies the state of the customer information and returns the updated information to the client. The private method processElement()
is a helper method that processes the customer's XML element representing a purchase and returns the updated XML element.
Example 6-2 shows the method signatures for the StatefulDoc
class (see the src
directory to view the complete source code for StatefulDocImpl
).
Example 6-2 Defining Java Methods for a Stateful Document Style Web Service
import org.w3c.dom.*; import oracle.xml.parser.v2.*; public class StatefulDocImpl implements StatefulDoc private Element e ; public void startShopping(Element e) { } public Element makePurchase() { } private void processElement(Element e) { }
Oracle Application Server Web Services allows you to limit the methods you expose as Document Style Web Services by supplying a public interface. To limit the methods exposed in a Web Service, include a public interface that lists the method signatures for the methods that you want to expose. Example 6-3 shows an interface for the methods in the class StatelessDocImpl
. Example 6-4 shows an interface for the methods in the class StatelfulDocImpl
.
When an interface is included with a Document Style Web Service, then only the public methods specified in the interface need to conform to the method signature restrictions shown in Table 6-1. If you do not include an interface, then all the public methods in the class must conform to the method signature restrictions. Using an interface, for example StatelessDoc
shown in Example 6-3, only the methods with the specified method signatures are exposed when the Java class is prepared and deployed as a Document Style Web Service.
Use a Document Style Web Service interface for the following purposes:
To limit the exposure of methods to a subset of the public methods within a class.
To expand the set of methods that are exposed to include methods within the superclass of a class.
To limit the exposure of methods to a subset of the public methods within a class, where the subset contains only the methods that use supported method signatures. Table 6-1 lists the supported signatures for Java methods that implement Document Style Web Services.
Example 6-3 Using a Public Interface to Expose Stateless Java Services
import org.w3c.dom.*; public interface StatelessDoc { //method to display the element public void displayElement(Element e) ; //method to process the input xml doc public Element processElement(Element e) ; }
Example 6-4 Using a Public Interface to Expose Stateful Java Services
import org.w3c.dom.Element; // Interface that implements getElement and setElement public interface StatefulDoc { // Set the Element public void startShopping(Element e); // Retrieve the element that was set public Element makePurchase(); }
It is entirely up to the Web Service developer to determine the processing that occurs for messages associated with a Document Style Web Service.
The message associated with a Document Style Web Service is specified in the Element
parameter or the Element
return value associated with the Document Style Web Service. It is the Document Style Web Service developer's job to process or generate messages. The only limitation on Document Style Web Service messages is that the Element
must conform to must conform to the Document Object Model (DOM) as specified by the W3C (org.w3c.dom.Element)
.
A Document Style Web Service implementation or the client that uses a service may need to supports null
values, since a null
could be passed as an input Element
or as the Element
that is returned.
For example, the following is valid for a Document Style Web Service implementation:
Element get_op () { return null; }
This section describes how to use the Oracle Application Server Web Services tool WebServicesAssembler
to prepare a J2EE .ear file for a stateless and stateful Document Style Web Service implemented as Java classes.
To deploy a Java class that implements a Document Style Web Service, you need to assemble a J2EE .ear file that includes the deployment descriptors for the Oracle Application Server Web Services Servlet and the Java classes that supply the Java implementation. A Web Service implemented with Java classes includes a .war file that provides configuration information for the Web Services Servlet running under Oracle Application Server Containers for J2EE (OC4J). This section describes the procedures you use to create a configuration file to use with the WebServicesAssembler
.
This section contains the following topics:
Creating a Configuration File to Assemble Document Style Web Services
Running WebServicesAssembler With Document Style Web Services
The Oracle Application Server Web Services assembly tool, WebServicesAssembler
, assists in assembling Oracle Application Server Web Services. This section describes how to create a configuration file to use to assemble a Document Style Web Service. The Web Services assembly tool uses an XML configuration file that describes the Document Style Web Service. The WebServicesAssembler
uses the configuration file to produce a J2EE .ear file that can be deployed under Oracle Application Server Web Services.
Create WebServicesAssembler
configuration file by adding the following:
Table 6-2 describes the top level WebServicesAssembler
configuration file tags. Add these tags to provide top level information describing the Document Style Web Service.
Example 6-5 shows a complete stateless sample configuration file. Example 6-6 shows a complete stateful sample configuration file. The stateless
and stateful
directories in the java_doc_services
demo
directory contain the sample config.xml
files.
Table 6-2 Top Level WebServicesAssembler
Configuration Tags
Tag | Description |
---|---|
<context> context</context>
|
Specifies the context root of the Web Service.
This tag is required. |
<datasource-JNDI-name> name</datasource-JNDI-name>
|
Specifies the datasource associated with the Web Service. |
<description> description</description>
|
Provides a simple description of the Web Service.
This tag is optional. |
<destination-path> dest_path</destination-path>
|
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. |
<display-name> disp_name</display-name>
|
Specifies the Web Service display name.
This tag is optional. |
<option name=source-path"> path<option>
|
Includes a specified file in the output .ear file. Use this option to specify java resources, or the name of an existing .war, .ear, or ejb-jar file that is used as a source file for the output J2EE .ear file.
When a .war file is supplied as input, the optional contextroot specifies the root-context for the .war file. path1 specifies the context-root for the .war. path2 specifies the path to the file to include. For example: <option name="source-path" contextroot="/test">/myTestArea/ws/src/statefull.war</option> This tag is optional. |
<stateless-java-service> sub-tags</stateless-java-service>
|
Use this tag to add a Document Style Web Services that defines a stateless service. See Table 6-3 for a description of valid sub-tags. |
<stateful-java-service> sub-tags</stateful-java-service>
|
Use this tag to add a Document Style Web Services that defines a stateful service. See Table 6-3 for a description of valid sub-tags. |
<temporary-directory> temp_dir</temporary-directory>
|
Specifies a directory where the assembler can store temporary files.
This tag is optional. |
The Document Style Web Service developer determines if the service is stateful or stateless. The configuration file includes different tags depending on the type of the service. This section covers the tags for both cases, including:
Table 6-3 Java Service WebServicesAssembler Configuration Tags - Document Style
Table 6-3 describes the <stateful-java-service>
WebServicesAssembler
configuration file tags. Use these tags when creating a configuration file for a stateful Document Style Web Service.
Example 6-5 shows a complete config.xml
file, including the stateful Document Style Web Service tags.
Table 6-3 describes the <stateless-java-service>
WebServicesAssembler
configuration file tags to use when creating a stateful Document Style Web Service. The <stateless-java-service>
tag is included within a <web-service>
tag in the configuration file. Add this tag to provide information required for generating a stateless Document Style Web Service J2EE .ear file.
Example 6-6 shows a complete config.xml
file, including the stateless Document Style Web Service tags.
Note: Deploying a stateful Java implementation class as a stateless Document Style Web Service could yield unpredictable results. |
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 Document Style Web Service .ear. A client-side developer can then obtain the WSDL file from the deployed Web Service and use it to build an application.
Example 6-5 Sample Stateful Java WebServicesAssembler Configuration File for a Document Style Web Service
<web-service> <display-name>Stateful Java Document Web Service</display-name> <description>Stateful Java Document Web Service Example</description> <!-- Specifies the resulting web service archive will be stored in ./docws.ear --> <destination-path>./docws.ear</destination-path> <!-- Specifies the temporary directory that web service assembly tool can create temporary files. --> <temporary-directory>./temp</temporary-directory> <!-- Specifies the web service will be accessed in the servlet context named "/docws". --> <context>/statefuldocws</context> <!-- Specifies the web service will be stateful --> <stateful-java-service> <interface-name>StatefulDoc</interface-name> <class-name>StatefulDocImpl</class-name> <!-- Specifies the web service will be accessed in the uri named "/docService" within the servlet context. --> <uri>/docservice</uri> <!-- Specifies the location of Java class files ./classes --> <java-resource>./classes</java-resource> <!-- Specifies that it uses document style SOAP messaging --> <message-style>doc</message-style> </stateful-java-service> <!-- generate the wsdl --> <wsdl-gen> <wsdl-dir>wsdl</wsdl-dir> <!-- over-write a pregenerated wsdl , turn it 'false' to use the pregenerated wsdl--> <option name="force">true</option> <option name="httpServerURL">http://localhost:8888</option> </wsdl-gen> <!-- generate the proxy --> <proxy-gen> <proxy-dir>proxy</proxy-dir> <option name="include-source">true</option> </proxy-gen> </web-service>
Example 6-6 Sample Stateless Java WebServicesAssembler Configuration File for a Document Style Web Service
<web-service> <display-name>Stateless Java Document Web Service</display-name> <description>Stateless Java Document Web Service Example</description> <!-- Specifies the resulting web service archive will be stored in ./statelessdocws.ear --> <destination-path>./statelessdocws.ear</destination-path> <!-- Specifies the temporary directory that web service assembly tool can create temporary files. --> <temporary-directory>./temp</temporary-directory> <!-- Specifies the web service will be accessed in the servlet context named "/statelessdocws". --> <context>/statelessdocws</context> <!-- to package the stylesheet to format input xml --> <option name="source-path">converter.xsl</option> <!-- Specifies the web service will be stateless --> <stateless-java-service> <interface-name>StatelessDoc</interface-name> <class-name>StatelessDocImpl</class-name> <!-- Specifies the web service will be accessed in the uri named "/docService" within the servlet context. --> <uri>/docservice</uri> <!-- Specifies the location of Java class files ./classes --> <java-resource>./classes</java-resource> <!-- Specifies that it uses document style SOAP messaging --> <message-style>doc</message-style> </stateless-java-service> <!-- generate the wsdl --> <wsdl-gen> <wsdl-dir>wsdl</wsdl-dir> <!-- over-write a pregenerated wsdl , turn it 'false' to use the pregenerated wsdl--> <option name="force">true</option> <option name="httpServerURL">http://localhost:8888</option> </wsdl-gen> <!-- generate the proxy --> <proxy-gen> <proxy-dir>proxy</proxy-dir> <option name="include-source">true</option> </proxy-gen> </web-service>
After you create the WebServicesAssembler
configuration file, you can generate a J2EE .ear file for the Document Style Web Service. The J2EE EAR file includes Document Style Web Service servlet configuration information, including the generated file web.xml
, and the implementation classes.
Run the Oracle Application Server Web Services assembly tool, WebServicesAssembler
as follows:
java -jar WebServicesAssembler.jar -config my_service_config
Where: my_service_config is the configuration file that contains the <stateless-java-service>
or the <stateful-java-service>
tag.
After creating the .ear file containing Java classes and the Web Services Servlet deployment descriptors, you can deploy the Web Service as you would any standard J2EE application stored in an .ear file (to run under OC4J).
See Also: Oracle Application Server Containers for J2EE User's Guide in the Oracle Application Server 10g Documentation Library |