YOUR FEEDBACK
the usr wrote: So... how about your prediction that SCO would prevail? 11/20/2008 565 - FINAL...
SOA World Conference
Virtualization Conference
$100 Savings Expire November 18, 2008... – Register Today!


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
I know, the economy is rough these days. Myself, I'm unwilling to look at my mutual funds until we're through this. However, when times are tough, markets normalize, and while the stock holders and venture capitalists out there are crying in their beers, now could be a great time to start something...
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


Using JAX-RPC Parameter Modes with Apache Axis
Using JAX-RPC Parameter Modes with Apache Axis

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 provides a means for performing RPC over SOAP. It provides rules for client code generation, SOAP Binding, mapping from Java to WSDL and WSDL to Java, type mappings between Java and XML data types, and client APIs for constructing Web service invocations.

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
On the client side, JAX-RPC defines the following major interfaces:

  • ServiceFactory: Creates the instances of Service interface.
  • Service: Defines methods for dynamic proxy invocation and DII. getPort( ) method is used for dynamic proxy invocation.
  • Call: createCall( ) method on Service interface returns the Call object which is used for DII.

    JAX-RPC supports the following three types of invocation models:

  • Synchronous request-response mode: A Client invokes a remote method on a service and receives return values or an exception. Client blocks the thread until it gets a response from the remote service.
  • One-way RPC Mode: A Client invokes a remote method on a service endpoint in the one-way mode. The client invocation thread does not block and continues execution without waiting for this remote method invocation to be processed by the service.
  • Non-blocking RPC invocation: A service client invokes a remote method on a service endpoint and continues processing in the same thread without waiting for the return of the remote method invocation.

    The Synchronous Request-Response Mode and One-Way RPC Mode are achieved by the JAX-RPC DII Call interface.

    JAX-RPC Parameter Modes
    JAX-RPC uses pass by copy semantics for parameter passing in a remote method invocation. The JAX-RPC specification does not support the object-by-reference mode for remote method invocations. JAX-RPC specifies the following rules for the IN, OUT and INOUT parameter passing modes and return value:

  • An in parameter is passed as copy. The value of the in parameter is copied before a remote method invocation.
  • The return value is created as a copy and returned to the caller from a remote method invocation.
  • The OUT and inOUT parameters are passed by copy. JAX-RPC uses the Holder classes to support the inOUT and OUT parameters. A service client provides an instance of a Holder class that is passed by value for either out or inout parameter. The contents of the Holder class are modified in the remote method invocation and the service client uses the changed contents after the method invocation returns.
  • JAX-RPC defines ParameterMode class with static instances namely IN, OUT, and INOUT, to specify parameter-passing modes in Web service invocation. ParameterMode class acts as a type safe enumeration for parameter modes.

    Holder Classes
    Holder classes enable the mapping to preserve the intended operation signature and parameter passing semantics. A holder class is simply a class that contains an instance of its type. According to the JAX-RPC specification, each Holder class provides the following methods and fields

  • A public field named value. The type of value is the mapped Java type
  • A default constructor that initializes the value fields to a default value
  • A constructor that sets the value field to the passed parameter

    For example, the holder for the Double class would be:

    public final class DoubleHolder implements Holder {
    public double value;
    public DoubleHolder() { }
    public DoubleHolder(double value) {
    this.value = value;
    }
    }

    In this article, I've used JAX-RPC Synchronous Request-Response Mode to explain the following parameter modes using Apache Axis.

    • in parameters using simple types
    • in and out parameters using simple types
    • inout parameters using simple types
    • out parameters using complex types
    IN Parameters Using Simple Types
    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
    For example, develop a currency converter SOAP service as:

    package com.mydomain.SampleService;
    public class SampleService {
    public double convertcurrencyin(double in) {
    double res = in * 48;
    return res;
    }
    }

    Here I've used the default rate; it should be replaced by the actual value.

    Deploying the SOAP Service
    Create a Web Services Deployment Descriptor file (deploy.wsdd) in order to deploy the Web service (see Listing 1). Deploy the service using the deploy.wsdd file as described in the Axis documentation.

    Developing the SOAP Client
    Create a service using ServiceFactory in order to create the Call objects.

    Service service = new Service();
    Call call = (Call) service.createCall ( );
    String endpointURL = http://localhost:8080/axis/servlet/AxisServlet;
    call.setTargetEndpointAddress( new java.net.URL(endpointURL) );

    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);
    Object ret = call.invoke( new Object[] { db} );

    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
    This example shows how to develop a service and client using in and out parameters. The out parameters are achieved using Holder classes.

    Developing the SOAP Service
    In this example the client sends the currency to be converted as an input parameter to the service and the client receives the converted currency as output by using the holder classes. The service looks like:

    package com.mydomain.SampleService;
    public class SampleService {
    public int convertcurrencyout(double in, DoubleHolder dh) {
    double res = in * 48;
    dh.value = res;
    return 1;
    }
    }

    Deploying the SOAP Service
    Add the following entries to the deploy.wsdd file as a child element of the service element and deploy the service.

    <operation name="convertcurrencyout">
    <parameter name="arg1" mode="IN"/>
    <parameter name="result" mode="OUT"/>
    </operation>

    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
    Create a Call object and configure the objects with the service details (see Listing 4). Parameters of the type OUT need not be passed to the invoke method.

    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
    SOAP INOUT parameters are achieved using Holder classes.

    Developing the SOAP Service
    In this example the Client sends the currency as an instance of DoubleHolder. The service accesses the currency by using the holder's value field and setting the converted currency in the same field.

    The service looks like:

    package com.mydomain;
    import javax.xml.rpc.holders.*;
    public class SampleService {
    public int convertcurrencyinout(DoubleHolder dh) {
    dh.value = dh.value * 48;
    return 1;
    }
    }

    Developing the SOAP Client
    Create the Call object and configure it with the service details in Listing 7.

    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
    In this example the client sends an order ID to the remote SOAP service and the service will return the shipment address as output parameter in the response message. Since Shipment Address is an output parameter, create a holder class to hold the Address and create Address class according to the JavaBeans Specification.

    SOAP Service

    package com.mydomain;
    public class SampleService {{
    public String getShipmentDetail(String orderId, AddressHolder adrh) {
    Address adr = new Address();
    adr.setstreet("CunninghamRoad");
    adr.setcountry("INDIA");
    adrh.value = adr;
    return orderId;
    }

    Add the following entries in the deploy.wsdd file inside the service element and register the bean mappings as shown below.

    <operation name="getShipmentDetail">
    <parameter name="orderId" mode="IN"/>
    <parameter name="result" mode="OUT"/>
    </operation>
    <beanMapping qname="myNS:Address" xmlns:myNS="urn:MyService"
    languageSpecificType="java:com.mydomain.Address"/>

    SOAP Client
    On the client side, register the serializers and deserializers for the user-defined data types, i.e., for the Address object.

    QName qn = new QName( "urn:SampleService", "Address" );
    call.registerTypeMapping(Address.class, qn,
    new org.apache.axis.encoding.ser.BeanSerializerFactory(Address.class, qn),
    new org.apache.axis.encoding.ser.BeanDeserializerFactory(Address.class, qn));

    Once the type mappings are registered, pass the parameters and invoke the service as shown:

    call.setOperationName( new QName("SampleService", "getShipmentDetail") );
    call.addParameter( "orderId", XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter( "result",qn,ParameterMode.OUT);
    call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
    String orderId = "ORD_001";
    String val = (String)call.invoke( new Object[] {orderId} );

    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

  • Apache Axis: http://xml.apache.org/axis
  • JAX-RPC: http://java.sun.com/xml/jaxrpc
  • SOAP: www.w3.org/TR/SOAP
    About Aravilli Srinivasa Rao
    Aravilli Srinivasa Rao, a software analyst at Hewlett-Packard, is technical lead for the development of HP's public UDDI Registry. He has worked with HP's e-speak and Total-e-Server (J2EE Application Server) products and is currently involved in the design and development of the projects in the mobile space to implement Web services.

  • YOUR FEEDBACK
    Damodar Beena wrote: Good article and it clearly explained about OUT and INOUT usage.
    SOA WORLD LATEST STORIES
    SYS-CON's 1st International Cloud Computing Conference & Expo, on Nov. 19-21, 2008 in San Jose, CA, attracted more than 40 sponsors and exhibitors with over 1,000 preregistered delegates. The three content-packed days emphasized value with a rich array of sessions led by exceptional sp...
    "Virtualization will help our customers be more agile and efficient," noted Mike Neil this morning at SYS-CON’s Virtualization Conference & Expo, in San Jose, CA, "and there are three areas these companies are focused on." These areas are to drive costs down, increase efficiency, and...
    The future of cloud computing is all about lowering costs and getting the ability to easily move between service providers. At the Cloud Power Panel on Friday at the 1st International Cloud Computing Conference & Expo in San Jose, CA, the power panelists – Songnian Zhou, CEO of Platf...
    Intel’s most complex x86 desktop chip ever, a tiny part loaded with an incredible 731 million transistors that’s been five years in the making, has been released to the most dubious demand environment ever, especially for desktops – dubious enough for Intel to have cut its guidan...
    In his virtualization session on Nov. 21 at the 4th International Virtualization Conference & Expo in San Jose, CA, Roland Wartenberg, SAP's director of virtualization strategy, discussed the supported virtualization solutions provided by partners of SAP's virtualization ecosystem. Sim...
    With an ever increasing variety of physical and virtual endpoints, companies are rapidly facing the next big challenge – manageability. So stated Symantec's Brian Duckering and Intel's Chuck Brown in their general session on Friday at SYS-CON’s 4th International Virtualization Conf...
    SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
    SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


    SYS-CON FEATURED WHITEPAPERS


    ADS BY GOOGLE