Oracle9i Application Server Oracle9iAS SOAP Developer's Guide Release 1 (v1.0.2.2) Part Number A90297-01 |
|
This chapter provides an introduction to the procedures you use to write a SOAP Java service, to deploy the service, and to write a SOAP Java client that uses the service. Code examples in this chapter, use the simple clock sample supplied with the Oracle SOAP installation. Very little setup is required before you can use Oracle SOAP with Java clients. Using Oracle SOAP, you can easily make requests for SOAP services and generate replies from SOAP services.
A Java service runs on a SOAP server as part of the Oracle SOAP Java Provider. The Java service handles requests generated by a SOAP client.
This chapter covers the following topics:
Writing a SOAP Java service involves building a Java class that includes one or more methods that generate data used as responses to incoming calls. Normally a service is a method that can run independently of SOAP. There are very few restrictions on what actions a SOAP service can perform. At a minimum, most SOAP services generate some data or perform an action.
This section shows how to build a service that returns the current date and time. The clock service takes a SOAP request for a service and generates a response with a return value representing the date (a String
).
The complete simple clock service is supplied with Oracle SOAP in the directory $SOAP_HOME/samples/simpleclock
on UNIX or in %SOAP_HOME%\samples\simpleclock
on Windows NT.
Developing a SOAP Java service consists of the following steps:
Create a SOAP Java service by writing a class with methods that are deployed as a SOAP service. The Oracle SOAP Java Provider runs these methods in response to a request issued by the SOAP Request Handler Servlet. When looking at the simple clock service supplied with Oracle SOAP, note that the single jar file, samples.jar
, contains a package, samples
, that includes several samples. For the SOAP server installation the jar file is in the directory $SOAP_HOME/webapps/soap/WEB-INF/lib
on UNIX or in %SOAP_HOME%\webapps\soap\WEB-INF\lib
on Windows NT. For the SOAP client installation, the jar file is in the directory $SOAP_HOME/lib
on UNIX or in %SOAP_HOME%\lib
on Windows NT.
The class MySimpleClockService
provides the simple clock service methods. If you want to place the Java service in a package, use the Java package
specification to name the package. The first line of MySimpleClockService.java
specifies the package name as follows:
package samples.simpleclock;
The simple clock service is implemented with SimpleClockService
, a public class. The service defines a single public method, getDate()
, that supplies a date as a String
. In general, a SOAP Java service defines one or more methods. As Example 2-1 shows, the SimpleClockService
uses one public method, getDate()
.
public class SimpleClockService extends Object { public SimpleClockService() { } public static String getDate() { . . } }
The getDate()
method returns a String
value. Parameters and results sent between a client and a service go through the following steps:
Oracle SOAP supports a prepackaged implementation for handling these four steps for serialization and encoding, and deserialization and decoding, of scalar and user-defined types. Additionally, you can implement your own serialization and encoding mechanism.
The prepackaged mechanism makes the four serialization and encoding steps easy both for SOAP client-side applications, and for implementation of SOAP Java services. Using the prepackaged mechanism, Oracle SOAP, as specified in the SOAP client, supports the following encoding mechanisms:
BeanSerializer
.
Element
. When an Element
passes as a parameter to a SOAP service, the service processes the Element
. For return values sent from a SOAP service, the client parses and processes the element.
Type | Type |
---|---|
|
|
|
|
|
|
|
|
|
|
Vector |
Enumeration |
The getDate()
code segment shown in Example 2-2 gets a date and returns a String
value as a response. The Oracle SOAP Java Provider receives a request from the SOAP Request Handler Servlet and calls the getDate()
method. After running, getDate()
returns its result to the Oracle SOAP Java Provider. The Oracle SOAP provider processes the return value and produces a SOAP envelope. Finally, the SOAP Request Handler Servlet serializes the reply and sends a response to the SOAP client. Example 2-2 shows that the Java service writer only needs to return a String
for the simple date service.
public static String getDate() { return (new java.util.Date()).toString(); }
When an error occurs while running a Java service, the service should throw an exception, and the SOAP Request Handler Servlet then returns a SOAP fault. The exception is sent to the log file when the logger is enabled and the severity
value is set to debug
.
To deploy a SOAP service, you need to create a service deployment descriptor file and deploy the service using the Service Manager utility.
This section covers the following topics:
A service deployment descriptor file is an XML file that defines configuration information for the Java service. A service deployment descriptor file defines the following information:
Example 2-3 shows the SimpleClock
service descriptor file SimpleClockDescriptor.xml
. This descriptor file is included in the samples/simpleclock
directory. The service descriptor file must conform to the service descriptor schema (the schema, service.xsd
, is located in the directory $SOAP_HOME/schemas
on UNIX or in %SOAP_HOME%\schemas
on Windows NT).
The service descriptor file identifies methods associated with the service in the isd:provider
element that uses the methods
attribute. The isd:java class
element identifies the Java class that implements the SOAP service, and provides an indication of whether the class is static.
<isd:service xmlns:isd="http://xmlns.oracle.com/soap/2001/04/deploy/service" id="urn:jurassic-clock" type="rpc" > <isd:provider id="java-provider" methods="getDate" scope="Application" > <isd:java class="samples.simpleclock.SimpleClockService"/> </isd:provider> <!-- includes stack trace in fault --> <isd:faultListener class="org.apache.soap.server.DOMFaultListener"/> </isd:service>
To deploy a SOAP Java service, the class that implements the service must be available when Oracle SOAP starts. To add the class to the CLASSPATH
, modify the CLASSPATH
for the SOAP Request Handler Servlet. Using the standard installation, modify the file jservSoap.properties
in the directory $ORACLE_HOME/Apache/Jserv/etc
on UNIX or in %ORACLE_HOME%\Apache\Jserv\etc
on Windows NT.
The ServiceManager
is an administrative utility that deploys and undeploys SOAP services.
To deploy the simple clock service, first set the SOAP environment, then use the deploy
command to deploy the SimpleClockService
service. On UNIX, the command is:
cd $SOAP_HOME/bin source clientenv.csh cd $SOAP_HOME/samples/simpleclock ServiceManager.sh deploy SimpleClockDescriptor.xml
For Windows NT, the command is:
cd %SOAP_HOME%\bin clientenv.bat cd %SOAP_HOME%\samples\simpleclock ServiceManager.bat deploy SimpleClockDescriptor.xml
When you are ready to undeploy a service, use the undeploy
command with the registered service name as an argument. On UNIX, the command is:
ServiceManager.sh undeploy urn:jurassic-clock
For Windows NT, the command is:
ServiceManager.bat undeploy urn:jurassic-clock
The ServiceManager
is an administrative utility that lists and queries SOAP services. To list the available services, first set the SOAP environment, then use the list
command. One UNIX, the command is:
cd $SOAP_HOME/bin source clientenv.csh ServiceManager.sh list
On Windows NT, the command is:
cd %SOAP_HOME%\bin clientenv.bat ServiceManager.bat list
To query a service and obtain the descriptor parameters set in the service deployment descriptor file, use the query
command. On UNIX, the command is:
ServiceManager.sh query urn:jurassic-clock
On Windows NT, the command is:
ServiceManager.bat query urn:jurassic-clock
After creating and deploying one or more SOAP services, client-side applications can request service invocations. The example described in this section is a SOAP client-side application that requests a date, using the simple clock service, and the method GetDate()
.
Developing a Java client-side SOAP application consists of the following steps:
Use a SOAP Java service by making a SOAP request. The file MySimpleClockClient.java
shows a SOAP client that makes a SOAP request. On UNIX, the directory $SOAP_HOME/samples/simpleclock
contains this source file; on Windows NT, %SOAP_HOME%\samples\simpleclock
.
The first line of MySimpleClockClient.java
specifies the package name for the service that is added to samples.jar.
package samples.simpleclock;
The SOAP client-side application uses the following imports:
import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Response; import org.apache.soap.rpc.Parameter; import org.apache.soap.Constants; import org.apache.soap.SOAPException; import java.net.URL; import java.net.MalformedURLException;
The org.apache.soap.rpc
imports for the SOAP client-side are discussed in the following sections.
The MySimpleClockClient
class includes the SOAP request for the SOAP getDate
Java service. Example 2-4 shows the start of the client's main()
routine that processes the command line argument.
public static void main(String[] args) { if (args.length == 0) { System.out.println( "Usage is java samples.simpleclock.MySimpleClockClient SOAP_server_url"); System.exit(1); } else { try { URL url = new URL (args[0]); MySimpleClockClient soapClockClient = new MySimpleClockClient(url); } catch (MalformedURLException mue) { mue.printStackTrace(); } } }
The package org.apache.soap.rpc
contains the SOAP Call
object. A SOAP client-side request uses a Call
object to build a request for a SOAP service. After the SOAP request is created, it is invoked to enable the client API to pass the request on to a SOAP server. Example 2-5 shows the code that builds a request for a SOAP service invocation.
Call call = new Call(); call.setTargetObjectURI("urn:jurassic-clock"); call.setMethodName("getDate"); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
This code performs the following functions:
Call
object.
Call
object's target URI which identifies the service.
Call
object's method name.
Call
object's encoding style.
Call
object's parameters. For this service, the Call
object does not set any parameters to send with the service request.
In addition, the Call
object's setTimeout()
method sets the timeout, an integer representing seconds, for a SOAP call. The default Call
timeout, implicitly set in this example specifies no timeout. Setting a timeout value of 0 also specifies no timeout.
Example 2-5 shows the client-side method that sets the default encoding style for the service request setEncodingStyleURI
. The simple clock service uses standard SOAP v1.1 encoding.
In a client-side application, the SOAP API uses the encoding style set for the call to serialize and encode any parameters that are sent to the SOAP service, unless a specific encoding style is set for the parameter. For primitive types, the SOAP Java client-side API handles serialization and encoding internally using the standard SOAP encoding. For complex Java types, not found in Table 2-1, the application programmer must supply serialization and encoding methods to the client-side API.
Example 2-6 shows the Call
object invoke()
method that invokes the service at the specified SOAP URL. A Response
object handles any response. The URL that you provide on the command line should be the URL for the SOAP Request Handler Servlet. This value depends on where SOAP is deployed. For example, the URL could be composed as follows:
http://machineName:port/soap/servlet/soaprouter
Response resp = call.invoke(url, "");
During invocation, if the Call
timeout is not reached, and the invoke()
method returns, the Response
object holds the SOAP return value or any fault generated. The return value is stored in a Parameter
component of the Response
object. Use the getValue()
method to convert the response to a Java object. Example 2-7 shows how GetDate
handles the response to either process a fault or show the date returned from the simple clock service's getDate
method.
try { System.out.println("Calling urn:jurassic-clock"); Response resp = call.invoke(url, ""); if (!resp.generatedFault()) { Parameter result = resp.getReturnValue(); System.out.println(result.getValue()); } else { System.out.println("FAULT Returned"); System.out.println(resp.getFault().getFaultString()); } } catch (SOAPException soapE) { soapE.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }
After writing a SOAP client and setting the SOAP environment, run the client as you would any Java program. On UNIX, use the following commands:
cd $SOAP_HOME/bin source clientenv.csh java ${JAXP} samples.simpleclock.MySimpleClockClient ${SOAP_URL}
On Windows NT, use the following commands:
cd %SOAP_HOME%\bin clientenv.bat java %JAXP% samples.simpleclock.MySimpleClockClient %SOAP_URL%
Oracle SOAP uses the security capabilities of the underlying transport that sends SOAP messages. Oracle SOAP supports the HTTP and HTTPS protocols for sending SOAP messages. HTTP and HTTPS support the following security features:
Table 2-2 lists the client-side security properties that Oracle SOAP supports.
In a SOAP client-side application, you can set the security properties shown in Table 2-2 as system properties by using the -D
flag at the Java command line. You can also set security properties in the Java program by adding these properties to the system properties (use System.setProperties()
to add properties).
Example 2-8 shows how Oracle SOAP allows you to override the values specified for system properties using Oracle SOAP transport specific APIs. The setProperties()
method in the class OracleSOAPHTTPConnection
contains set properties specifically for the HTTP connection (this class is in the package oracle.soap.transport.http
).
org.apache.soap.rpc.Call call = new org.apache.soap.rpc.Call(); oracle.soap.transport.http.OracleSOAPHTTPConnection conn = (oracle.soap.transport.http.OracleSOAPHTTPConnection) call.getSOAPTransport(); java.util.Properties prop = new java.util.Properties(); // Use client code to set name-value pairs of properties in prop . . . conn.setProperties(prop);
This section lists several techniques for troubleshooting Oracle SOAP, including:
SOAP provides the TcpTunnelGui
command to display messages sent between a SOAP client and a SOAP server. TcpTunnelGui
listens on a TCP port, which is different than the SOAP server, and then forwards requests to the SOAP server.
Invoke TcpTunnelGui
as follows:
java org.apache.soap.util.net.TcpTunnelGui TUNNEL-PORT SOAP-HOST SOAP-PORT
Table 2-3 lists the command line options for TcpTunnelGui
.
Argument | Description |
---|---|
TUNNEL-PORT |
The port that |
SOAP-HOST |
The host of the SOAP server |
SOAP-PORT |
The port of the SOAP server |
For example, suppose the SOAP server is running as follows,
http://system1:8080/soap/servlet/soaprouter
You would then invoke TcpTunnelGui
on port 8082 with this command:
java org.apache.soap.util.net.TcpTunnelGui 8082 system1 8080
To test a client and view the SOAP traffic, you would use the following SOAP URL in the client program:
http://system1:8082/soap/servlet/soaprouter
To add debugging information to the SOAP Request Handler Servlet log files, change the value of the severity option for the value debug
in the file soapConfig.xml.
This file is placed in the directory $SOAP_HOME/webapps/soap/WEB-INF/config
on UNIX or in %SOAP_HOME%\webapps\soap\WEB-INF\config
on Windows NT.
For example, the following soapConfig.xml
segment shows the value to set for severity
to enable debugging:
<!-- se
verity can be: error, status, or debug --> <osc:logger class="oracle.soap.server.impl.ServletLogger"> <osc:option name="severity" value="debug" /> </osc:log
ger>
After modifying the value
attribute for the severity
option element in soapConfig.xml
, perform the following steps to view debug information.
stopSoapJServ
command.
startSoapJServ
command. You do not need to perform this step if the SOAP Request Handler Servlet is running in auto start mode.
After stopping and restarting the SOAP Request Handler Servlet, you can view debug information in the file jserv.log
. The file is in the directory $ORACLE_HOME/Apache/Jserv/logs
on UNIX or in %ORACLE_HOME%\Apache\Jserv\logs
on Windows NT.
Oracle SOAP is instrumented with DMS to gather information on the execution of the SOAP Request Handler Servlet, the Java Provider, and on individual services.
DMS information includes execution intervals from start to stop for the following:
soap/java-provider/
service-URI
)
To view the DMS information, go to the following site:
http://hostname
:port
/soap/servlet/Spy
|
![]() Copyright © 2001 Oracle Corporation. All Rights Reserved. | | Ad Choices. |
|