Web Services
  Home arrow Web Services arrow Page 4 - Use collection types with SOAP and JAX-RPC
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
WEB SERVICES

Use collection types with SOAP and JAX-RPC
By: developerWorks
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2004-12-22


    Table of Contents:
  • Use collection types with SOAP and JAX-RPC
  • Listing 2. The generated XML Schema for the CustomerService class.
  • Listing 3. The CustomerService class using a simple array.
  • Create a wrapper interface
  • Resources

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Use collection types with SOAP and JAX-RPC - Create a wrapper interface
    ( Page 4 of 5 )

    So far, so good. But what if you have an existing class that exposes language-specific Java collection classes in its method signatures, and you still want to expose this class via a Web service?

    One relatively easy way of dealing with this situation is to create a wrapper around your service implementation, converting the collection interface into an array interface. For example, let's consider the original LinkedList-based CustomerService implementation listed above. We create a class with methods that invoke the original collection-based implementation but return Java arrays instead of the collections. The wrapper class might look like the one in Listing 5:

    Listing 5. The wrapper class.

    public class TheCustomerServiceWrapper {
      protected TheCustomerServiceLinkedList innerService =
      new TheCustomerServiceLinkedList();

      public Customer[] getCustomers(String queryString) {
        return (Customer[]) innerService.getCustomers(queryString
        ).toArray(new Customer[0]);
      }
    }


    Now you can create the appropriate Web services artifacts based on this wrapper class, which internally uses the existing collection-based implementation.

    Summary

    The Java programming language offers a variety of collection classes for different types of collections of objects. None of these, however, are language-neutral, and serializing instances of them into XML is difficult and sometimes impossible. The only recommended way to expose object collections is to use arrays. The WS-I Basic Profile also describes and recommends this approach.

    Using Java's collection classes in the signatures of the public methods of your classes is generally a poor choice, regardless of the implications associated with Web services, because doing so dilutes the "contract" between invoker and provider. These classes invariably store the objects they "collect" as generic references to java.lang.Object. This prevents static-type checking by the compiler and introduces new classes of runtime errors. In cases where an implementation already exists, you can still use an array to expose it as an interoperable Web service by using wrapper classes.

    Note that this practice agrees nicely with our good practice recommendation that business logic be coded in a Java class and wrapped in a session EJB to be exposed as a Web service.



     
     
    >>> More Web Services Articles          >>> More By developerWorks
     

       

    WEB SERVICES ARTICLES

    - Dynamic Data Analysis on the Web-a Design Ap...
    - Use collection types with SOAP and JAX-RPC
    - Blogging Away To Glory (A bBlog Primer)
    - Introduction to Service Oriented Architectur...
    - Connecting Smart Devices on the Internet
    - An Embeddable Standards Compliant Web Servic...


    Email Marketing Software
    iContact Email Marketing Software Simplifies Online Communication.
    Internet Marketing Company
    Provider of internet marketing services to boost your site rankings.
    seo firm
    SEO firm with excellent organic results for clients in all verticals
    Survey software
    Survey Software that helps you create elegant web based surverys.



    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek