|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TODAY'S TOP SOA & WEBSERVICES LINKS Product Review Using JAX-RPC Parameter Modes with Apache Axis
Using JAX-RPC Parameter Modes with Apache Axis
Dec. 16, 2002 12:00 AM
The RPC mechanism enables a remote procedure call from a client to be communicated to a remote server. SOAP RPC supports three types of parameter modes - IN, OUT, and INOUT - for remote method invocation. In this article I'll explain how JAX-RPC supports SOAP RPC parameter modes and how to use JAX-RPC parameter modes with Apache Axis.
JAX-RPC JAX-RPC defines one static model and two dynamic models for the client side to invoke a remote procedure. In the static model, stubs are used and the code-generation tools generate the stubs. One dynamic model is based on generating a proxy object dynamically using java reflection APIs and another is based on Dynamic Invocation an Interface (DII) using the Call object. The examples shown in this article use DII rather than the static model.
JAX-RPC interfaces
JAX-RPC supports the following three types of invocation models:
The Synchronous Request-Response Mode and One-Way RPC Mode are achieved by the JAX-RPC DII Call interface.
JAX-RPC Parameter Modes
Holder Classes For example, the holder for the Double class would be:
public final class DoubleHolder implements Holder { In this article, I've used JAX-RPC Synchronous Request-Response Mode to explain the following parameter modes using Apache Axis.
This example deals with developing a currency converter soap service (conversion from dollars to rupees). The service takes only one input parameter of simple type and returns a simple type.
Developing the SOAP Service
package com.mydomain.SampleService; Here I've used the default rate; it should be replaced by the actual value.
Deploying the SOAP Service
Developing the SOAP Client
Service service = new Service(); After creating a Call object, configure the call object with the operation (method) name, parameter types, and parameter modes like IN or OUT or INOUT and return type (see Listing 2). After setting the parameter modes, parameter types, and return types, invoke the target end point by passing the parameters and get the result. The invoke( ) method calls a specified operation using the synchronous request-response interaction mode. Use the invoke OneWay( ) method for using the one-way interaction mode. The invoke method blocks until the remote service receives the method call and return either a response or an exception, whereas invokeOneWay( ) doesn't block and this method is not allowed to propagate a remote exception to the client.
Double db = new Double (4.0); Use the Axis TCP Monitor tool to see the request/response message between the SOAP server and the client on the wire. The SOAP Messages look like Listing 3. Observe the request and response message and notice that Response is appended to the name of operation i.e. convertcurrencyin. Apache Axis appends operation/ method name for the return element where as some SOAP servers don't. (See source code for this article, available at www.sys-con.com/webservices/sourcec.cfm.)
IN and OUT Parameters Using Simple Types
Developing the SOAP Service
package com.mydomain.SampleService;
Deploying the SOAP Service
<operation name="convertcurrencyout"> A parameter element is used to specify parameter modes and parameter names. This is one of the ways that Axis SOAP server gets the information about the parameters.
Developing the SOAP Client In order to get the output parameters from the target end point service, use the method getOutputParams( ) on the Call object as shown in Listing 5. The messages in Listing 6 are sent and received from the SOAP server. Observe the SOAP response, it has an additional element "result" after the return element. Each output parameter will have an element in the soap response with the output value.
INOUT Parameters Using Simple Types
Developing the SOAP Service The service looks like:
package com.mydomain;
Developing the SOAP Client Observe that code and notice that the parameter mode is ParameterMode.INOUT and the passed parameter is the holder's wrapper class, i.e., Double. There is no difference in getting the output from the service for output parameters and inout parameters. On the wire the SOAP message looks like Listing 8. So far I've discussed simple data types only. What about complex data types? JAX-RPC specifies the semantics for Java serialization in terms of XML mapping. Axis provides default serialization and deserialization for the JavaBeans. In my next example I've used user-defined holders (AddressHolder) for the output parameter and user-defined type (Address) and used axis default bean serialization. Use Apache's Java to WSDL tool to generate a WSDL file. It generates complex data types for the user-defined types like Address Object. I have not used WSDL to invoke the remote service
OUT Parameters Using Complex Types SOAP Service
package com.mydomain; Add the following entries in the deploy.wsdd file inside the service element and register the bean mappings as shown below.
<operation name="getShipmentDetail">
SOAP Client
QName qn = new QName( "urn:SampleService", "Address" ); Once the type mappings are registered, pass the parameters and invoke the service as shown:
call.setOperationName( new QName("SampleService", "getShipmentDetail") ); Retrieving the output parameter is the same as for the simple types. Generating the SOAP message on the wire looks like Listing 9. If you want to send a user-defined Holder (AddressHolder) as an INOUT parameter to the remote SOAP service, then pass the user-defined type (Address) as an INOUT parameter and register the type mappings.
References YOUR FEEDBACK
SOA WORLD LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||