YOUR FEEDBACK
Kyle Simpson wrote: Uhh, how exactly is this really at all different from flash and externalinterfac...
Cloud Computing Conference
March 30 - April 1, New York
Register Today and SAVE !..


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
As you can imagine, I spend a lot of time speaking to people about service-oriented architecture (and its variants for infrastructure and enterprise) and about how best to create a true implementation (or at least, an effective one). There is a great deal of detail in creating such an artifact – d...
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


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.

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 is the premier social graph fully integrating with the premier enterprise cloud computing company - this is the true power of Internet," gushed Marc Benioff, Chairman and CEO of Salesforce.com, as he today launched a new offering called Force.com for Facebook – designed to fost...
The other day, HP, the industry's resident smarty pants, let drop that starting this fiscal year – which is now, oh, five or six weeks old – it will save a billion dollars a year on IT compared to 2005 – although it's added upwards of $25 billion in revenue since then. COO Randy ...
Thanks to a sketchy notice in the Official Journal of the European Union we now know a tad more about why Intel has taken the European Commission to court. Seems Intel is accusing the EC of making it the butt of a "discriminatory and partial" antitrust investigation because the EC won'...
If you've been following me on Twitter, or through my other blogs, you already know that I made it to the SOA World Conference & Expo in San Jose, CA, which was collocated with Cloud Computing Conference & Expo. I did the keynote on Wednesday and then stayed around for some of the sess...
A few years ago, a British newspaper speculated on what might be the Web equivalent of the Seven Wonders of the World, and received suggestions that were hardly surprising: Google search, the Amazon.com e-tail portal, the eBay auction mechanism, etc. But that was back in 1991, before F...
Active Endpoints has announced the general availability of ActiveVOS 6.0.2, in response to ever increasing demands for improved process performance and efficiencies. ActiveVOS is an all-in-one, 100% standards-based orchestration and business process management system (BPM) that permits...
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