Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..


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
Everyone wants to lower their capital expenditures and increase operational efficiency - it's a sign of the times. The economy of the past 12 - 18 months has forced all organizations to do more with less and become more efficient. While everyone can identify with the request to do more with less, th...
SYS-CON.TV
Sending Out-of-Band Messages to SOAP-Based Web Services
Sending Out-of-Band Messages to SOAP-Based Web Services

SOAP, the Simple Object Access Protocol, is a lightweight toolkit for building Web services. It is an amalgam of ubiquitous technologies - HTTP and XML. Though the likes of Microsoft, IBM, and the Apache Software Foundation normally have little in common, all support it as a foundation for deploying Web services. One of the great advantages of SOAP's lightweight nature is the simplicity of server-side programming. A SOAP service needs no knowledge of the SOAP environment. In fact, just about any Java class that exposes public methods can be turned into a SOAP service.

Unfortunately, sophistication usually brings complication. While there is little you need to do to write a SOAP-based Web service, it is difficult for a service to know much about the context of a request being made. Should the service evolve over time, you might want the client to provide a service version so a proper response may be sent to a back-revision client. If a service is available to a number of applications, it may be useful to know which is making a request. The obvious approach to solving this problem is to add additional parameters for these things to the service. This quickly becomes annoying for the service programmer, as every method in every service would require these parameters. Things become tedious for the client programmer also, as such information is relatively static and would be duplicated across every call.

A Basic SOAP Web Service
Consider Listing 1 (all code listings may be found at  . www.sys-con.com/webservices/sourcec.cfm). TestService certainly is a trivial service, but no special coding is required to make this a SOAP service. The SOAP RPC router and Java reflection do the work of receiving a request and matching it up with a deployment descriptor and method signature. The code to call it would look like Listing 2. You will need a copy of SOAP from Apache to try the examples. These were built with version 2.0. Use the SOAP administrative interface to deploy the service.

The obvious way to add information like application name and service version to this example would be to add parameters to the call. A better approach would be to develop an out-of-band communication channel with SOAP services. Likewise, the service would need some way of finding these values while servicing a request. As HTTP is one of the component technologies, can the additional information be included in HTTP headers?

HTTP and SOAP
Looking at the conversation between the example client and server above, we see the conversation shown in Listing 3. With the exception that the content of the POST is a SOAP payload, there is nothing unusual about this interaction. So, if we are to use HTTP headers to transmit out-of-band messages, how can we affect the SOAP conversation to include additional headers? It might be tempting to use the SOAPAction value, but its definition is somewhat fuzzy and probably should be avoided. The mechanism we should use is not obvious from the client example above, but there is a way.

Extending the SOAPHTTPConnection
There is a method on the Call object that enables us to provide an instance of a SOAPTransport. SOAPTransport is responsible for transmitting the SOAP payload to the server and receiving the response. Normally, this would be an instance of SOAPHTTP Connection, though you could use an SMTP-based transport. Looking at the documentation for SOAPTransport, we see that the send() method enables us to contribute headers to the request. There is also a getHeaders() method that enables us to see the headers from the response. Our solution lies in extending SOAPHTTPConnection and providing our own send(), as in Listing 4.

Our send() arranges for the out-of-band messages to be included with any headers SOAP has inserted, then calls super.send(). The messages are stored in a static hash table, so they will be shared across every instance of this SOAPTransport. We have also included some helper methods to add, remove, and get messages from the hash table. To use this new SOAPTransport we modify TestMain as in Listing 5.

The static initial-ization block will ensure that any mes-sages are set on our SOAPTra-nsport before we have a chance to use it. If TestMain was a servlet, the APP_NAME and APP_VER values might be obtained from the servlet conf-iguration and set dur-ing the servlet's init(). Running the modified sample, the message sent from the client now looks like Listing 6.

Creating a Service Context for SOAP Services
The headers are now included in the request being sent to the server, and the server is accepting them, though not acting upon them. On the receiving end, the challenge is the fact that the SOAP service is running in a context-free environment. If we can solve our problem without building a dependency upon SOAP mechanisms into our services, we will be able to use our services in other environments. Listing 7 shows a class that provides the necessary context.

Note the use of an InheritableThreadLocal to store a hash table. Values stored with a ThreadLocal's get() and set() methods are unique to that thread. An Inheritable ThreadLocal ensures that any threads created after a value is set inherit that value. This is important since, server-side, the request is driven by a servlet called RPCRouterServlet. Most servlet containers, such as Tomcat or JRun, will create a pool of threads to service requests. Each time we make a request, a thread is taken from the pool and returned when the request is complete. Our service may be called by any number of applications (and versions of applications) and, using an InheritableThreadLocal, the application name and version may be attached to the thread servicing the request.

Next, we must extend the SOAP RPCRouterServlet as in Listing 8. This extension intercepts the call to doPost() (RPCRouterServlet rejects GET requests), extracts the messages, and adds them to the ServiceContext. Following the call to super.doPost(), it calls ServiceContext.clear() to ensure that the thread does not service another request with incorrect information attached to it. The final step, Listing 9, updates the service to use the ServiceContext. Now, running the TestMain class:

> java TestMain foo

The returned value was 'The argument you sent was 'foo', your application name is 'TestMain', your application version is '1.0'"

Cautions
The idea of using a ThreadLocal or InheritableThreadLocal client-side to transmit user credentials (i.e., value of Http ServletRequest.getRemoteUser()) might be tempting. Doing so asks the client of a service to identify itself honestly. Sending a username and password would be done in the clear. Unless you secure access to your services to trusted clients or have trusted clients digitally sign the message, it probably isn't a good idea.

If you look at SOAPSMTPConnection you'll see that, although it does implement the SOAPTransport interface, it ignores the headers parameter on the send() method. This technique will not work with an unmodified Apache SOAP implementation if you are using SMTP as a transport.

Summary
Using HTTP headers as an out-of-band communication channel is relatively straight-forward, and the channel can just as easily be extended to be bi-directional. Use of this technique should take some unnecessary drudgery out of SOAP programming.

About Mark Moore
Mark Moore is currently an independent consultant. Previously, he was
Chief Architect for KPMG International's Global Knowledge Exchange,
deploying knowledge sharing capabilities to 80,000 KPMG employees in more
than 40 countries. He has been designing and developing web-based knowledge
management and collaborative solutions for the last six years.

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

Register | Sign-in

Reader Feedback: Page 1 of 1

You misquote me, then accuse me of incorrectness. The group of players I name is larger than the one in your posting. You could pick any two and find some common ground at some point in their history. Even IBM and Microsoft agreed on OS/2, once upon a time.

Since "Bob's" email no longer works, I will post a response to his comments.

Bob,

I was hunting up the URL for one of my articles and noticed the two comments you left on the "Out of band communications" article. Too bad you didn't email them to me as well, as I would have been happy to discuss them with you.

For the "Snob" comment, I would counter that in my 17 years of experience, starting with OS programming and compiler building at Prime computer I have programmed, professionally, in the following languages: Several Assemblers -- both accumulator and general register, flat and segmented address spaces -- PL/1, COBOL, Modula II, Ada, C, C++, VB, Java, and Various scripting and 4GL languages.

I've also programmed in many more languages non-professionally, and too many OSs and environments to count. All have their advantages and disadvantages. I do not think I am a snob. I'm sorry you do. Unfortunately, the space requirements of such an article do not allow me to demonstrate my facility with all of these things simultaneously.

As for the "Standards" comment. The article uses only published interfaces and common extension techniques. The technique documented also works with a .NET/C# back-end and, in fact, that was the original implementation that inspired the article. Again, the space allowed in an article does not permit the demonstration of all permutations. As for the example, most didactic examples seem contrived. It was used for simplicity, and every attempt was made to ensure the example did not detract from the technique itself. After all, the purpose was to demonstrate a technique, not tell the tale of the development requirements that lead to it. I can only say that out of band communication is a common comms technique (note chapter 14 in the following book: http://www.pearsonptg.com/book_detail/0,3771,0789722410,00.html) and that most programmers will require at some time in their carreer and it should be part of every programmers toolbox -- It is not a "work around".

Sorry you did not find the article useful,

Mark

You developed an incredibly complex work around solution. Better to do a good design effort in the first place! But what ever you do, DO NOT go around the standards.

Programmers who are so stuck on one technology or company not to be willing to look at good solutions, miss a lot.
You obviously fall into the JAVA or nothing crowd. Too bad, keep you head in the sand.

'IBM, and the Apache Software Foundation normally have little in common' - IBM is using Apache HTTP server on AIX and, no doubts, on other platforms as well. I understand that MS has nothing in common with other players though (other than stolen code).

Brgrds
V.Levine


Your Feedback
Mark wrote: You misquote me, then accuse me of incorrectness. The group of players I name is larger than the one in your posting. You could pick any two and find some common ground at some point in their history. Even IBM and Microsoft agreed on OS/2, once upon a time.
Mark wrote: Since "Bob's" email no longer works, I will post a response to his comments. Bob, I was hunting up the URL for one of my articles and noticed the two comments you left on the "Out of band communications" article. Too bad you didn't email them to me as well, as I would have been happy to discuss them with you. For the "Snob" comment, I would counter that in my 17 years of experience, starting with OS programming and compiler building at Prime computer I have programmed, professionally, in the following languages: Several Assemblers -- both accumulator and general register, flat and segmented address spaces -- PL/1, COBOL, Modula II, Ada, C, C++, VB, Java, and Various scripting and 4GL languages. I've also programmed in many more languages non-professionally, and too many OSs and environments to count. All have their advantages and disadvantages. I do not think I am a snob....
bob wrote: You developed an incredibly complex work around solution. Better to do a good design effort in the first place! But what ever you do, DO NOT go around the standards.
Bob wrote: Programmers who are so stuck on one technology or company not to be willing to look at good solutions, miss a lot. You obviously fall into the JAVA or nothing crowd. Too bad, keep you head in the sand.
Viktor Levine wrote: 'IBM, and the Apache Software Foundation normally have little in common' - IBM is using Apache HTTP server on AIX and, no doubts, on other platforms as well. I understand that MS has nothing in common with other players though (other than stolen code). Brgrds V.Levine
SOA World Latest Stories
This coming Tuesday, December 8, at 2:00PM EST, SYS-CON.TV will be broadcasting live from its 4th-floor studio overlooking Times Square in New York City a very special "Power Panel" in which Cloud Computing Expo Conference Chair Jeremy Geelan and three top industry guests will be looki...
If you are like me, you are regularly receiving unsolicited email from various quarters, telling you about the latest and greatest SEO solutions on the planet. Just buy the book, or guide, or download the promotional whitepaper and this expert will offer you the latest "Secrets" to sea...
There's a lot of talk about how we need to focus on our buyers' issues and provide them educational insights to help them learn what they need to know to make buying decisions. Heck, I say it in my book...in several places, I think. I've said it on this blog, and I'll continue to say i...
This past weekend I set out explore some of the extension capabilities of Google Wave. One of the weaknesses that have been identified by many is the lack of integration with email. For me, in particular, because Wave is new, many Waves are being orphaned as those playing and testing o...
More good news for cloud computing! Google last week released its once mysterious Chrome Operating System to open source. Chrome OS, available in 2010 – is a web-based operating system that promises to boot up super-fast on a netbook – way faster than the time it takes to start your ba...
In CloudBerry Lab we are striving to make our customer service better. In this competitive market with the abundance of free offerings this is the only way to stay afloat. One of the ways to keep customers happy is to be very responsive when it comes to support request resolution. Shou...
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