148 lines
6.7 KiB
HTML
148 lines
6.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
|
|
|
|
<title>Migrate Apache SOAP Web services to Web services for J2EE</title>
|
|
</head>
|
|
|
|
<BODY>
|
|
<!-- Java sync-link -->
|
|
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
|
|
|
<h4><A NAME="wsmigj2ee"></A>Migrate Apache SOAP Web services to Web services for J2EE</h4>
|
|
|
|
|
|
<p>If you have used the Apache SOAP support to create Web
|
|
services client applications in WebSphere Application Server - Express Version 5.0 and want use Web
|
|
services for J2EE, also known as JSR 109, you need
|
|
to migrate your Version 5.0 client applications.</p>
|
|
<p>To migrate these client applications to the JSR 109 Web services
|
|
standards:</p>
|
|
<ol>
|
|
<li>Plan your migration strategy.
|
|
<p>There are two ways you can port an Apache SOAP client to Java API for
|
|
XML-based RPC (JAX-RPC) Web services client:</p>
|
|
<ul><li>If you have, or can create, a Web Services Description Language
|
|
(WSDL) document for the service, consider using the <strong>WSDL2Java</strong> command
|
|
tool to generate bindings for the Web service. It is more work to adapt an
|
|
Apache SOAP client to use the generated JAX-RPC bindings, but the resulting
|
|
client code is more robust and easier to maintain. To follow this path, see <a
|
|
href="../webserv/wsdevclient.htm">Develop a Web services client</a> in the <em>Web services</em> topic.</li>
|
|
<li>If you do not have a WSDL document for the service, do not expect
|
|
the service to change, and you want to port the Apache SOAP client with a
|
|
minimal work, you can convert the code to use the JAX-RPC dynamic invocation
|
|
interface (DII), which is similar to the Apache SOAP APIs. The DII APIs do
|
|
not use WSDL or generated bindings.</li></ul>
|
|
<p>You should be aware that since JAX-RPC does not specify a framework
|
|
for user-written serializers, the JAX-RPC does not support the use of custom
|
|
serializers. If your application cannot conform to the default mapping between
|
|
Java, WSDL, and XML supported by WebSphere Application Server - Express, you should
|
|
not attempt to migrate the application. </p>
|
|
<p>The remainder of this topic assumes that you have decided to use the
|
|
JAX-RPC DII APIs. </p>
|
|
</li>
|
|
<li>Convert the client application from Apache SOAP to JAX-RPC DII
|
|
<p>The Apache SOAP API and JAX-RPC DII API structures are similar. You
|
|
can instantiate and configure a call object, set up the parameters, invoke
|
|
the operation, and process the result in both. </p>
|
|
<p>You can create a generic instance of a Service object with</p>
|
|
<pre>javax.xml.rpc.Service service =
|
|
ServiceFactory.newInstance().createService(new QName(""));</pre> in JAX-RPC.
|
|
<ol type="a">
|
|
<li>Create the call object.
|
|
<p>An instance of the call object is created by </p>
|
|
<pre>org.apache.soap.rpc.Call call = new org.apache.soap.rpc.Call ()</pre> in
|
|
Apache SOAP.
|
|
<p>An instance of the call object is created by </p>
|
|
<pre>java.xml.rpc.Call call = service.createCall();</pre> in
|
|
JAX-RPC.
|
|
</li>
|
|
<li>Set the endpoint URI.
|
|
<p>The target URI for the operation is passed as a parameter to</p>
|
|
<pre>call.invoke: call.invoke("http://...", "");</pre> in
|
|
Apache SOAP.
|
|
<p>The setTargetEndpointAddress method is used as a parameter to</p>
|
|
<pre>parametcall.setTargetEndpointAddress("http://...");</pre>in JAX-RPC.
|
|
<p>Apache SOAP has a setTargetObjectURI method on the call object that contains routing
|
|
information for the request. JAX-RPC has no equivalent method. The information
|
|
in the targetObjectURI is included in the targetEndpoint URI for JAX-RPC. </p>
|
|
</li>
|
|
<li>Set the operation name.
|
|
<p>The operation name is configured on the call object by</p>
|
|
<pre>call.setMethodName("opName");</pre> in
|
|
Apache SOAP.
|
|
<p>The setOperationName method, which accepts a <tt>QName</tt> instead
|
|
of a <tt>String</tt> parameter, is used in JAX-RPC as follows:</p>
|
|
<pre>call.setOperationName(new javax.xml.namespace.Qname("namespace",
|
|
"opName"));</pre>
|
|
</li>
|
|
<li>Set the encoding style.
|
|
<p>The encoding style is configured on the call object by</p>
|
|
<pre>call.setEncodingStyleURI(org.apache.soap.Constants.NS_URI_SOAP_ENC);</pre> in
|
|
Apache SOAP.
|
|
<p>The encoding style is set by a property of the call object</p>
|
|
<pre>call.setProperty(javax.xml.rpc.Call.ENCODINGSTYLE_URI_PROPERTY,
|
|
"http://schemas.xmlsoap.org/soap/encoding/");</pre>in
|
|
JAX-RPC.
|
|
</li>
|
|
<li>Declare the parameters and set the parameter values.
|
|
<p>Apache SOAP parameter types and values are described by parameter instances,
|
|
which are collected into a Vector and set on the call object before the call,
|
|
for example: </p>
|
|
<pre>Vector params = new Vector ();
|
|
params.addElement (new org.apache.soap.rpc.Parameter(name,
|
|
type, value, encodingURI));
|
|
// repeat for additional parameters... call.setParams (params);</pre>
|
|
<p>For
|
|
JAX-RPC, the call object is configured with parameter names and types without
|
|
providing their values, for example: </p>
|
|
<pre>call.addParameter(<em>name</em>, <em>xmlType</em>, <em>mode</em>);
|
|
// repeat for additional parameters call.setReturnType(<em>type</em>);</pre> Where<ul>
|
|
<li><em>name</em> (type <tt>java.lang.String</tt>) is the name of the parameter</li>
|
|
<li><em>xmlType</em> (type <tt>javax.xml.namespace.QName</tt>) is the XML type
|
|
of the parameter</li>
|
|
<li><em>mode</em> (type <tt>javax.xml.rpc.ParameterMod</tt>e) the mode of the
|
|
parameter, for example, IN, OUT, or INOUT</li>
|
|
</ul>
|
|
</li>
|
|
<li>Make the call.
|
|
<p>The operation is invoked on the call object by </p>
|
|
<pre>org.apache.soap.Response resp = call.invoke(endpointURI, "");</pre> in
|
|
Apache SOAP.
|
|
<p>The parameter values are collected into an array and passed
|
|
to <tt>call.invoke</tt> as follows: </p>
|
|
<pre>Object resp = call.invoke(new Object[] {parm1, parm2,...});</pre> in
|
|
JAX-RPC.
|
|
</li>
|
|
<li>Check for faults.
|
|
<p>You can check for a SOAP fault on the invocation by checking the Response:</p>
|
|
<pre>if resp.generatedFault then {
|
|
org.apache.soap.Fault f = resp.getFault;
|
|
f.getFaultCode();
|
|
f.getFaultString(); }</pre>in Apache SOAP.
|
|
<p>A <tt>java.rmi.RemoteException</tt> is
|
|
thrown in JAX-RPC if a SOAP fault occurs on the invocation.</p>
|
|
<pre>try
|
|
... call.invoke(...)
|
|
catch (java.rmi.RemoteException) ...</pre>
|
|
</li>
|
|
<li>Retrieve the result.
|
|
<p>In Apache SOAP, if the invocation was successful and returns a result,
|
|
it can be retrieved from the Response object: </p>
|
|
<pre>Parameter result = resp.getReturnValue(); return result.getValue();</pre>
|
|
<p>In
|
|
JAX-RPC, the result of invoke is the returned object when no exception is
|
|
thrown: </p>
|
|
<pre>Object result = call.invoke(...);
|
|
...
|
|
return result;</pre>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
<p><strong>Note: </strong>Examples might be wrapped for display purposes.</p>
|
|
|
|
</body></html>
|