<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>subbu.org &#187; Web Services</title>
	<atom:link href="http://www.subbu.org/blog/category/web-services/feed" rel="self" type="application/rss+xml" />
	<link>http://www.subbu.org</link>
	<description>HTTP, REST and some Cycling</description>
	<lastBuildDate>Tue, 13 Jul 2010 00:09:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resource Access Spin</title>
		<link>http://www.subbu.org/blog/2008/07/resource-access-spin</link>
		<comments>http://www.subbu.org/blog/2008/07/resource-access-spin#comments</comments>
		<pubDate>Tue, 15 Jul 2008 11:32:29 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2008/07/resource-access-spin/</guid>
		<description><![CDATA[What is striking about the WS-Empire striking back (borrowing from Mark&#8217;s post) is not the attempt to &#34;standardize&#34; certain new features for SOAP messages, but the apparent lack (or break-down) of a cohesive guiding principle for architecting SOAP-based web services. I&#8217;m referring to WS-ResourceTransfer here.

Let me get to the basics. According to SOAP 1.2, 

SOAP [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>What is striking about the WS-Empire striking back (borrowing from Mark&#8217;s <a href="http://www.mnot.net/blog/2008/07/04/a_new_dread">post</a>) is not the attempt to &quot;standardize&quot; certain new features for SOAP messages, but the apparent lack (or break-down) of a cohesive guiding principle for architecting SOAP-based web services. I&#8217;m referring to <a href="http://www.ibm.com/developerworks/library/specification/ws-wsrt/">WS-ResourceTransfer</a> here.</p>
<p><span id="more-194"></span></p>
<p>Let me get to the basics. According to <a href="http://www.w3.org/TR/soap12-part1/">SOAP 1.2</a>, </p>
<blockquote><p>
SOAP Version 1.2 is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. &#8230; using XML technologies, an extensible messaging framework containing a message construct that can be exchanged over a variety of underlying protocols.
</p></blockquote>
<p>If I buy into this model, I would take it that the message describes everything &#8211; the operation/verb, the data, and any additional instructions to process the data. </p>
<p>But if we look at WS-ResourceTransfer, it says that</p>
<blockquote><p>
it intends to form an essential core component of a unified resource access protocol for the Web services space&#8230;
</p></blockquote>
<p>and then goes on to define <em>a standardized technique for accessing resources</em> using <em>semantics familiar to those in the system management domain: get, put, create and delete</em>.</p>
<p>What? One of the strongest arguments in the REST vs WS-* debate so far has been that a uniform interface (as in REST) is not adequate to describe the varieties of operations that enterprises need to do (with WS-*). But then why attempt to define a uniform interface <em>familiar to those in the system management domain</em> when the WS-* side concluded that uniform interfaces don&#8217;t meet the needs? Looks like a <a href="http://stage.vambenepe.com/archives/225">resource access</a> spin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2008/07/resource-access-spin/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JSR286 and WSRP 2.0</title>
		<link>http://www.subbu.org/blog/2008/02/jsr286-and-wsrp-20</link>
		<comments>http://www.subbu.org/blog/2008/02/jsr286-and-wsrp-20#comments</comments>
		<pubDate>Sat, 16 Feb 2008 10:31:15 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Web Services]]></category>
		<category><![CDATA[J2EE]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2008/02/jsr286-and-wsrp-20/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>Yesterday, I was tipped by one of my ex-colleagues at BEA that both <a href="http://jcp.org/en/jsr/detail?id=286">JSR-286</a> and <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wsrp">WSRP 2.0</a> have been finalized and submitted for voting by JCP and OASIS respectively. I was an active contributor to both these specifications till mid 2007. Congratulations to both the working groups!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2008/02/jsr286-and-wsrp-20/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why do Open APIs Matter?</title>
		<link>http://www.subbu.org/blog/2007/09/why-do-open-apis-matter</link>
		<comments>http://www.subbu.org/blog/2007/09/why-do-open-apis-matter#comments</comments>
		<pubDate>Wed, 19 Sep 2007 20:40:42 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2007/09/why-do-open-apis-matter/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>To quote <a href="http://www.highscalability.com">HighScalability</a> on <a href="http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster">Scaling Twitter</a>,</p>
<div class="note">
Turn your website into an open service by creating an API. Their API is a huge reason for Twitter&#8217;s success. It allows user&#8217;s to create an ever expanding and ecosystem around Twitter that is difficult to compete with. You can never do all the work your user&#8217;s can do and you probably won&#8217;t be as creative. So open you application up and make it easy for others to integrate your application with theirs.
</div>
<p>In other words, expect your users to be as creative as you are (if note more), and let them compete to build interesting applications around your software.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2007/09/why-do-open-apis-matter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST vs WS &#8211; History Repeats</title>
		<link>http://www.subbu.org/blog/2007/07/rest-vs-ws-history-repeats</link>
		<comments>http://www.subbu.org/blog/2007/07/rest-vs-ws-history-repeats#comments</comments>
		<pubDate>Thu, 12 Jul 2007 10:11:06 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2007/07/rest-vs-ws-history-repeats/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>Recently, there have been a number of blog posts and articles on this topic, and this time around, the REST side is winning, and I find two reasons for this shift. Firstly, HTTP is more ubiquitous than ever. Secondly, WS-* has reached a point where the complexity of specifications and related abstractions overtook the basics. This recent shift reminds me of the history of CORBA, and how it had its glory and then quickly lost it.</p>
<p><span id="more-107"></span></p>
<p>Looking at WSDL, SOAP, and related base WS specifications, the basic problem they try to solve is to keep the interfaces and messages independent of how messages are transported from one point to another. This kind of transport agnosticism is set in stone in some of the base specs. Most implementors of web services followed suite, and architected the core runtime such that &#8220;transport&#8221; is a last minute detail that can be changed at will without changing the semantics of application. Given that the goal is to keep the application independent of the transport, some of the basic ideas in SOAP and WSDL are not unnatural, although that does not excuse the proponents from the complexity and unparsable language introduced in some of the specs.</p>
<p>The trouble is that, the folks who designed WS standards and implementations solely for <a href="http://www.subbu.org/weblogs/main/2006/08/protocol_agnost_1.html">transport agnostic</a> scenarios ended up selling the technology as a means to build loosely coupled distributed applications. With that, folks came up with explanations for why SOAP has headers, why SOAP needs additional security specifications, why you need special purpose web service proxies, and so on. This silliness went to the extent that some folks started circulating FUD that you <a href="http://www.iks.inf.ethz.ch/education/ss07/ws_soa/slides/SOAPvsREST_ETH.pdf">can&#8217;t get the right &#8220;ilities&#8221; with REST</a>. This kind of pitch works as long as the majority of applications are talking to each other over diverse transports, but that is not the reality today.</p>
<p>The reality is that, HTTP is more predominant today than ever. When the transport is HTTP, it makes more sense to design the interface to take advantage of the transport to the extent possible, and not try to hide the transport. With this approach, there is no need to bend over backwards and invent crazy specifications for things that could be solved very simply with HTTP. I find that this a bigger reason for the recent shift towards REST over WS. This shift may have less to do with the core principles of REST.</p>
<p>This change is somewhat similar to what happened to <a href="http://en.wikipedia.org/wiki/CORBA">CORBA</a>. When CORBA was designed, it was meant to solve a similar problem &#8211; i.e. to keep applications written in heterogeneous languages talk to each other. But then, it was sold as a general purpose distributed object technology, and ended up becoming uber-complex, but complexity can not be sold for ever. That is precisely what is happening to WS today.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2007/07/rest-vs-ws-history-repeats/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON as a General Purpose Alternative?</title>
		<link>http://www.subbu.org/blog/2007/01/json-as-a-general-purpose-alternative</link>
		<comments>http://www.subbu.org/blog/2007/01/json-as-a-general-purpose-alternative#comments</comments>
		<pubDate>Thu, 04 Jan 2007 10:30:56 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Web Services]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2007/01/json-as-a-general-purpose-alternative/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>The <a href="http://www.25hoursaday.com/weblog/PermaLink.aspx?guid=d639d908-7fbc-40cd-8e36-e6d48c07f659">discussion</a> at Dare Obasanjo&#8217;s blog, and the references to some other recent posts motivate me to look at some of the broader arguments being made. It is clear that processing JSON data using JavaScript is trivial, and that is what makes JSON a popular alternative over XML currently. All other advantages and disadvantages over XML are incidental. If we take out JavaScript from the picture, JSON is not a clear winner. Both JSON and XML take some effort to parse and process outside JavaScript.</p>
<p><span id="more-88"></span></p>
<p>Unfortunately, some in the industry are missing this point, and concluding that JSON is a clear winner over XML for other reasons such as being a simpler format, faster and so on. For instance, in his post <a href="http://www.tbray.org/ongoing/When/200x/2006/12/21/JSON">JSON and XML</a>, Tim Bray seems to be favoring JSON because &ldquo;JSON&#8217;s single prpose design is to put struts on the wire&rdquo; That&#8217;s not why web developers favor JSON over XML. It is the complexity of processing on the browser, and JSON makes it trivial.</p>
<p>I tend to agree with <a href="http://pluralsight.com/blogs/dbox/archive/2007/01/03/45560.aspx">Don Box</a>, who commented that &ldquo;JSON has a huge hill to climb to displace XML for new applications that don&#8217;t already have a JavaScript/browser component&rdquo;. We need some more serious efforts to simplify JSON creating/parsing in languages other than JavaScript to make JSON more general-purpose than it is today. Although there is <a href="http://www.megginson.com/blogs/quoderat/2007/01/03/all-markup-ends-up-looking-like-xml/">no information that can be represented in an XML document that cannot be represented in a JSON document</a>, it does not mean that all new applications should switch from XML to JSON. For now, if a browser is the consumer of the data, consider JSON over XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2007/01/json-as-a-general-purpose-alternative/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>More on Validation</title>
		<link>http://www.subbu.org/blog/2007/01/more-on-validation</link>
		<comments>http://www.subbu.org/blog/2007/01/more-on-validation#comments</comments>
		<pubDate>Wed, 03 Jan 2007 20:42:19 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Web Services]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2007/01/more-on-validation/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>Does validation mean that interface and implementation are tightly coupled, making the service hard to maintain? Mark Baker posted some <a href="http://www.coactus.com/blog/2007/01/two-more-reasons-why-validation-is-still-harmful/">more questions on validation</a> yesterday. Validation does have merits in some cases, and the bigger challenge is designing extensible interfaces.</p>
<p><span id="more-87"></span></p>
<p>His first comment is that </p>
<div class="note">
Schemas, on the other hand, when used in a typical “gatekeeper” style &#8211; where the software doesn’t see the document until after it’s passed validation &#8211; break encapsulation by enforcing some business rules separately from the software responsible for them. In practice, it’s rarely the case that software doesn’t also have some of these rules, meaning that they’re duplicated, creating a maintainability issue.
</div>
<p>For an outsider/client, it does not matter whether a service failed due to validation error or some other failure. All that the client wants to know is whether the message was processed, and if not, why not. What difference does it make whether a scheme validator failed because &ldquo;ABC123&rdquo; is not a valid 5-digit number or some code block failed because it needs a valid ZIP code to proceed? In that sense, what is the difference between the a structural/value constraint in a schema or some error generated in code.</p>
<p>Another way to look at this is in terms of preconditions and post-conditions. As part of the interface design, it is sensible to express what the preconditions are and what the post-conditions are. Preconditions tell the client what needs to happen for the software to be able to process a request. Agreed that schema languages do not have the smartness to represent all possible preconditions, but they can simplify the effort required to implement certain preconditions in code. Let&#8217;s say, the software need to process a purchase order, and certain pieces of data are required to make a purchase order meaningful &#8211; for example, it may need certain product descriptions, some contact info etc. To verify these preconditions, the software needs to check that these elements are supplied, and that they make sense (i.e. the software understands those product descriptions and contact info). In most cases, it is possible to express these preconditions in a schema language, and let a validator assert some of the preconditions. This saves time and effort. As I argued in my <a href="http://www.subbu.org/weblogs/main/2006/12/is_validation_h_1.html">previous post</a>, upon a validation error, whether to fail immediately or continue is a use-case specific. </p>
<p>There is one particular case where I would consider validation dangerous. It some cases the same software may be described by multiple interfaces. In those case, it is better to keep the software itself decoupled from the interface description, i.e. from the schema language used for describing the interface, and verify the preconditions within code and not rely on a validator.</p>
<p>Preconditions are important to make an interface description useful. The key challenge here is specifying the preconditions such that they are extensible and not set in stone. The current version of the software may only be able to process locations expressed as <tt>&lt;address&gt;&lt;street&gt;&lt;/street&gt;&lt;city&gt;&lt;/city&gt;&lt;/address&gt;</tt>, but the next version may also be able to process a &ldquo;<tt>street, city, zip</tt>&rdquo; format, or even geo-coordinates. As the software gets smarter, it needs to be able to process more kinds of messages without significantly changing the interface itself. That is where the schema languages are lacking. It is true that schemas can be used to address extensibility &#8211; but in reality &#8211; the solutions are painful to implement &#8211; like versioning a schema, introducing extension points and so on. The must-ignore rule is easy enough to implement, but the rest of the schema extensibility solutions are not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2007/01/more-on-validation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Axis2 and the Let Us Repeat Success Strategy</title>
		<link>http://www.subbu.org/blog/2006/12/axis2-and-the-let-us-repeat-success-strategy</link>
		<comments>http://www.subbu.org/blog/2006/12/axis2-and-the-let-us-repeat-success-strategy#comments</comments>
		<pubDate>Wed, 27 Dec 2006 11:19:23 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Web Services]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2006/12/axis2-and-the-let-us-repeat-success-strategy/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>Sanjeeva Weerawarana of Axis-fame gave a candid and somewhat introspective talk on <a href="http://www.bloglines.com/blog/sanjiva?id=163">Web Services Middleware</a> a few weeks ago at Google. The talk was mostly about the history behind SOAP and WSDL, about how Axis1 was designed, how Axis2 is radically different, and the grand scheme of things around Axis. A video of this talk is available at <a href="http://video.google.com/videoplay?docid=1710477770315021899&#038;q=type%3Agoogle+engEDU">http://video.google.com</a>.  This is a talk worth listening to. Sanjeeva does a good job at summarizing things around SOAP, WSDL and Axs. Based on his overview, and my own limited experience, I think Axis2 is based on a good architecture, but it may have come late to the field, and with lots of bugs and compatibility problems. </p>
<p><span id="more-85"></span></p>
<p>It is amusing to watch one of the SOAP-proponents admit that &ldquo;letting a Java class be turned into a web service&rdquo; was a big mistake. I must congratulate him for being so candid about it. He also points out that every web services stack worth a name now follows the same paradigm &#8211; write a Java class, click a few buttons, and out comes a web service &#8211; to become part of a grand SOA soup. Of course, this approach demos well &#8211; marketing folks love this kind of stuff. <a href="http://jcp.org/en/jsr/detail?id=181">JSR 181</a> takes it one step further by letting you add Java annotations to Java classes to turn them into a web service.  I bet this class-first approach will turn out into a nightmare once the service is put into serious use. Well &#8211; it is too late.</p>
<p>Coming back to Axis, IMO, Axis 1.x was good enough for most applications. It promotes the class first approach, has a built in Java-XML binding framework, and works reasonably well. It was widely used, and most bugs got fixed over time. May be having Java-XML binding at the core was a mistake &#8211; but who cares &#8211; most developers write code using the generated beans anyway. Apparently this was not good enough for some, and Axis had to be rewritten.</p>
<p>I&#8217;m not a big fan of rewriting software for architectural reasons. Just because the original version was successful, it is naive to assume that the rewrite will be equally, if not more, successful. Moreover, rewrites usually break feature, API and bug compatibility &#8211; and Axis2 did that completely.</p>
<p>Here is my personal experiece with Axis. Our team at work uses Axis to drive some web services for testing our product. Our experience with Axis versions upto 1.3 was satisfactory. We did generate POJOs from a WSDL and schemas, and wrote test clients using the generated code. Then came a new version of the WSDL, and Axis 1.3 could not handle that. We ran into some serialization bugs, and so wanted to try 1.4. No luck with that either. Then we tried the <em>all new</em> Axis2. What a disappointment? It is completely incompatible with Axis 1.x at the source level itself. Moreover, it had new kinds of feature incompatibilities and bugs forcing us to hack it to make it work. Another consequence of this rewrite exercise is that bugs filed against Axis 1.x now go into the <a href="http://www.jwz.org/doc/cadt.html">use new version please</a> void.</p>
<p>To give a more concrete example, Axis 1 had a nifty little feature to let the stub instance replay cookie headers between requests. You just call <tt>setMaintainSession(true)</tt> on the stub instance. Internally, this class makes the stub capture all <tt>Set-Cookie</tt> headers from responses and send <tt>Cookie</tt> headers on future requests. You might ask why would I want to care about transport headers while writing web services. Well, web services is a leaky abstraction, and <a href="http://www.subbu.org/weblogs/main/2006/08/protocol_agnost_1.html">protocol agnosticism</a> does not work in reality.</p>
<p>Axis2 supposedly has an equivalent of <tt>setMaintainSession(true</tt>. The equivalent is to do something like</p>
<pre class="brush: java">
Options options = new Options();
options.setManageSession(true);
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
</pre>
<p>But this turned out be more complex than I originally thought. This was not a replacement at all. Instead of capture any cookie, Axis2 looks for some internal cookie named <tt>axis_session</tt>. I suppose that this is the name of the cookie that Axis2 may set on the server side. I was more horrified to see some WS-Addressing related code for session management. I have not spent enough time to make it work, but I came across some code using WS-Addressing for session management in Axis2. This is also confirmed by this article <a href="http://www.developer.com/java/web/article.php/3620661">Axis2 Session Management</a>. </p>
<p>There are few more stories about feature incompatibility. See <a href="http://www.mail-archive.com/axis-dev@ws.apache.org/msg25197.html">[axis2] a little frustrated</a> for example. (Thanks to my colleague Nate Lipke for forwarding this link.)</p>
<p>One last comment about Axis2. Right now, it does not implement JAX-WS and related specs, making it even harder for JEE fans to consider using Axis2. I wonder why Axis user community (including some corporations who built their products on top of Axis) did not speak up against the rewrite idea. Oh well &#8211; repeating a success story is such a bad idea.</p>
<p>P.S.: Just to spice your reading experience up a bit, also check out <a href="http://wanderingbarque.com/nonintersecting/2006/11/15/the-s-stands-for-simple/">The S stands for Simple</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2006/12/axis2-and-the-let-us-repeat-success-strategy/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Service API Design &#8211; Context vs State</title>
		<link>http://www.subbu.org/blog/2006/12/service-api-design-context-vs-state</link>
		<comments>http://www.subbu.org/blog/2006/12/service-api-design-context-vs-state#comments</comments>
		<pubDate>Sun, 24 Dec 2006 20:45:26 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[soa]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2006/12/service-api-design-context-vs-state/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p></p><p>Carlos Perez at <a href="http://www.manageability.org">manageability.org</a> posted an interesting discussion on <a href="http://www.manageability.org/blog/stuff/object-oriented-interaction-harmful">OO-styled interactions</a>, and I can&#8217;t agree more.</p>
<p>It is very common to find most people listing <em>stateless</em>ness as one of the key principles of service API design. Statelessness is an overloaded term. To my experience, when someone says that a service is stateful, he/she usually means that the service <em>maintains</em> some internal state. We can argue all day long on whether maintaing state is good or bad &#8211; the answer usually depends on what the service is doing. In most cases, whether a service needs to maintain state or not is a service implementation choice &#8211; service users do not need to know or care about it.</p>
<p><span id="more-82"></span></p>
<p>From the client&#8217;s point of view, statefulness of a service usually implies that interactions with the service need to happen in some sequence to be meaningful, i.e. the client maintains some context with the service it is interacting with. Context is what a client should care about &#8211; not about whether the service is stateful or stateless.</p>
<p>Shared context makes service invocation interesting and meaningful. The service needs to define the context which may then be updated by the service or the client, and may even include references to any internal state maintained by the service itself. Services that don&#8217;t require any client-managed context are usually general-purpose utility services. Most usuful services need to depend on some share context to be useful. Context is what makes it possible to break a task into sub-tasks and let the client invoke sub-tasks in some defined sequence.</p>
<p>Some designers may prefer combining shared context with the inputs and outputs of service invocations. IMO, keeping the context separate from the data being processed and returned makes the service interface definition lot more cleaner, easier to understand, and extend. One problem with most programming models used for implementing services is that they don&#8217;t provide for shared context.  For instance, take stateful EJBs. They are becoming extinct (rightly so) because they emphasize on the stateful nature and not on the shared context. With stateful EJBs, sharing the context meant that the client held onto the bean till the work is done. That is not the same as the shared context. Unfortunately, later layers like Java web services extended the same notion, and don&#8217;t provide for shared context within the supported programming models. You can easily bind a web service implementation to a class or a EJB, but you need to invent your own mechanisms for supporting shared context. Then there is the <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=ws-caf">Web Servces Composite Application Framework</a>, but I don&#8217;t think that is what service developers really want to worry about.</p>
<p>This also reminds me of <a href="http://www.w3.org/2001/03/WSWS-popa/paper29">The Need for Shared Context</a> by Anne Thomas Manes, which argued for the need for defining a shared context.</p>
<p>Another harmful aspect OO-styled interactions that Carlos did not mention is idempotency. One of the problems with object-oriented  development is that it is difficult to tell whether a given service invocation is idempotent or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2006/12/service-api-design-context-vs-state/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAX-WS for RESTful Web Services?</title>
		<link>http://www.subbu.org/blog/2006/08/jax-ws-for-restful-web-services</link>
		<comments>http://www.subbu.org/blog/2006/08/jax-ws-for-restful-web-services#comments</comments>
		<pubDate>Thu, 31 Aug 2006 09:04:37 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2006/08/jax-ws-for-restful-web-services/</guid>
		<description><![CDATA[This post is in response to Sameer Tyagi&#8217;s article on using JAX-WS for RESTful web services posted at the Sun Developer Network.  I find a few points stated in this article troubling if not inaccurate &#8211; (a) it presents REST in a limited scope thereby showing SOAP in better light, and (b) it misses [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This post is in response to <a href="http://blogs.sun.com/sameert">Sameer Tyagi</a>&#8217;s article on using <a href="http://java.sun.com/developer/technicalArticles/WebServices/restful/">JAX-WS for RESTful web services</a> posted at the <a href="http://java.sun.com/developer/">Sun Developer Network</a>.  I find a few points stated in this article troubling if not inaccurate &#8211; (a) it presents REST in a limited scope thereby showing SOAP in better light, and (b) it misses some key differences between REST and SOAP based web services. Beyond this, the example cited in this article just shows why you SHOULD NOT use JAX-WS for REST style web services. In this post, I would like to discuss the whys behind the two statements I just made.</p>
<p><span id="more-77"></span></p>
<p>Let me first list each point mentioned about when to use REST and when to use SOAP, and comment on each. The statements in italics below are from this article.</p>
<ol>
<li>
<p>Use REST when <em>the web services are completely statelesss</em>.</p>
<p>This article contents that REST is suited for stateless services. To the contrary, most people prefer keeping SOAP style web services stateless. I also find it easier to manage state over REST based services than SOAP based services. With REST based services, you can either manage state with cookies or with the state encoded in the URI. With SOAP based services, the only option is to encode the state within the envelope.
</li>
<li>Use REST when <em>bandwidth is particularly important and needs to be limited</em>.</p>
<p>REST based web services may be less-bloated. That may or may not turn into better performance &#8211; it depends on the network and the latency.</p>
</li>
<li>Use REST for <em>web service delivery or aggregation into existing web sites</em> &#8230; using technologies such as <em>Asynchronous JavaScript with XML (AJAX)</em>.
<p>This point is a stretch for two reasons. It is equally possible to invoke SOAP style services via XMLHttpRequest. There are pros and cons to each approach. Secondly, I would not use JAX-WS for driving Ajax responses as using <a href="http://www.subbu.org/weblogs/main/2006/08/json_vs_xml_1.html">JSON over XML</a> has several advantages and JAX-WS is not meant for anything other than XML.</p>
<li>
<p>Use REST when <em>the service producer and service consumer have a mutual understanding of the context and content being passed along</em> and use SOAP when <em>a format contract mus be established to describe the interface that the web service offers</em>.</p>
<p>Both the statements are misleading. I think these statements are based on the assumption that WSDL and schemas provide such a contract for SOAP based web services. This is only half-true. WSDL and schemas can describe the structure of messages (data, headers, faults etc.), but you still need to describe the <a href="http://www.subbu.org/weblogs/main/2005/10/xml_and_semanti_1.html">semantics</a> of operations and messages outside the WSDL. Without a description of those semantics, it is not difficult for different people to come up with different interpretations. WSDL and schemas don&#8217;t describe the semantic meaning. </p>
<li>
<p>Use SOAP when <em>The architecture must address complex nonfunctional requirements</em> such as <em>Transactions, Security,<br />
Addressing, Trust, Coordination, and so on</em> that <em>go beyond simple CRUD operations</em> possible with REST.
<p>This article contends that real enterprise applications need more than the CRUD operations that are possible with HTTP. Actually, this article starts by saying how HTTP is related to SQL for CRUD capabilities. This is nothing but a mis-interpreation of HTTP. HTTP defines some standard verbs with defined semantics. There are two ways you can use HTTP for REST style services &#8211; by encoding the operations in the URI, and/or by defining new verbs. This gives a wide range of possibilities for surfacing services &#8211; definitely not limited to CRUD. In any case, how is this better than encoding the operations in the header/body of a SOAP message and send all messages via POST? </p>
<p>Regarding the non-functional requirements such as <em>Transactions, Security, Addressing, Trust, and Coordination</em>, except for security, we are yet to see any one using the others seriously today. Who said security cannot be addressed with RESTful web services? </p>
</ol>
<p>What this article forgets to mention is that RESTful services don&#8217;t hide the fact that they are operating over HTTP, where as SOAP style services try to hide this and encourage <a href="http://www.subbu.org/weblogs/main/2006/08/protocol_agnost_1.html">protocol agnosticism</a>. The result of this protocol agnosticism is API bloat with too many indirections. I have been developing web services for over three years, and I don&#8217;t have problems with the lower level APIs (SAAJ, DOM etc.) &#8211; what frustrates me is the bloat added by the higher-level APIs (dispatchers, handlers, XML binding etc.) trying to hide the protocol. </p>
<h3>JAX-WS for RESTful Services?</h3>
<p>JAX-WS (like its dead-cousin JAX-RPC) is designed with protocol abstraction in mind &#8211; so they carry the bloat I just mentioned. The API goes on to great trouble in hiding the protocol with layer upon layer &#8211; may be the thought was if there are too many layers on top of the protocol, nobody would notice the protocol?</p>
<p>Yes, you can use JAX-WS for REST style services, but as I show below, using JAX-WS makes your code inherit some of that bloat. It adds more complexity without necessarily offering any advantages. Note that the example in this article uses JAXB in combination with JAX-WS, and my comments are limited to using JAX-WS.</p>
<p>First, let me briefly describe the example provided in this article. </p>
<ol>
<li>A purchase order service to get, create, update, or delete purchase orders. This service is implemented using the<br />
<a href="http://java.sun.com/javaee/5/docs/api/javax/xml/ws/Provider.html"><code>javax.xml.ws.Provider</code></a> interface<br />
and some annotations of JAX-WS. The <code>invoke()</code> of this class method processes the request by first checking the request<br />
verb and the path of the URI used to make the request.</li>
<li>A client that uses the <a href="http://java.sun.com/javaee/5/docs/api/javax/xml/ws/Service.html"><code>javax.xml.ws.Service</code></a><br />
and <a href="http://java.sun.com/javaee/5/docs/api/javax/xml/ws/Dispatch.html"><code>javax.xml.ws.Dispatch</code></a><br />
interfaces of JAX-WS to 	talk to the purchase order service. </li>
</ol>
<p>This example is simple, yet demonstrates the bloat very well. Let&#8217;s see the bloat.</p>
<ol>
<li>
<p>The servlet API is best suited for providing an entry point for REST-style services. The API has the right abstractions for serving services over HTTP. But since JAX-WS wants to stay protocol agnostic, there is no way you can bind JAX-WS provider classes to servlets. But still JAX-WS leaks some protocol details via the <a href="http://java.sun.com/javaee/5/docs/api/javax/xml/ws/handler/MessageContext.html"><code>javax.xml.ws.handler.MessageContext</code></a><br />
(which IMO, makes <a href="http://www.subbu.org/weblogs/main/2006/04/angle_brackets.html">JAX-WS more usable than JAXRPC</a>). So, this example ends up using the leaks to get details of the request API. </p>
<pre class="brush: java">
public Source invoke(Source source) {
try{
MessageContext mc = wsContext.getMessageContext();
String path = (String)mc.get(MessageContext.PATH_INFO);
String method = (String)mc.get(MessageContext.HTTP_REQUEST_METHOD);
System.out.println("Got HTTP "+method+" request for "+path);
if (method.equals("GET"))
return get(mc);
if (method.equals("POST"))
return post(source, mc);
if (method.equals("PUT"))
return put(source, mc);
if (method.equals("DELETE"))
return delete(source, mc);
throw new WebServiceException("Unsupported method:" +method);
} catch(JAXBException je) {
throw new WebServiceException(je);
}
}
</pre>
<p>The above code from this article makes a good case why you should servlet API and not JAX-WS. Since this service is bound to HTTP, this code had to obtain the request info directly via the leaked abstractions. Here is how you could rewrite this using the servlet API.</p>
<p><code language="Java"><br />
// Nothing<br />
</code></p>
<p>Except for message parsing, there is no need to write code to detect the verb. The good old <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServlet.html"><code>javax.servlet.http.HttpServlet</code></a> does this job, and would delegate to methods like <code>doGet()</code>, <code>doPost()</code> etc.</p>
</li>
<li>
<p>The purchase order service writes back fault messages and response error codes. Here again, we see the SOAP concepts leaking into the REST-style purchase order service.</p>
<li>
<p>The client side code is similarly more complex like the service implementation. The client first creates a Service, adds a Port, then creates a Dispatcher, creates a RequestContext, and then invokes the service.</p>
<pre class="brush: java">
private  void retrieveOrder() {
service = Service.create(qname);
service.addPort(qname, HTTPBinding.HTTP_BINDING, url + "ABC-123");
Dispatch<Source> dispatcher = service.createDispatch(qname, Source.class, Service.Mode.MESSAGE);
Map<String, Object> requestContext = dispatcher.getRequestContext();
requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "GET");
Source result = dispatcher.invoke(null);
printSource(result);
}
</pre>
<p>There are too many abstractions in this code snippet. It uses APIs designed for SOAP and WSDL to implement REST-style invocations. But why not use <code>HttpURLConnection</code> for the same task?</p>
<pre class="brush: java">
// pseudo code
URL url = new URL(...);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setRequestMethod("GET");
// ...
InputStream is = connection.getInputStream();
// Read and bind to a JAXB object
</pre>
<p>This code is not trivial either, but you are atleast dealing with HTTP directly &#8211; no SOAPy abstractions in the way of doing REST.</p>
</ol>
<p>Due to the fact that JAX-WS hides HTTP, you will also notice that neither the client nor the service can easily deal with things like headers and cookies. This article makes a good point that REST style services can take advatange of HTTP caching, but unfortunately, JAX-WS won&#8217;t let you do it easily.</p>
<h3>My Conclusion</h3>
<p>In summary, this articles makes an attempt to justify that JAX-WS can beused for programming REST-style web services. It should also have<br />
taken the time to justify why you must use JAX-WS as opposed to, let&#8217;s say, servlets and a HTTP client? </p>
<p>If the JAX-WS API is really intent on supporting REST-style programming, here are some the things that it needs to do</p>
<ol>
<li>Provide an easier way to process XML and JSON messages on the server side without hiding HTTP, preferrably by extending the servlet API.</li>
<li>Provide an wasier way to write HTTP client by creating some light-weight abstractions on the top of <code>HttpURLConnection</code> so that writing XML to, and reading XML from HTTP connections is simplified.</lI>
</ol>
<p>As of today, I would not recommend using JAX-WS for REST-style web services.</p>
<p><strong>Update (09/03/2006):</strong> I just came across Mark Baker&#8217;s interview at <a href="http://www.infoq.com/articles/mark-baker-REST">http://www.infoq.com/articles/mark-baker-REST</a>. In response to a question on combining REST with more conventional web services approaches, he says <em>it&#8217;s technically possible, but from what I&#8217;ve seen of Web services toolkits (even those that claim to &#8220;support REST&#8221;), there&#8217;s a very good chance that it&#8217;ll be more trouble than it&#8217;s worth</em>. That says it all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2006/08/jax-ws-for-restful-web-services/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Protocol Agnosticism</title>
		<link>http://www.subbu.org/blog/2006/08/protocol-agnosticism</link>
		<comments>http://www.subbu.org/blog/2006/08/protocol-agnosticism#comments</comments>
		<pubDate>Fri, 04 Aug 2006 14:13:01 +0000</pubDate>
		<dc:creator>Subbu Allamaraju</dc:creator>
				<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://wp.subbu.org/2006/08/protocol-agnosticism/</guid>
		<description><![CDATA[web services protocol abstraction
]]></description>
			<content:encoded><![CDATA[<p></p><p>Will the goal to keep web services protocol agnostic cause web services to<br />
implode? May be so, given that protocol abstraction is making web services<br />
design and deployment more complex than necessary. </p>
<p><span id="more-73"></span></p>
<p>A number of people have already blogged about this issue, see, e.g. David Orchard&#8217;s<br />
<a href="http://www.pacificspirit.com/blog/2005/04/05/underlying_protocol_is_a_completely_leaky_abstraction"><br />
Underlying Protocol is a completely leaky abstraction</a>, or Stefan Tilkov&#8217;s<br />
<a href="http://www.innoq.com/blog/st/2005/01/30/mapping_wsaddressing_to_http.html"> Mapping WS-Addressing to HTTP</a>. Both the posts are quite old, but the  facts remain &#8211; that most SOAP based web services are designed for protocol independence, with no practical justifiable reasons.&nbsp; Web services APIs (e.g. those in the JEE umbrella like JAX-WS) are still designed with this abstraction in mind. As a result, implementations of these APIs as well as applications using these APIs rarely take advantage of the protocol. Consider this recent SOAy article titled <a href="http://www-128.ibm.com/developerworks/java/library/os-ag-soapojo/index.html">SOA framework with Apache Geronimo and POJOs</a>  which states that designing for location and protocol independence is somehow a good thing. This idea seems quite popular still.</p>
<p>At the message design level, the downside of protocol abstraction is message complexity. A lot of details end up being specified in the message payload (e.g. as SOAP headers) when the same data could more efficiently be carried at the protocol level (e.g. as URIs or headers in HTTP). Examples include WS-Addressing, and some aspects of WS-Security token  profiles. Protocol abstraction does not come cheap. It forces some extra processing cycles to create/process messages.</p>
<p>An example closer to my experience is transporting resources over a web service (in WSRP 2.0). Resources are usually arbitrary documents or media that are consumed by user agents. By this very nature, it makes a lot of sense to be able to transport HTTP headers for caching, ranges etc. These headers make it efficient to serve resources to user agents. But since WSRP is a web services protocol, the temptation is to abstract these headers into the message itself. Then the question arises &#8211; what would you call them &#8211; httpHeaders, or transportHeaders or something more abstract (and vague)? It seems silly to have to abstract out these headers into something vague (to keep it independent of HTTP) &#8211; just so that this data<br />
can be carried over diverse protocols like HTTP and SMTP, or even a protocol involving pigeons? Ultimately such attempts at keeping web services protocol agnostic will underutilize the power and flexibility available at the protocol level. This is sad.</p>
<p>Another side effect of this protocol abstraction is the existence of a number of SOAy products for routing, monitoring, SLAs etc. These products may be offering some value, but, IMO, are solving problems at the wrong level, i.e. message level instead of the transport level (e.g. HTTP). Take routing for example. HTTP proxies have been doing routing requests/responses for a number of years, quite efficiently so. I can&#8217;t say the same thing about SOAP proxies that look at the XML, run some rules, and then route each message to an end point &#8211; basically adding a number of processing cycles to already complex web services.</p>
<p>Good for PowerPoint, not for deployment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subbu.org/blog/2006/08/protocol-agnosticism/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
