Comments
bruce.armstrong wrote: Somebody just said it better than I did, and with more chops to say it: Open Letter to Mark Zuckerberg, Sheryl Sandberg & Facebook Mobile
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2
Creating Message-Based Web Services with WebSphere Studio Application Developer, Part 2

Part 1 of this article (WSDJ, Vol.1, issue 7) showed how to create and use SOAP message-based Web services in WebSphere Studio Application Developer (WSAD). The standard behavior of such services is synchronous. Despite the provision for asynchronous operation of the message-based Web service proxy in Part 1, the operation wasn't actually asynchronous. This article shows how to provide for truly asynchronous operation using threads.

Instrumenting the Web Service Client
We'll first instrument the Web service client so we can more easily understand its behavior. Listing 1 shows the Web service modified to introduce a two-second delay between receiving the request and returning the response.

Listing 2 shows the client from Part 1 modified so that the client calculates the time required to execute the proxy's send() and receive() methods. The modified client also prints those times.

If you run the modified client, you'll see something similar to the following results in the Console view:

  • The Web service echoed the attribute; the value is "good"
  • The proxy send invoked - interval 2273
  • The proxy receive invoked - interval 100

    The time for the send() method reflects the two-second delay introduced into the Web service. This is because the SOAP Message.send() method used in the proxy send() method called by the client is synchronous.

    Creating an Asynchronous Message Client Proxy
    To introduce asynchrony, we must introduce a "proxy" thread that makes the synchronous call to the Web service so that the proxy send() method, running in the "client" thread, can operate asynchronously with respect to the Web service. The approach shown in Listing 3 introduces a wrapper for the proxy from Part 1. The wrapper has the same signature as the proxy, so the client doesn't have to change. This approach reuses the proxy from Part 1 unmodified.

    First, we create a class that will be used to synchronize the client and proxy threads. The class shown in Listing 3 implements a rather standard pattern for synchronizing threads, using synchronized get() and put() methods.

    Listing 4 shows the implementation of the proxy thread. It implements methods needed to set the URL for the endpoint of the Web service, set the input to the Web service, and set the synchronizing object. Of course, it also has a run() method, which calls setURL(), send(), and receive() methods in the original proxy (from Part 1) to invoke the Web service and get the response. It then puts the response in the synchronizing object.

    Listing 5 shows the proxy wrapper, which has the same signature as the original proxy in Part 1. The new send() method creates an instance of the synchronizing class and an instance of the new thread object and starts the thread. This causes invocation of the proxy thread's run() method, which in turn calls the Web service. The new receive() method calls the get() method of the synchronizing object to retrieve the response.

    Since the revised proxy has the same signature as the proxy in Part 1, we need to make only a small change in the client to use the new threaded proxy. Simply change "Message ServiceProxy" to "ProxyWrapper" and save the revised client. Now run client. You'll see something similar to the following results in the Console view:

  • The Web service echoed the attribute; the value is "good"
  • The proxy send invoked - interval 300
  • The proxy receive invoked - interval 2404

    The two-second delay in the Web service is now reflected in the receive() method. This is exactly the asynchronous behavior desired.

    Summary
    This article walked you through the steps necessary to introduce asynchrony into SOAP message-based Web services. The solution shown isn't the most complete or efficient - exceptions aren't really handled correctly, and it features reuse of both client code and proxy code from Part 1. However, it's a good start that can be customized.

    References

  • "Creating Web-Based Messages with WebSphere Studio Application Developer - Part 1." WebSphere Developer's Journal. Vol.1, issue 7.
  • Web services zone on IBM developerWorks: www.ibm.com/developerworks/webservices.
    About Greg Flurry
    Greg Flurry is a member of the IBM Software Group Emerging Technologies area. His current responsibilities include introducing web services techologies into the IBM WebSphere product family.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Enterprise Open Source Magazine Latest Stories . . .
    Before embarking on using open source cloud technology for your web property, a basic understanding of cloud, as it’s used in the industry, is essential. While there might be exceptions, here are the definitions. A software application delivered on the web instead of installing standa...
    Businesses today generate billions of events or 100s of TBs of data in a month. These data contain valuable insights into customer behavior, key trends, buying patterns, etc. If these are successfully mined, they can lead to successful decision-making to maximize revenue and traffic fo...
    Grid Dynamics, an eCommerce technology solutions company, and GridGain Systems, makers of an open source in-memory platform for Big Data processing, on Wednesday announced the expansion of their partnership which began in 2008. Grid Dynamics provides personalization and big data solut...
    Private clouds solve many problems for enterprises and bring unique operational challenges along with them. There are dozens of companies of all sizes that will build you a private cloud and turn over the keys – then what? Trying to convert a traditional enterprise IT operations team t...
    The networking industry has gone through different waves over last 30+ years. In the ’80s, the first wave was all about connecting and sharing; how to connect a computer to other peripheral devices and other computers. There were many players who developed technology and services to ad...
    If your organization already uses virtualized infrastructure, you are well on your way to providing IT as a Service. But as businesses demand faster results in today’s competitive market, organizations look to gain more benefits from cloud computing than just virtualized infrastructure...
    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