<?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>brettdargan.com &#187; hateoas</title>
	<atom:link href="http://brettdargan.com/blog/tag/hateoas/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettdargan.com/blog</link>
	<description>&#955; Thoughts and rants</description>
	<lastBuildDate>Fri, 28 May 2010 01:35:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>HATEOAS for legacy object models</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/</link>
		<comments>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 15:44:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hateoas]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196</guid>
		<description><![CDATA[One of the best aspects of RESTful orientated services is getting your resources connected, possibly even achieving HATEOAS. Making that jump with with legacy object models or data can be tricky, depending on how intrusive you want to be. There is such a large amount of legacy data in various forms, usually with minimal links/relations [...]]]></description>
			<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>One of the best aspects of RESTful orientated services is getting your resources connected, possibly even achieving HATEOAS. Making that jump with with legacy object models or data can be tricky, depending on how intrusive you want to be.</p>
<p>There is such a large amount of legacy data in various forms, usually with minimal links/relations that could be leveraged.</p>
<p>So it is a worthy challenge to try and do it in the least intrusive manner possible.</p>
<p>This is one approach that is reasonably decoupled from an existing legacy model.</p>
<p>There are three main parts to this technique:</p>
<ol class="arabic simple">
<li>Enhance your model objects so they have a placeholder/collection so you can accumulate links</li>
<li>Annotate your model at interesting points with <strong>link templates</strong>, around attributes or methods or classes</li>
<li>Use a custom <a class="reference external" href="http://jersey.dev.java.net&quot;">ContainerResponseFilter</a> class of jersey to scan for annotations of interest, then evaluate your link templates (at run time), using the data of your models and any request based information you may require.</li>
</ol>
<p>I chose to enhance my model classes using <a class="reference external" href="http://eclipse.org/aspectj">AspectJ</a> at compile time.</p>
<p><a class="reference external" href="http://brettdargan.com/blog/wp-content/uploads/2009/01/hateoas4legacytar.bz2">Download the source</a></p>
<div class="codeblock"><div class="highlight"><pre>mvn glassfish:run
./curl_test #will hit two urls
</pre></div>
</div><p>and you should see some results, with links like this:</p>
<div class="codeblock"><div class="highlight"><pre><span style="color: #BC7A00">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span> <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span>
        <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Brisbane&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Sydney&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Melbourne&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/AU&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Brisbane<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
        <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
        <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Sydney<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Melbourne<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/cities&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>AU<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Australia<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
</pre></div>
</div><p>All countries Results</p>
<div class="codeblock"><div class="highlight"><pre><span style="color: #BC7A00">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;countries&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/AU&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>AU<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Australia<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/USA&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>USA<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>United States of America<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/countries&gt;</span>
</pre></div>
</div><p>It is very crufty, but does work in the simple cases.
I haven't had a chance to demonstrate all of the features yet.</p>
<p>I'm likely to further flesh out this example as it is interesting in other RESTful related ways.</p>
</div>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/home/?status=HATEOAS+for+legacy+object+models+http%3A%2F%2Ftinyurl.com%2Fcee6ve" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=HATEOAS+for+legacy+object+models+http%3A%2F%2Ftinyurl.com%2Fcee6ve" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

