Bill the Plumber

Plumbing the network

  • Recent Posts

  • c

  • Archives

To WADL or not to WADL

Posted by billburke on May 21, 2009

I edited this to be correct.  I incorrectly assumed that WADL didn’t support HATEOAS.  Apologies Marc Hadley

A friend, colleague, and old mentor of mine, Steve Vinoski (he also introduced me to REST) talks a little bit about his RESTful experiences with his current development team.  It is cool to hear that this stuff is working in action specifically:

For example, I just finished a meeting a couple of hours ago where some client code needs to interact with a particular part of my system via HTTP, but wants XML instead of JSON currently provided.  Simple — it’s just a different representation of the same resources…..[snip] Can you imagine the hoops one would have to jump through with typical RPC-oriented systems [snip]?

He also goes on to talk about how client developers asked for a “REST-like-interface”:

[snip] A document listing all resource URIs, and for each one, the HTTP verbs that apply to it, the representations available from it, and what status codes to expect from invoking operations on it….[snip]for a proper RESTful system, you don’t need a document like that, at least not the type of document they’re asking for.

My guess is that his developers are looking for something a WSDL-like document, or something like WADL. What Steve is getting at is that you don’t need a WADL because HATEOAS allows you to discover how to interact with your services.  In abrowser-based, HTML-based world, this is definately true.  HTML documents are self-describing and renderable by your browser.  Humans can look at a rendered page and now how to interact, serf, and fill and post forms.  Machine-based clients are different though.  They usually exchange more machine-friendly formats like XML and JSON.  They can’t make dynamic decisions and need to know ahead of time what interactions are available and how to perform the interactions.  The de facto way of doing this has been to embed somethign like an Atom link into a document:

<order id="123">
   <amount>$123.45</amount>
   <atom:link rel="CANCEL" href="http://orders.com/orders/123/cancelled"/>
   <atom:link rel="PAYMENT" href="http://orders.com/orders/123/payment" type="application/xml"/>
   ...
</order>

In Atom land, interactions are defined as named, logical, relationships which provide a URI and expected type.  While machine-based clients are not going to be able to make many dynamic decisions on a self-describing document, there are a lot of advantages to HATEOAS that Craig McClanahan talks about.

The thing is, I think Steve’s developers are right.  They need some kind of “RESTful like interface”.  I do agree that you don’t need a document that describes status codes.  The status codes exchanged between a RESTful client and server for a given HTTP operation is well defined by the HTTP specification.  Users should not try to override the meaning of a given status code.  The thing is, even with links, you still need to document which relationships will be available, what they do, and what formats the linked URIs expect.  As a client developer, you need to know this information ahead of time.  For state-changing interactions, you also need to know whether you need to do a PUT or POST.  This is extremely important information because PUT is idempotent and POST is not.  For those URI’s that take query parameters, you will need to define what query parameters there are and what values they expect.  Finally, on error status codes, you will need to know whether or not the server will return a representation that describes the error and what type it will be.

WADL allows you to define all this stuff.  It allows you to define URIs, their media types, what methods they expose, what query parameters,  what, if any representations are returned on failures.  It also allows you to define links and how they relate to other resources.

<resource_type id="vdc">
  <method name="GET">
    <response status="200">
      <representation mediaType="application/vnd.order+xml">
        <parameter name="CANCEL" path="/order/link[@rel='CANCEL']" style="plain">
          <link resource_type="cancel"/>
        </parameter>
        <parameter name="PAYMENT" path="/order/link[@rel='PAYMENT']" style="plain">
          <link resource_type="payment"/>
        </parameter>
      </representation>
    </response>
  </method>
</resource_type>
<resource_type id="cancel">
   <method name="PUT">
      <failure status="400" mediaType="aplication/vnd.error+xml"/>
   </method>
</resource_type>
...

I’ll admit, I am squeamish about WADL.  One of the things I liked about REST is that I wasn’t stuck writing WSDL documents and being dependent on a bloated SOAP stack.  WADL is just as verbose as WSDL.  I like how you can have any link structure you want in your documents and map it using XPath or some JSON equivalent.  Its just so damn verbose!  I still think something like this encourages an RPC-like approach to system design.  So what do we do instead?    Since HATEOAS is so close to the dataformat, awhile back, I talked about using XML schema to define your interface and link relationships.  Subbu also talks about expanding Atom links with a template, which should satisfy the query parameter problem.  I would also suggest adding allow and failure-type attributes to Atom links.  Allow being what HTTP methods are allowed, and failure-type specifying the media type that would be used with any failure responses.  So, here would be an example:

<order id="123">
   <amount>$123.45</amount>
   <atom:link rel="CANCEL" href="http://orders.com/orders/123/cancelled"
                           allow="GET, PUT" failure-type="application/vnd.failures+xml"/>
   <atom:link rel="PAYMENT" href="http://orders.com/orders/123/payment" type="application/xml"
                            allow="GET, PUT" failure-type="text/plain"/>
   ...
</order>

I think this covers the bases.  Thoughts?  Viable?

Posted in REST | 8 Comments »

The Dali Lama is a Pats fan

Posted by billburke on May 4, 2009

Saw this in the Boston Globe today.  The Dali Lama is a pats fan!

patslama

Posted in spam | Leave a Comment »

Oracle and Java

Posted by billburke on April 22, 2009

Let’s face it.  We all knew Sun would get acquired.  The question was just when and by whom.  Now that its happened, and Oracle is the winner, I must say I like the situation better than if IBM had bought them.  Just from a EE specification perspective, IBM was always a bit reactionary when it came to anything new.  On EE 5, Oracle was a staunch ally in our push to get JPA through and a part of EE 5 (and thus retiring CMP and making JDO obsolete).  On EE 6, we’ve met a bit of resistence from them when it comes to the-spec-formally-known-as-Web-Beans, but they’ve been at least open to the idea.  Who knows how the Oracle business guys will want to deal with Java.  That is the wildcard IMO.  Should be fun… Interesting times.

Posted in java, javaee | 5 Comments »

OSGi doesn’t need to be in your face

Posted by billburke on April 2, 2009

Awhile back on TSS, I complained about OSGi possibly bleeding too much into applications.  That OSGi did not belong within application code.  This IBM article is a prime example of my point.  Here we have standard Spring code and XML.  Nowhere in there do you have OSGi APIs.  Yet, you get OSGi classloading and lifecycle.  I bet, that if you can’t already right now, Spring will eventually be able to register IoC references as direct dependencies within an OSGi kernel.  There’s really no reason or advantage to have OSGi APIs bleed into application code.

Another example is JBoss 5.  While not running on top of an OSGi kernel (instead its running on JBoss’s own special kernel) it can manage dependency and lifecycle for a variety of different component models like:  Spring, JBoss MC, EJBs, JCA adapters, Queues, Topics, Servlets, etc.  This can work because JBoss’s kernel provides a deployment abstraction and framework to publish and manage inter-component dependencies.  The end goal here is that all these different component models can take advantage of all this dependency management without writing to specific APIs and to stay within the confines of their own component model’s specification.  The metadata is there.  The dependency information is there.  There’s no reason to write to a specific deployment API to leverage these types of services.

This is what I had hoped OSGi would become.  A standard kernel where classloading, deployment, and dependency management would be provided as low level services so that existing and new component models would have a standard way to mix and match themselves and to deploy themselves.  In theory, such a kernel would allow JBoss’s Transaction Manager to run within a Web Logic server.  JBoss’s EJB container to run within Websphere.  Sun’s WS-* implementation to run within JBoss.

Maybe my concern is not real.  Maybe most OSGi evangelists are not positioning OSGi as an application API.  Let’s hope they aren’t.

Posted in java, jboss, spring | 7 Comments »

REST needs Polymorphic XSD

Posted by billburke on March 31, 2009

I was thinking alot about REST and service versioning again today.  In my previous blog I talked a bit about using the media type and probably XML schema to guarantee a contract between the client and server.  The client would ask for “application/vnd1+xml” and be all set for its conversation to begin.

The big problem I see with this is a service maintenance problem.  As you rev your service and your schema you’re going to have to support a lot of different media types.  What would make things easier is if XML Schema supported polymorphism.  That way a client could ask for “application/vnd1+xml” format and still receive and validate a newer version of the schema.  Please correct me if I’m wrong, but I don’t think you can do this in XML schema.  Yes you could extend various types from the parent to create a newer version of a schema, but a validator would not be able to enforce a polymorphic relationship with its parent AFAIK.

Clients and servers could get around this XSD problem by not doing validation and hoping that the schema developers are disciplined enough to make future versions of the format backward compatible.  It just seems incomplete to me to not be able to validate.

Posted in REST | 3 Comments »

MediaType as Your IDL

Posted by billburke on March 24, 2009

I was reading recently a very excellent article by Subbu about Describing RESTFul Applications.  I highly recommend the article as it very clearly illustrates the RESTful principle of HATEOAS.  One of the profound questions the article asks is does REST need a description language like IDL or WSDL? I guess the main arguments for this would be:

  • Tooling.  Would be nice to be able to generate some client and server code to avoid all the boilerplate nonsense you usually have to do.
  • Define an enforceable contract that can be validated.

There is something called WADL out there, but, as Subbu sort of hints at in his article, such an approach encourages an RPC-like approach for defining interactions with your application.  He goes on to describe what he feels like might be a good definition language while, at the end, asking the question of: Is it Practical? with the biggest roadblock being:

How about software tools that want to test or enforce the contract? It is possible to create such software that reads the above machine-readable description to do the following at runtime.

  • Check that the media types of representations are predefined.
  • Check that the representations match the predefined descriptions of media types.
  • Check that all links contained in representations have predefined relations and media types, and that the URIs included follow predefined URI patterns.

I am not aware of any software that can validate these in this manner.

My answer to this question and roadblock is, why not have your media type define your entire contract?  Require that certain links and relations be a part of your document and define them explicitly in your XSD.  Maybe even the atom link’s media type should be required as well.  Then, simple XML validation can guarantee the contract.  The client application locks in the contract simply by specifying an Accept header containing a custom media type with its initial URI traversal.  We still get a lot of decoupling because the endpoint URIs are discovered at runtime yet we have something we can both generate code from and enforce a contract through.  Add in URI Templates to your links and all you’re missing is what HTTP methods are allowed to be invoked.  Using schema to enforce your contract doesn’t have to stop at XML as mappings like BadgerFish and tools like Jettison have shown.

All and all, the more I think about it, the more I believe that Human Documentation plus a schema is all that is needed in the RESTful world.  I’m glad that as more people like Subbu think and analyze through the IDL problem there are less and less reasons to have an IDL for REST.

Posted in REST | 1 Comment »

Obama to the rescue

Posted by billburke on February 28, 2009

I listen a lot to talk radio, specifically WEEI Sports radio, and 96.9 FM Talk Radio in the Boston area. Unfortunately, when it comes to politics, all you hear on talk radio is conservative, right wing viewpoints. I do live in Massachusetts, so don’t ask me why all this right wing propaganda pollutes our airwaves. I guess this is because right-wing politics tend to piss a lot of people off and drive up ratings. I don’t know. You got me, a liberal democrat listening to them, so I guess the ploy has worked.

One thing I heard a lot after Obama’s first address to Congress was conservatives attacking Obama’s speech and the stimulus. You hear nitpicks about how Texas is getting a cheerleading museum. Stuff like that. Showing bloat that when compared to the overall size of the stimulus package is pretty insignificant. What I wanted to do within this blog is call attention to a few of the good things that are in the bill.

Last summer I joined our Town’s Finance Committee. The Finance Committee’s job is to review all departmental budgets in town and to submit an overall base budget for the entire town. I couldn’t have picked a more interesting time to join. The economy has stalled town growth which means very little new revenue growth. Massachusetts state revenue is also way down which has put local aid funds in serious jeopardy. The contracts for our Police, Fire, and Teachers are all up for renegotiation. Add to this Massachusetts Proposition 2 1/2 which forbids local communities to raise taxes more that 2.5% without 2/3 of the town voting to support a tax increase. It has turned out to be a very tight budget year.

In a tight budget year, we all know what takes the brunt of any cuts. The school system. Our school is faced with probable cuts in funding to after school programs, children supplies, furniture, and even textbooks. There’s also the very real danger of staff reductions and increased class sizes as well as we’re dangerously close to the 2.5% threshold.

The federal stimulus package couldn’t have come at a better time and is affecting our budget in three possible separate ways

  • Special Education.  Massachusetts law requires kids with special education needs to be supported by the community and integrated with the school.  A special needs kid moving into town can have a huge impact on the schools budget as they cost a lot more than a regular student to educate and support.  For example, in our town, new special ed kids account for 25% of the growth of the schools budget.  During the Bush Administration ‘W’ set up guildelines for special education, promised funding, but never delivered.  It looks like the stimulus is providing the promised funding.  This results in hundreds of thousands of dollars being put into the school system.
  • It is not fully clear yet, but it looks like the stimulus package will help fully fund the shortfall of state education aid.
  • Obama wasn’t lying when he said our schools were crumbling.  Our 40-year old roof started leaking into a 4th grade classroom due to the severe weather we’ve been having this winter.  The kids had to be moved to another area in the building.  There is a high possibility the stimulus will help us fund putting in a badly needed roof.  Our junior high and high school also have new roofing needs that have been put off.

I know the conservatives among you will never ever admit that the stimulus is doing any good, but I hope those of you on the fence at least have had their eyes opened to some of the good.  Too often the media (even the liberal media) focuses too much on the eyebrow-raising parts of politics and never really sheds light on the true reality.  Hopefully this blog has done a little to shed some light on things.

Posted in flame bait | 5 Comments »

RESTEasy 1.0.2.GA Released

Posted by billburke on February 13, 2009

More bugs found by our users. See our release notes on 1.0.2.GA for more details.

Next release will be 1.1-RC1 beginning of March which will introduce client and server side interceptors. Client side “Browser” caching. Server side cache support. GZIP encoding support

Posted in JAX-RS, REST, RESTEasy, Webservices, jboss | Leave a Comment »

RESTEasy 1.0.1.GA released, Minor Bug Fixes

Posted by billburke on January 30, 2009

Users found a few minor bugs with 1.0.GA.  See our release notes on 1.0.1.GA for more details.  Unless there is a critical bug reported, no releases until March.

Posted in JAX-RS, REST, RESTEasy, Webservices | 1 Comment »

Writing RESTFul Java Book

Posted by billburke on January 29, 2009

I’ve contracted with O’Reilly to write a “RESTFul Java” book about REST, Java, and JAX-RS.  Should be out sometime this summer.

Posted in JAX-RS, REST, RESTEasy, Webservices | 13 Comments »