Oracle® Application Server Web Services Developer's Guide
10g Release 2 (10.1.2) Part No. B14027-01 |
|
Previous |
Next |
This chapter describes the Oracle Application Server Web Services features that allow you to easily create and run a client application that uses Oracle Application Server Web Services.
This chapter contains the following topics:
Getting WSDL Files and Client-Side Proxy Jars for Web Services
Working with WSDL Files and Oracle JDeveloper to Use Web Services
When you want to use Web Services you need to develop a client application. There are two types of Web Services clients: static web service clients and dynamic web service clients. A static web service client knows where a Web Service is located without looking up the service in a UDDI registry. A dynamic web service client performs a lookup to find the Web Service's location in a UDDI registry before accessing the service. Chapter 10, "Discovering and Publishing Web Services" provides detailed information on looking up Web Services in a UDDI registry.
Using a static client Oracle Application Server Web Services provides several options for locating Oracle Application Server Web Services, including:
Using a known Web Service located at a known URL.
Using Oracle Application Server Web Services and a known service URL to obtain a client-side proxy Jar, or by other means obtaining a client-side proxy Jar for a Web Service. The client-side proxy Jar that Oracle Application Server Web Services generates includes the URL to locate the associated Web Service.
Using Oracle Application Server Web Services and a known service URL to obtain a WSDL file, or by other means obtaining a WSDL file that describes a Web Service. The WSDL files that Oracle Application Server Web Services generates includes the URL to locate the associated Web Service.
After you locate a Web Service or after you obtain either the WSDL or client-side proxy Jar, you can build a client-side application that uses the Web Service.
See Also: Chapter 10, "Discovering and Publishing Web Services" |
This section covers the following:
To use Oracle Application Server Web Services you need to create a client-side application that accesses a Web Service. Oracle Application Server Web Services supplies the following files for deployed Web Services:
WSDL service descriptions
Client-side proxy Jar (class files)
Client-side proxy source
Oracle Application Server Web Services provides a Web Service Home Page for each deployed Web Service. To access a Home Page, enter a service endpoint of the form,
http://host:port/context-root/service
Figure 8-1 shows the Web Service Home Page for StatefulExample, at the following endpoint,
http://system1.us.oracle.com/webservices/statefulTest
A Web Service Home Page provides the following:
A Link to the WSDL file - To obtain the WSDL file for a Web Service, select the Service Description link and save the file.
Links to Web Service Test Pages for each supported operation-To test the available Web Service operations enter the parameter values for the operation, if any, and select the Invoke button.
Links to the Web Service client-side proxy Jar and the client-side proxy source - To obtain the client-side proxy Jar or the client-side proxy source, select the appropriate link, Proxy Jar or Proxy Source, and save the file.
Web Service Test Pages have the following limitations:
There is no support for complex input parameters for RPC style Web Services. Such pages do not support the Invoke button.
There is no support for Document Style Web Services. Such pages do not support the Invoke button.
If you do not use the Web Service Home Page to get the WSDL file or client-side proxy for a Web Service, you can obtain these files directly.
This section covers the following:
Getting Client-Side Proxy Jar and Client-Side Proxy Source Jar
Getting Client-Side Proxy Jar and Client-Side Proxy Source by Package
To obtain the WSDL service description for a Web Service, use the Web Service URL and append a query string. The format for the URL to obtain the WSDL service description is as follows (see Table 8-1 for a description of the URL components):
http://host:port/context-root/service?WSDL
or
http://host:port/context-root/service?wsdl
This command returns a WSDL description in the form service.wsdl
. The service.wsdl
description contains the WSDL for the Web Service named service, located at the specified URL. Using the WSDL that you obtain, you can build a client application to access the Web Service.
To obtain the client-side proxy Jar for a Web Service, use the Web Service URL and append a query string. The client-side proxy Jar file contains the proxy stubs class that supports building an application that communicates using SOAP to access the Web Service. The proxy class does the following:
Provides a static location for the Web Service (the service does not need to be looked up in a UDDI registry).
Provides proxy methods for each method exposed as part of the Web Service.
Performs all of the work to construct the SOAP request, including marshalling and unmarshalling parameters, and handling the response.
The format for the URL to obtain the client-side proxy Jar is as follows (see Table 8-1 for a description of the URL components):
http://host:port/context-root/service?PROXY_JAR
or
http://host:port/context-root/service?proxy_jar
This command returns the file service_proxy.jar
. The service_proxy.jar
is a Jar file that contains the client-side proxy classes that you can use to build a client-side application to access the Web Service.
To obtain the client-side proxy source Jar for a Web Service, use the Web Service URL and append a query string. The format for the URL to obtain the client-side proxy source Jar is as follows (see Table 8-1 for a description of the URL components):
http://host:port/context-root/service?PROXY_SOURCE
or
http://host:port/context-root/service?proxy_source
This command returns the file service_proxysrc.jar
. The file service_proxysrc.jar
is a Jar file that contains the client-side proxy source files. This file represents the source code for the file service_proxy.jar
associated with the service.
When you obtain the client-side proxy Jar file or the client-side proxy source Jar, you have the option of including a request parameter that specifies a package name for the generated client-side proxy classes or source files. If the Web Service's client-side Java class is part of a particular package, then you should specify the package name to match the client-side application's package name.
The format for the URL to obtain the client-side proxy Jar and specify the package name is as follows (see Table 8-1 for a description of the URL components):
http://host:port/context-root/service?PROXY_JAR&packageName=mypackage
or
http://host:port/context-root/service?proxy_jar&packageName=mypackage
This command returns the file service_proxy.jar
. The service_proxy.jar
is a Jar file that contains the client-side proxy classes, using the specified package, mypackage for the Java package
statement.
The format for the URL to obtain the client-side proxy source Jar and specify the package name is as follows (see Table 8-1 for a description of the URL components):
http://host:port/context-root/service?PROXY_SOURCE&packageName=mypackage
or
http://host:port/context-root/service?proxy_source&packageName=mypackage
This command returns the file service_proxysrc.jar
. As for the proxy_jar
, you have the option of specifying a request parameter with a supplied package name by include a packageName=
name option. The service_proxysrc.jar
is a Jar file that contains the client-side source files for the client-side proxy that accesses the Web Service.
Table 8-1 URL for Accessing Client Side Proxy Stubs
URL Component | Description |
---|---|
context-root | The context-root is the value specified in the <context-root> tag for the web module associated with the Web Service. See the META-INF/application.xml in the Web Service's .ear file to determine this value.
|
host | This is the host of the Web Service's server running Oracle Application Server Web Services. |
mypackage | This specifies the value that you want to use for the package name in the generated proxy Jar or proxy source. |
port | This is the port of the Web Service's server running Oracle Application Server Web Services. |
service | The service is the value specified in the <url-pattern> tag for the servlet associated with the Web Service. This is the service name. See the WEB-INF/web.xml in the Web Service's .war file to determine this value.
|
The Oracle Application Server Web Services WebServicesAssembler
tool allows you to generate client-side proxies. A client-side proxy can access a Web Service that is deployed either on an Oracle Application Server Web Services endpoint or on a third party Web Service endpoint.
To generate a client-side proxy with WebServicesAssembler
, specify a <proxy-gen>
tag in the configuration file. Table 8-2 describes the <proxy-gen>
WebServicesAssembler
configuration file sub-tags.
Note: When you are generating client-side proxies and you are accessing an external WSDL file from behind a firewall, make sure to set the appropriate security properties shown in Table 8-4, such ashttp.proxyHost and http.proxyPort .
|
Example 8-1 shows a sample WebServicesAssembler
that includes a <proxy-gen>
tag.
Example 8-1 WebServicesAssembler Proxy Gen Configuration File
<?xml version="1.0"?> <web-service> <proxy-gen> <proxy-dir>/TestArea/Hotel/proxy/outside</proxy-dir> <option name="include-source">true</option> <option name="wsdl-location" package-name="myPackage.proxy"> http://terraservice.net/TerraService.asmx?WSDL</option> <option name="wsdl-location"> http://ws.serviceobjects.net/sq/FastQuote.asmx?WSDL</option> </proxy-gen> </web-service>
Table 8-2 Proxy Generation <proxy-gen> Sub-Tags
This section describes how to use the client-side proxy Jar when you are building the client-side application to access a Web Service. The client-side proxy Jar class allows you to easily build an application that uses a Web Service.
The client side proxy Jar file contains a Java class to serve as a proxy to the Web Service implementation. The client-side proxy code constructs a SOAP request and marshalls and unmarshalls parameters for you. Using the proxy classes saves you the work of creating SOAP requests for accessing a Web Service or processing Web Service responses.
Example 8-2 shows a source code sample client-side proxy extracted from a Web Service. For each operation available on the Web Service, there is a corresponding method in the proxy class. The example shows the method helloWorld(String)
that serves as a proxy to the helloWorld(String)
method in the associated Web Service implementation.
Example 8-3 shows client-side application code that uses the helloWorld()
method from the supplied client-side proxy shown in Example 8-2.
Note: When you are accessing an external Web Service from behind a firewall, make sure to set the appropriate security properties shown in Table 8-4, such ashttp.proxyHost and http.proxyPort .
|
Example 8-2 Sample Client-side Proxy Method for Web Services
public class StatefulExampleProxy { public java.lang.String helloWorld(java.lang.String param0) throws Exception { . . . } . . . }
Example 8-3 Sample Client-side Application Using a Proxy Class for Web Services
import oracle.j2ee.ws_example.proxy.*; public class Client { public static void main(String[] argv) throws Exception { StatefulExampleProxy proxy = new StatefulExampleProxy(); System.out.println(proxy.helloWorld("Scott")); System.out.println(proxy.count()); System.out.println(proxy.count()); System.out.println(proxy.count()); } }
When you build a Web Services clients using a proxy, you need to use the correct CLASSPATH
to run the client. Table 8-3 lists jars that you need to include in the CLASSPATH
.
Table 8-3 Web Services CLASSPATH Components for a Client Using a Client-side Proxy
Component Jar | Description |
---|---|
proxy.jar
|
The proxy jar file that provides access to the Web Service. |
$ORACLE_HOME/lib/xmlparserv2.jar
|
The Oracle XML parser jar. |
$ORACLE_HOME/j2ee/home/lib/http_client.jar
|
The Oracle HTTP client jar. |
$ORACLE_HOME/soap/lib/soap.jar
|
The Oracle SOAP jar. |
$ORACLE_HOME/j2ee/home/lib/mail.jar
|
Generally, this is available in the JRE. If this is not available in the JRE, then include it in the CLASSPATH. |
$ORACLE_HOME/j2ee/home/lib/activation.jar
|
Generally, this is available in the JRE. If this is not available in the JRE, then include it in the CLASSPATH |
$ORACLE_HOME/jlib/javax-ssl-1_1.jar
|
Used when the client uses SSL to connect to a Web Service that uses SSL. In this case, do not include $ORACLE_HOME/lib/jsee.jar in the CLASSPATH .
|
$ORACLE_HOME/jlib/jssl-1_1.jar
|
Required when the client is using SSL to connect to a Web Service that uses SSL. In this case, either $ORACLE_HOME/jlib/javax-ssl-1_1.jar or $ORACLE_HOME/lib/jsse.jar must be specified.
|
$ORACLE_HOME/lib/jsse.jar
|
Used when the client uses SSL to connect to a Web Service that uses SSL. In this case, do not include $ORACLE_HOME/jlib/javax-ssl-1_1.jar in the CLASSPATH.
|
$ORACLE_HOME/webservices/lib/wsdl.jar
|
Required when the client is using a Dynamic Proxy. |
$ORACLE_HOME/webservices/lib/dsv2.jar
|
Required when the client is using a Dynamic Proxy. |
When Java Beans are used as parameters to Oracle Application Server Web Services, the client-side code should use the generated Bean included with the downloaded client-side proxy. This is because the generated client-side proxy code translates SOAP structures to and from Java Beans by translating SOAP structure namespaces to and from fully qualified Bean class names. If a Bean with the specified name does not exist in the specified package, the generated client code will fail.
However, there is no special requirement for clients using Web Services Description Language (WSDL) to form calls to Oracle Application Server Web Services, rather than the client-side proxy. The generated WSDL document describes SOAP structures in a standard way. Application development environments, such as Oracle JDeveloper, which work directly from WSDL documents can correctly call Oracle Application Server Web Services with Java Beans as parameters.
When you run a client-side application that uses Oracle Application Server Web Services, you can access secure Web Services by setting properties in the client application. Table 8-4 shows the available properties that provide credentials and other security information for Web Services clients. Table 8-3 lists jar file that need to be included in the CLASSPATH, including those required to support SSL.
In a Web Services client application, you can set the security properties shown in Table 8-4 as system properties by using the -D
flag at the Java command line, or you can also set security properties in the Java program by adding these properties to the system properties (use System.setProperties()
to add properties). In addition, the client side stubs include the _setTranportProperties
method that is a public method in the client proxy stubs. This method enables you to set the appropriate values for security properties by supplying a Properties
argument.
Table 8-4 Web Services HTTP Transport Security Properties
The Web Services WSDL allows you to manually, or using Oracle JDeveloper or another IDE, build client applications that use Web Services.
The Oracle JDeveloper IDE supports Oracle Application Server Web Services with WSDL features and provides unparalleled productivity for building end-to-end J2EE and integrated Web Services applications.
Oracle JDeveloper supports Oracle Application Server Web Services with the following features:
Allows developers to create Java stubs from Web Services WSDL descriptions to programmatically use existing Web Services.
Allows developers to create a new Web Service from Java or EJB classes, automatically producing the required deployment descriptor, web.xml, and WSDL file for you.
Provides schema-driven WSDL file editing.
Offers significant J2EE deployment support for Web Services J2EE .ear files, with automatic deployment to OC4J.
Non-Oracle Web Services IDEs or client development tools can use the supplied WSDL file to generate Web Services requests for services running under Oracle Application Server Web Services. Currently, many IDEs have the capability to create SOAP requests, given a WSDL description for the service.