Bill the Plumber

Plumbing the network

  • My New Book

  • Recent Posts

  • Categories

  • Archives

RESTEasy 1.2.1 Released

Posted by billburke on November 23, 2009

Minor bug fix release.  Also, had to remove one of the referenced maven repositories because it was screwing up the build.

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

“rel” name requirement overloaded

Posted by billburke on November 19, 2009

The Atom link element and the Link header name their links using the “rel” attribute.  There is a requirement in the Atom Syndication Format and Link header RFCs that states that if the relationship is not registered with IANA, that you must use a IRI instead of a simple name.  Maybe I’m misinterpreting things, but it seems that this IRI must point to an actual resource that describes the link relationship.  IMO, this will make using links awkward as REST permeates into the application development space.  Why?  Applications will define new links.  It would be rather silly for each application to register themselves at IANA for every link they define.  So, they are stuck putting in an IRI that may change over time.  Clients that consume resources will be looking for specific relationships to do their processing.  The Link header specification, I think, tries to mitigate this problem by introducing a “title” attribute.  Which, still will be weird, because clients will be looking up “rel” or “title” attributes depending on what link relationships that want to traverse.  Seems very inconsistent to me.

What I wish they had done (or would do) is define a “relref” that is an optional URL to the description of the non-standard link relationship.  That way the rel attribute remains simple and not overloaded.

If I’m misinterpreting things, apologies.  But thats what I seem to read and what I see in examples.

Posted in REST | 2 Comments »

Overview of REST-* Messaging Draft 4

Posted by billburke on November 19, 2009

Just finished draft 4 of REST-* Messaging.  Please check our our discussion group if you want to talk more about it.  Here’s a list of resources and their corresponding relationships for a high level overview.  See the spec for more details.  It relies heavily on Link headers.  The current draft shows a lot of example HTTP request/responses to give you a good idea of what is going on.

Destination

A queue or a topic resource.

Relationships:

  • post-message – link to POST/create a message to a queue or topic.  This can be
  • post-message-once – link to POST/create a message to a queue or topic using the POST-Once-Exactlly (POE) pattern
  • post-batch – POST/create a batch of messages using Atom or Multipart
  • post-batch-once – POST/create a batch using the POE pattern.

Message

Every message posted creates a message resource that can be viewed for adminstration, auditing, monitoring, or usage.

Links Relationships:

  • reply-to.  Destination that you can reply to
  • reply-to-once.  Destination that you can reply to once using the POST-Only-Once pattern
  • reply-to-batch. Destination that you can reply with a batch of messages
  • reply-to-batch-once.  Batch using POE.
  • next.  If pulling from a topic, messages will have this link.  This is the next message after this one.
  • acknowledgement.  If pulling from a queue, this link allows you to change the state of the message to acknowleged or not.
  • generator. Destination that the message came from

Topic

Has the same links as Destination with these added:

Link Relationships:

  • next.  GET the next incoming message.  Clients should use the Accept-Wait header to set a blocking timeout (see later).
  • last.  Last posted message to the topic
  • first.  First message posted to topic, or, the first message that is still around.
  • subscribers. URL that allows you to view (GET) or create/register (POST) a list of URLs to forward messages to.

Queue

Same as Destination, but these additional link relationships:

Link Relationships:

  • poller.  Alias to the next available message in the queue.  Returns a message representation along with a Content-Location header pointing to the real one.  a POST is required to access this because the state of the queue is changed.
  • subscribers.  Same as topic push model.


Posted in REST, REST-star | Leave a Comment »

Etag embedded within a Link

Posted by billburke on November 12, 2009

I wanted to add acknowledgement to the queue consumer pull model in REST-* Messaging.  The way it would work is that consumers do a POST on the queue’s URL.  They receive the message as well as a Link header pointing to an acknowledgement resource.  When the client consumer successfully processes the message, it posts a form parameter, acknowledge=true to the acknowledgement link.

There is a problem with this though.  The design is connectionless to honor the stateless REST principle.  So there is no specific session resource that the client consumer is interacting with.  The consumer may never acknowledge the message, so I need the server to re-enqueue the message and deliver it to a new consumer.  The problem is, what if the old consumer tries to acknowledge after the message is re-enqueued or even after it is redelivered to a different consumer?

I first thought of letting the first consumer to acknowledge win and do something like POST-Once-Exactly (POE).  The problem with this is, what if there’s a network failure and the consumer doesn’t know if the acknowledgement happened or not?  It would redeliver the message and get back a Method Not Allowed response error code.  With this code, the consumer doesn’t know if somebody else acknowledged the message or if the older request just went through.  So, I went with a conditional POST.  The acknowledgement link, when performing a GET on it, would return an ETag header that the consumer must transmit with the acknowledgement POST.  If the message was re-enqueued, then the underlying ETag would change, and the conditional post would fail for the older consumer.

Still this solution is suboptimal because an additional GET request needs to be executed.  It is also subject to a race condition.  What if the message is re-enqueued before the consumer does a GET on the acknowledgement resource?  SO, what I decided to do was embed the etag value with the acknowledgement link.  For example:

1. Consume a message
Request:

POST /myqueue/consumer

Response:

HTTP/1.1 200 OK
Link: </myqueue/messages/111/acknowledgement>; rel=acknowledgement; etag=1
Content-Type: ...

...  body ...

2. Acknowledge the message
Request:

POST /myqueue/messages/111/acknowledgement
If-Match: 1
Content-Type: application/x-www-form-urlencoded

acknowledge=true

Success Response:

HTTP/1.1 204 No Content

Response when it was updated by somebody else.

HTTP/1.1 412 Precondition Failed

POE Redelivery Response.  It was already successfully updated by the consumer.

HTTP/1.1 405 Method Not Allowed

Posted in REST, REST-star | 2 Comments »

No Wait in HTTP

Posted by billburke on November 10, 2009

One thing the HTTP specification does not have is a “Server Timeout” response code.  The 408 and 504 response codes are the only thing that comes close.  The idea of a “Server Timeout” code is that the server received the request, but timed out internally trying to process the request.  Another thing I think that is missing from HTTP is a way for the client to tell the server how long it is willing to wait for a request to be processed.

I’ve run into both of these scenarios with the REST-* Messaging specification when I have pulling client consumers.  For the “Server Timeout” I decided upon 202, Accepted.  It seems to fit as I can tell the client to try again at a specific URL.  As for the client requesting a wait time?  I invented a new request header:  “X-RS-Wait”.  Its value is the time in seconds that the client wants to wait for a request to be processed.  Maybe there is a standard or drafted protocol I missed in my Google search?

Posted in REST, REST-star | 4 Comments »

REST-* Messaging Draft 3

Posted by billburke on November 6, 2009

After prototyping, I’m back to writing another draft. This is a little bit more formal draft. I created a OSS project at:

http://sf.net/projects/rest-star

A draft of the PDF is at:

http://reststar-messaging.googlegroups.com/web/REST-Star-Messaging-draft-3.pdf

(You’ll have to click through an additional link that is *very* long). This draft only talks about the Message Publishing Protocol. I still have to write up the topic and queue push and pull model.  To discuss the draft please post at the REST-* Messaging Group.  I’m also looking for people to help prototype the specification.  Post to the RESTEasy developers list if you’re interested.

Posted in REST, REST-star | Leave a Comment »

RESTEasy 1.2.GA Released

Posted by billburke on November 4, 2009

After a few months RESTEasy 1.2.GA is finally ready.  This is mostly a cleanup, bug fix, and refactoring release, but here are some features of note:

I’d also like to thank Attila Kiraly for fixing some bugs that cropped up in Multipart and XOP support.  Pascal de Kloe, a new committer, also helped refactor content negotiation to support charset variants.  Solomon Duskis continues to be a seasoned veteran and helps with bugs and features here and there.

What’s next?  I’d like to focus next on getting complete OAuth support in.  I think it will help out our REST-* efforts as we look to secure the services we’re defining there.  RESTEasy is also going to expand beyond a simple JAX-RS implementation.  As JBoss projects like HornetQ, jBPM, Drools, Transactions, and Infinispan obtain RESTful interfaces, I’ll be creating a REST profile under the RESTEasy umbrella.

Useful links:

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

Parsing Link headers with Javascript and Java

Posted by billburke on October 15, 2009

I wrote a Link header parser in Javascript. Thanks Mark Nottingham for sending me a link to his python equivalent.

var linkexp=/<[^>]*>\s*(\s*;\s*[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*")))*(,|$)/g;
var paramexp=/[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*"))/g;

function unquote(value)
{
    if (value.charAt(0) == '"' && value.charAt(value.length - 1) == '"') return value.substring(1, value.length - 1);
    return value;
}

function parseLinkHeader(value)
{
   var matches = value.match(linkexp);
   var rels = new Object();
   var titles = new Object();
   for (i = 0; i < matches.length; i++)
   {
      var split = matches[i].split('>');
      var href = split[0].substring(1);
      var ps = split[1];
      var link = new Object();
      link.href = href;
      var s = ps.match(paramexp);
      for (j = 0; j < s.length; j++)
      {
         var p = s[j];
         var paramsplit = p.split('=');
         var name = paramsplit[0];
         link[name] = unquote(paramsplit[1]);
      }

      if (link.rel != undefined)
      {
         rels[link.rel] = link;
      }
      if (link.title != undefined)
      {
         titles[link.title] = link;
      }
   }
   var linkheader = new Object();
   linkheader.rels = rels;
   linkheader.titles = titles;
   return linkheader;
}

I had written a non-regular-expression, hand-coded parser in Java for RESTEasy. Thought it might be faster than regexp. That could probably be ported to Javascript too.

Posted in REST, java | Leave a Comment »

Link headers vs. Custom headers

Posted by billburke on October 14, 2009

There’s a really nice RFC out that defines the concept of a Link header.  Link headers are like Atom links within documents except they are specified within request or response headers.  For example let’s say we wanted to GET a medical image of an MRI.  This image might have additional relationships to a front, back, top, bottom up view.  A response with link headers might look like this:

HTTP/1.1 200, OK
Content-Type: image/jpeg
Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"

...

The jpeg format cannot embed hyperlinks within it so to obtain relationship information, the Link header is used.  Other than data formats that don’t support hyperlinks, using the Link header can also be very valuable to intermediaries that don’t care or want to know about the content being exchanged.

Link headers vs. Custom headers

I really like the logical concept of Link headers.  The syntax of the header is also solid and fine.  The problem I have with it though is that it is non-trivial to parse.    Please, please, correct me if I’m wrong, but parsing a Link header, according to the current version of the spec, isn’t as easy as doing a few string.splits or simple regular expressions.  This is because ‘;=,’ characters can be embedded within quotes.  The ‘;’ can also be embedded within links and media types.  Not only this, but to get at a specific link I have to parse all the links defined within the header and create a map, before I can define a specific link.

Granted, its not hard to write a parser for this.  It is a micro format.  The problem is that HTTP libraries generally do not have native support for this.  Not a very big deal, but IMO, one of the big selling point of REST is its low footprint and the ability to leverage existing libraries to make HTTP invocations.  I came across this problem when writing a Javascript client.

This made me think about redefining the problem.  Instead, isn’t a Custom HTTP header easier to interact with from an API point-of-view?  Do clients and servers really need the media type information (or really any other metadata) about the link?  Could we instead have a simple custom header?

HTTP/1.1 200, OK
Front-link: http/.../front.jpg
Back-link: http://.../back.jpg
Content-Type: image/jpeg

...

Then its just a matter of hash lookup using existing HTTP library facilities.

The downside of course to all of this is that you lose all the self-description aspects that are provided by Link headers.  Specifically the media type (type attribute) as well as IETF registered links vs. custom link relationships referenced via a URL.  IMO, this self-description metadata within Link headers also helps to mitigate against namespace clashes where different domains might define the same header names.

Header Templates?

What if the Link header spec defined a template for header names?  like Link-{rel}, Link-{rel}-Type, Link-{rel}-Title, etc…  Link-{rel}-{attribute}  So, my response might look like this instead:

Link-Front: http:/.../frong.jpg
Link-Front-Type: image/jpeg
Link-Back: http:/.../back.jpeg
Link-Back-Type: image/jpeg

To find links published by a resource is just a matter of iterating through and doing a “startsWith(‘Link’)” on the header.

Posted in REST | 7 Comments »

Announcing a new distributed computing paradigm: ULSER

Posted by billburke on October 7, 2009

I’m pleased to announce a new distributed effort named ULSER.  ULSER stands for a set of uncompromisable architectural principles, specifically:

  • Uniform constrained interface.
  • Links as the engine of application state
  • Statelessness for scalability
  • Enterprise applicable
  • Resource and representation oriented

Why call it ULSER?  Well, even though these architectural principles are extremely useful to design distributed applications (and middleware), I’ve found that discussing any of these  principles publicly have given me (and others) an ulcer.   So, I thought I’d make these principles my own and let others share the pain.  I’m also going to create a set of standards called ULSER-*.  ULSER-*.org will focus on bringing ULSER principles to middleware technology.  Since middleware generally produces ulcers in engineers I think the name is perfect!  I’ve also created an open source Java project called EasyULSER so that you can let Java give you an ulcer too!

Also, don’t worry, I’ve deliberated with the doctor who discovered ulcers and coined the term “ulcer”.  He didn’t mind me using the term as long as what I’m doing will cause me an ulcer.  The ulcer community didn’t seem to mind either as when I tried to explain to them the principles of ULSER and how I’m using them, it gave them an ulcer too, so they were happy.  So, it looks like we’re ready to go!  ONWARD!

Posted in flame bait, sarcasm, satire, spam | 8 Comments »