<?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>wwerner&#039;s blog</title>
	<atom:link href="http://blog.wolfgang-werner.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.wolfgang-werner.net</link>
	<description>tutorials, tips and trivia on eclipse, osgi, web &#38; xml technologies</description>
	<lastBuildDate>Tue, 10 Jan 2012 14:11:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rumors of my demise have been greatly exaggerated</title>
		<link>http://blog.wolfgang-werner.net/rumors-of-my-demise-have-been-greatly-exaggerated/</link>
		<comments>http://blog.wolfgang-werner.net/rumors-of-my-demise-have-been-greatly-exaggerated/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 14:11:44 +0000</pubDate>
		<dc:creator>Wolfgang Werner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.wolfgang-werner.net/?p=651</guid>
		<description><![CDATA[While I did not post anything here during the last year (was a pretty short year, anyway :-/), I actually did do some writing: (German) A piece on the Equinox OSGi Console, basically the same as in an earlier post here. Published in eclipse Magazin 2.11. HTML, PDF (German) Devising an RESTful architecture based on [...]]]></description>
			<content:encoded><![CDATA[While I did not post anything here during the last year (was a pretty short year, anyway :-/), I actually did do some writing:<br />
<ul>
	<li>(German) A piece on the Equinox <span class="caps">OSG</span>i Console, basically the same as in an <a href="http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/">earlier post here</a>. Published in eclipse Magazin 2.11. <a href="http://it-republik.de/jaxenter/artikel/Von-alten-Konsolen-Affen-und-seltsamen-Schleifen-4093.html" target="_blank"><span class="caps">HTML</span></a>, <a href="http://www.bridging-it.de/fileadmin/img/news/06.2011_eclipse_Magazin_Strom_allein_ist_nicht_genug.pdf" target="_blank"><span class="caps">PDF</span></a></li>
	<li>(German) Devising an <span class="caps">REST</span>ful architecture based on <span class="caps">OSG</span>i &amp; Restlet using e-mobility charging station software as business case. Published in eclipse Magazin 6.11. <a href="http://it-republik.de/jaxenter/artikel/Zukunftssicher-unterwegs-mit-OSGi-und-REST-4150.html" target="_blank"><span class="caps">HTML</span></a>, <a href="http://www.bridging-it.de/fileadmin/img/news/06.2011_eclipse_Magazin_Strom_allein_ist_nicht_genug.pdf" target="_blank"><span class="caps">PDF</span></a></li>
	<li>A review on <a href="http://www.dzone.com/reviews/postgis-action" target="_blank">PostGIS in Action on dzone</a>.</li>
</ul>

<p>&lt;INSERT 2012 <span class="caps">WRITE</span>-MORE <span class="caps">RESOLUTION HERE</span>&gt;</p>]]></content:encoded>
			<wfw:commentRss>http://blog.wolfgang-werner.net/rumors-of-my-demise-have-been-greatly-exaggerated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful HTTP with JAX-RS</title>
		<link>http://blog.wolfgang-werner.net/restful-http-with-jax-rs/</link>
		<comments>http://blog.wolfgang-werner.net/restful-http-with-jax-rs/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 22:32:22 +0000</pubDate>
		<dc:creator>Wolfgang Werner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[jaxrs]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://blog.wolfgang-werner.net/?p=576</guid>
		<description><![CDATA[In this post, we'll look into creating a RESTful HTTP interface using JAX-RS. We'll see that it is pretty easy to expose ordinary java methods through HTTP.

We'll create a trivial model of a movie database and expose it via RESTful HTTP services as JSON and XML using JAX-RS, a little JAXB, Apache CXF, maven and Spring. We'll see that we need very little code to achieve that. This post focuses on the service front-end, the data is not persisted. We'll add JPA based persistence in a later post.]]></description>
			<content:encoded><![CDATA[<div class='toc wptoc'>
<h2>Contents</h2>
<ol class='toc-odd level-1'>
	<li>
		<a href="#Preparation">Preparation</a>
	</li>
	<li>
		<a href="#The_Model">The Model</a>
	</li>
	<li>
		<a href="#First_Service">First Service</a>
	</li>
	<li>
		<a href="#Wiring_it_up">Wiring it up</a>
	</li>
	<li>
		<a href="#Application">Application</a>
	</li>
	<li>
		<a href="#Take_it_for_a_test_drive">Take it for a test drive</a>
	</li>
	<li>
		<a href="#Some_data">Some data</a>
	</li>
	<li>
		<a href="#More_Services">More Services</a>
	</li>
	<li>
		<a href="#Reading_is_always_easy...">Reading is always easy...</a>
	</li>
	<li>
		<a href="#I_rest_my_case"><span style="font-weight: normal;">I rest my case</span></a>
	</li>
</ol>
</ol>
</div>
<br />
<span id="Preparation"><h2>Preparation</h2></span>
To follow along, you&#8217;ll need a <span class="caps">JDK</span> 1.6, &Acirc;&nbsp;Eclipse Helios <span class="caps">JEE </span>and Maven. M2eclipse won&#8217;t hurt. To get started, grab the <span class="caps">POM </span>file from <a href="https://github.com/wwerner/JAXRSTutorial/raw/master/pom.xml">https://github.com/wwerner/JAXRSTutorial/raw/master/pom.xml</a>.

<p>The complete source code is available on <a href="https://github.com/wwerner/JAXRSTutorial/" target="_blank">github</a>. There is one branch for each step so you can easily switch back and forth and compare your state with the expected one.</p>

<p>The <span class="caps">POM </span>defines a number of dependencies.&Acirc;&nbsp;The most notable ones are&Acirc;&nbsp;CXF <sup class='footnote'><a href='#fn-576-1' id='fnref-576-1' onclick='return fdfootnote_show(576)'>1</a></sup>,&Acirc;&nbsp;Jackson <sup class='footnote'><a href='#fn-576-2' id='fnref-576-2' onclick='return fdfootnote_show(576)'>2</a></sup> and&Acirc;&nbsp;Spring <sup class='footnote'><a href='#fn-576-3' id='fnref-576-3' onclick='return fdfootnote_show(576)'>3</a></sup>.</p>

<p>Run the following commands on the shell.</p>

<p>This will create the eclipse project we&#8217;ll be working on. I put in a little hack using the antrun plugin to create the source folders that would have been there if we started from an archetype. I&#8217;m pretty sure there is a better way to do this, please leave a pointer if you know.</p>

<p><span class="caps">CXF </span>comes with quite a load of dependencies of it&#8217;s own, so you might want to get a coffee<sup class='footnote'><a href='#fn-576-4' id='fnref-576-4' onclick='return fdfootnote_show(576)'>4</a></sup> while maven downloads the internets.</p>

<script src="http://gist.github.com/661747.js"></script>

<p>After mvn finished, you should have the same file structure as in this branch: <a href="https://github.com/wwerner/JAXRSTutorial/tree/stage2">https://github.com/wwerner/JAXRSTutorial/tree/stage2</a></p>

<p>Import the created project into your workspace using&Acirc;&nbsp;Import-&gt;Existing Projects. The project should look like this in the project explorer view:</p>

<img class="alignnone size-full wp-image-598" title="stage2_workspace" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage2_workspace.png" alt="" width="255" height="167" />
<span id="The_Model"><h2>The Model</h2></span>
For our movie database, we&#8217;ll only have two model classes: Actor and Movie. A movie consists of a title and the cast which maps the movie&#8217;s roles to Actors. The poor Actor can only afford one property: his name.

<p>We&#8217;ll put all of this in a new package in our project: net.wolfgangwerner.tutorial.jaxrs.model in src/main/java.</p>

<script src="http://gist.github.com/662446.js"></script>

<script src="http://gist.github.com/662451.js"></script>

See <a href="https://github.com/wwerner/JAXRSTutorial/tree/stage3" target="_blank">https://github.com/wwerner/JAXRSTutorial/tree/stage3</a>.<br />
<span id="First_Service"><h2>First Service</h2></span>
Now, what do we do to expose our model using <span class="caps">HTTP</span>? Let&#8217;s start with a trivial &#8216;Hello World&#8217; service to outline the concepts. &Acirc;&nbsp;We start with a new package called net.wolfgangwerner.tutorial.jaxrs.service and add a class called MovieService.

<script src="http://gist.github.com/662598.js"></script>

<p>Now, the only thing we have to do to expose this method is to add some <span class="caps">JAX</span>-RS annotations, @GET, which tells the runtime that this method should be called on <span class="caps">GET </span>requests and @Path which defines the <span class="caps">URI </span>(template) for which this method should be called. Additionally, we&#8217;ll add @Produces to make explicit which content type we are returning.</p>

<script src="http://gist.github.com/76a2d65ec11dd6feb29e.js"></script>

See&Acirc;&nbsp;<a href="https://github.com/wwerner/JAXRSTutorial/tree/stage4">https://github.com/wwerner/JAXRSTutorial/tree/stage4</a>.<br />
<span id="Wiring_it_up"><h2>Wiring it up</h2></span>
We could now configure the <span class="caps">JAX</span>-RS servlet<sup class='footnote'><a href='#fn-576-5' id='fnref-576-5' onclick='return fdfootnote_show(576)'>5</a></sup> and deploy it into a servlet container. In this case, we also need to make sure that we have a <span class="caps">JAX</span>-RS implementation in the classpath.

<p>Anyway, I&#8217;d like to do it a little different<sup class='footnote'><a href='#fn-576-6' id='fnref-576-6' onclick='return fdfootnote_show(576)'>6</a></sup>: We&#8217;ll use Spring IoC with the <span class="caps">JAX</span>-RS configuration namespace provided by <span class="caps">CXF </span>to define an <span class="caps">HTTP </span>server and publish our resource.</p>

<p>Create the file application-context.xml for Spring in src/main/resources and put in the following content.</p>

<script src="http://gist.github.com/674677.js"></script>

<p>Now what&#8217;s in there? First interesting thing is the declaration of the jaxrs namespace from <span class="caps">CXF</span>: xmlns:jaxrs=&#8221;http://cxf.apache.org/jaxrs. Then we define two beans, one for our service class and one for the jackson provider that will be used to render <span class="caps">JSON </span>representations.</p>

<p>The next part configures an <span class="caps">HTTP </span>server (CXF comes with jetty<sup class='footnote'><a href='#fn-576-7' id='fnref-576-7' onclick='return fdfootnote_show(576)'>7</a></sup>) to run on localhost port 9001. We tell the runtime to look for services in the service bean we defined earlier and we register the jackson <span class="caps">JSON </span>provider with this server.</p>

See<a href=" https://github.com/wwerner/JAXRSTutorial/tree/stage5" target="_blank"> https://github.com/wwerner/JAXRSTutorial/tree/stage5</a>.<br />
<span id="Application"><h2>Application</h2></span>
Next thing is to have an application we can start. For this tutorial, we do not run inside a web container but standalone. We&#8217;ll configure a server later on via spring, for now we just need something to start our application context.

<script src="http://gist.github.com/662585.js"></script>

<p>The application does nothing more than to look for a spring xml configuration file on the classpath and to start the configured context.</p>

See <a href="https://github.com/wwerner/JAXRSTutorial/tree/stage6" target="_blank">https://github.com/wwerner/JAXRSTutorial/tree/stage6</a>.<br />
<span id="Take_it_for_a_test_drive"><h2>Take it for a test drive</h2></span>
Your workspace should now look like this:

<p><img class="alignnone size-full wp-image-602" title="stage6_workspace" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage6_workspace.png" alt="" width="316" height="311" /></p>

<p>Select the Application class and choose Run as.. -&gt; Java Application<sup class='footnote'><a href='#fn-576-8' id='fnref-576-8' onclick='return fdfootnote_show(576)'>8</a></sup></p>

<p>The console output should tell you that spring wired the dependencies, jetty started and is listensing on port 9001 as you told it to in the application context.</p>

<p><img class="alignnone size-full wp-image-604" title="stage6_start" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage6_start.png" alt="" width="742" height="231" /></p>

<p>If &Acirc;&nbsp;you followed my earlier tutorials, you&#8217;ll know Poster<sup class='footnote'><a href='#fn-576-9' id='fnref-576-9' onclick='return fdfootnote_show(576)'>9</a></sup>, a firefox addon to make <span class="caps">HTTP </span>requests. If you don&#8217;t have it, get it or &Acirc;&nbsp;use the <span class="caps">HTTP </span>speaking tool of your choice instead <sup class='footnote'><a href='#fn-576-10' id='fnref-576-10' onclick='return fdfootnote_show(576)'>10</a></sup>.</p>

<p>Use Poster to <span class="caps">GET </span>http://localhost:9001/hello . Remember we defined the server port in application-context.xml and path via the @Path annotation in MovieService.</p>

<p><img class="alignnone size-full wp-image-606" title="stage6_poster" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage6_poster.png" alt="" width="565" height="362" /></p>

<p>Let&#8217;s try another thing: We can ask our service which kinds of interaction it supports using the <span class="caps">OPTIONS HTTP </span>verb<sup class='footnote'><a href='#fn-576-11' id='fnref-576-11' onclick='return fdfootnote_show(576)'>11</a></sup>.</p>

<p>This tells us that we can execute <span class="caps">GET, HEAD </span>and <span class="caps">OPTIONS </span>requests on our /hello <span class="caps">URL</span>:</p>

<p><img class="alignnone size-full wp-image-607" title="stage6_options" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage6_options.png" alt="" width="551" height="533" /></p>

<p>This is what it would look like with cURL:</p>

<p>R<script src="http://gist.github.com/675316.js"></script></p>

That was pretty easy. Boring, too. Let&#8217;s see how we can map actual object hierarchies to different formats and write data back to our application.<br />
<span id="Some_data"><h2>Some data</h2></span>
Before we add some more interesting services, let&#8217;s create some test data we can retrieve first. We&#8217;ll simply do so in the constructor of our service. In a later post, we&#8217;ll factor out a data store component that uses <span class="caps">JPA </span>for persistance. Stay tuned.]

<p>First we create a couple of actors, then we associate them with the movie using the cast map.</p>

<script src="http://gist.github.com/675617.js"></script>

<a href="https://github.com/wwerner/JAXRSTutorial/tree/stage7" target="_blank">https://github.com/wwerner/JAXRSTutorial/tree/stage7</a><br />
<span id="More_Services"><h2>More Services</h2></span>
Lets create a service that returns a movie by it&#8217;s id and can provide the result in <span class="caps">JSON </span>and <span class="caps">XML </span>format. The good message is that we don&#8217;t have to worry about marshalling and unmarshalling of our business objects. We can simply return Movie from our service method. Let&#8217;s give it a try and see what happens. Add the following method to our service class and call it using Poster/cURL/whatever.

<script src="http://gist.github.com/675623.js"></script>

<p>Note that we added an <span class="caps">URL </span>parameter {id} to the @Path annotation. We also added the @PathParam annotation to the id parameter in our method<sup class='footnote'><a href='#fn-576-12' id='fnref-576-12' onclick='return fdfootnote_show(576)'>12</a></sup>.</p>

<p>That&#8217;s the result<sup class='footnote'><a href='#fn-576-13' id='fnref-576-13' onclick='return fdfootnote_show(576)'>13</a></sup>: <script src="http://gist.github.com/675627.js"></script></p>

<p>We got <span class="caps">JSON, </span>as this is the first type defined in our @Produces annotation and the client did not send any preferences. Let&#8217;s add a request header that says &#8216;I&#8217;d rather take <span class="caps">XML&#8217;</span><sup class='footnote'><a href='#fn-576-14' id='fnref-576-14' onclick='return fdfootnote_show(576)'>14</a></sup>.</p>

<p><img class="alignnone size-full wp-image-610" title="stage7_xmlrequest" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage7_xmlrequest.png" alt="" width="564" height="379" /></p>

<p>This returns &#8230; &#8230; &#8230; an error? Correct. A kind of cryptic one as well:</p>


<pre>No message body writer has been found for response class Movie.</pre>


<p>This means that the jax-rs runtime did not find anything to serialize our Movie. Jackson, the <span class="caps">JSON </span>processor is kinda smart, it just uses reflection to render <span class="caps">JSON.</span> But for <span class="caps">XML, </span>we need to Do Stuff&#8482;. How do we get that body writer? We don&#8217;t need to. We can just use <span class="caps">JAXB </span>annotations in our model to link our data to an <span class="caps">XML </span>representation. The first thing to do is to add the @XmlRootElement annotation on both our model classes.</p>

<script src="http://gist.github.com/675638.js"></script>

<p>If you run this, you might note that the cast may be displayed before the title. That&#8217;s fugly. Add@XmlType(propOrder={&#8220;title&#8221;, &#8220;cast&#8221;}) &Acirc;&nbsp;to the movie class, restart the application and you are good. The nice thing about the <span class="caps">JAXB </span>bindings is that they are also evaluated by jackson. Add the annotation @XmlElement(name=&#8221;who&#8221;) to the getName() method of Actor and see what happens.</p>

<script src="http://gist.github.com/675651.js"></script>

<script src="http://gist.github.com/675657.js"></script>

<p>Note that the &#8220;name&#8221; element changed in both representations.</p>

Now you might argue that the default representations are still fugly. <span class="caps">JAXB </span>provides a nice mechanism to produce arbitrary output: @XmlAdapter. The approach is basically that you create a java class that produces the required <span class="caps">XML </span>output and an adapter that converts your business objects to the representation objects and vice versa. This seems overkill at first, but it is incredibly powerful. <a href="http://twitter.com/bdoughan" target="_blank">@bdoughan</a> wrote a nice <a href="http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html" target="_blank">post</a> on this if you want to dig deeper.<br />
<span id="Reading_is_always_easy8230"><h2>Reading is always easy&#8230;</h2></span>
&#8230; writing back is more interesting. Well, not in this case. It&#8217;s exactly the same. Just swap the @GET for a @POST and @Produces for @Consumes, pass the Movie as parameter, add some logic to save the value and you are done. Ok, we&#8217;re not really persisting stuff, so just storing in memory may not count. We&#8217;ll address persistence via <span class="caps">JPA </span>in a later post.

<p>To see which data we have stored on the server, we&#8217;ll also add a new service that returns all movies. Note that (typed) collections are handled transparently as well.</p>

<p>To make it a little more interesting, we return a useful response that tells us which resource has been created<sup class='footnote'><a href='#fn-576-15' id='fnref-576-15' onclick='return fdfootnote_show(576)'>15</a></sup>.</p>

<script src="http://gist.github.com/675677.js"></script>

<p>Just copy either the <span class="caps">JSON </span>or <span class="caps">XML </span>representation and <span class="caps">POST </span>it to the /movies <span class="caps">URL </span>using a new id. This will create a new movie and return it&#8217;s <span class="caps">URL.</span> You can also <span class="caps">GET </span>/movies to see a complete list of movies available.</p>

<p><img class="alignnone size-full wp-image-626" title="stage8_post" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage8_post.png" alt="" width="565" height="453" /></p>

<p><img class="alignnone size-full wp-image-625" title="stage8_post2" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/stage8_post2.png" alt="" width="510" height="525" /></p>

<script src="http://gist.github.com/675727.js"></script>

<a href="https://github.com/wwerner/JAXRSTutorial/tree/stage8" target="_blank">https://github.com/wwerner/JAXRSTutorial/tree/stage8</a><br />
<span id="I_rest_my_case"><h2><span style="font-weight: normal;">I rest my case</span></h2></span>
<span style="font-weight: normal;">We saw that it is pretty easy to expose simple java methods through <span class="caps">HTTP.</span></span>

<p>Two weeks before writing this post I gave a talk at the company I work with<sup class='footnote'><a href='#fn-576-16' id='fnref-576-16' onclick='return fdfootnote_show(576)'>16</a></sup> about <span class="caps">REST </span>and common <span class="caps">REST </span>misconceptions that also featured a live hacking session with the stuff you just read. Then I thought that I could reuse it for a blog. Then I went to Eclipse Summit Europe<sup class='footnote'><a href='#fn-576-17' id='fnref-576-17' onclick='return fdfootnote_show(576)'>17</a></sup> where <a href="http://twitter.com/doug_clarke" target="_blank">@doug_clarke</a> used <span class="caps">JAX</span>-RS in his <a href="http://www.eclipsecon.org/summiteurope2010/sessions/?page=sessions&amp;id=1692" target="_blank">talk</a>, then <a href="http://twitter.com/vogella" target="_blank">@vogella</a> published a <a href="http://www.vogella.de/articles/REST/article.html">tutorial </a>on <span class="caps">JAX</span>-RS as well<sup class='footnote'><a href='#fn-576-18' id='fnref-576-18' onclick='return fdfootnote_show(576)'>18</a></sup>.</p>

<p>I like to believe that it is an interesting topic more than I like to believe it is grossly redundant. Feel free to disagree, here&#8217;s my take on it anyway. As a side note, it&#8217;s&Acirc;&nbsp;actually&Acirc;&nbsp;only 89 lines of java code. That is pretty lean, I&#8217;d say. You can get each and every of these lines&Acirc;&nbsp;<a href="https://github.com/wwerner/JAXRSTutorial">here</a>. Awesome, isn&#8217;t it?</p>

<p>Also note that as we speak, a new version of the <a href="https://jsr311.dev.java.net/"><span class="caps">JAX</span>-RS/JSR311</a> specification is proposed <a href="http://markmail.org/message/wgm3hj3rrva3j6jo?q=list:net.java.dev.jsr311.dev">here</a>.</p>

<p>I&#8217;ll follow up on this post with adding <span class="caps">JPA</span>&Acirc;&nbsp;persistence&Acirc;&nbsp;to our movie store. Stay tuned if you are interested.</p>

<p>As bedtime candy, here are some of the slides<sup class='footnote'><a href='#fn-576-19' id='fnref-576-19' onclick='return fdfootnote_show(576)'>19</a></sup> I used in my talk.</p>


<a href='http://blog.wolfgang-werner.net/restful-http-with-jax-rs/1990-2/' title='1990'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/19901-150x150.jpg" class="attachment-thumbnail" alt="1990" title="1990" /></a>
<a href='http://blog.wolfgang-werner.net/restful-http-with-jax-rs/myth-2/' title='myth'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/myth1-150x150.jpg" class="attachment-thumbnail" alt="myth" title="myth" /></a>
<a href='http://blog.wolfgang-werner.net/restful-http-with-jax-rs/restafari-2/' title='RESTafari'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/RESTafari1-150x150.jpg" class="attachment-thumbnail" alt="RESTafari" title="RESTafari" /></a>
<a href='http://blog.wolfgang-werner.net/restful-http-with-jax-rs/soap-2/' title='soap'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/11/soap1-150x150.jpg" class="attachment-thumbnail" alt="soap" title="soap" /></a>


<p>Btw., we are looking for java developers. Please feel free to contact me if you are interested.</p>

<div class='footnotes' id='footnotes-576'><div class='footnotedivider'></div><ol><li id='fn-576-1'>&Acirc;&nbsp;<a href="http://cxf.apache.org/">http://cxf.apache.org/</a> <span class='footnotereverse'><a href='#fnref-576-1'>&#8617;</a></span></li><li id='fn-576-2'>&Acirc;&nbsp;<a href="http://jackson.codehaus.org/">http://jackson.codehaus.org/</a> <span class='footnotereverse'><a href='#fnref-576-2'>&#8617;</a></span></li><li id='fn-576-3'>&Acirc;&nbsp;<a href="http://www.springsource.org/">http://www.springsource.org/</a> <span class='footnotereverse'><a href='#fnref-576-3'>&#8617;</a></span></li><li id='fn-576-4'>Or beer, depending on the time of the day <span class='footnotereverse'><a href='#fnref-576-4'>&#8617;</a></span></li><li id='fn-576-5'>&Acirc;&nbsp;<a href="http://stackoverflow.com/questions/2072295/how-to-deploy-a-jax-rs-application">http://stackoverflow.com/questions/2072295/how-to-deploy-a-jax-rs-application</a> <span class='footnotereverse'><a href='#fnref-576-5'>&#8617;</a></span></li><li id='fn-576-6'>I like different approaches. And when I play, I try to be as independent of a certain stack as possible. I want to learn which part does what instead of relying on application server magic. <span class='footnotereverse'><a href='#fnref-576-6'>&#8617;</a></span></li><li id='fn-576-7'>Of course. Nearly everything comes with jetty. <span class='footnotereverse'><a href='#fnref-576-7'>&#8617;</a></span></li><li id='fn-576-8'>Alt-Shift-X, J if you are lazy, which you should be: <a href="http://threevirtues.com/">http://threevirtues.com/</a> <span class='footnotereverse'><a href='#fnref-576-8'>&#8617;</a></span></li><li id='fn-576-9'><a href="https://addons.mozilla.org/de/firefox/addon/2691/">https://addons.mozilla.org/de/firefox/addon/2691/</a> <span class='footnotereverse'><a href='#fnref-576-9'>&#8617;</a></span></li><li id='fn-576-10'>In particular, I like cURL. curl -v -X &lt;HTTP Verb&gt; &lt;URL&gt; is your friend <span class='footnotereverse'><a href='#fnref-576-10'>&#8617;</a></span></li><li id='fn-576-11'>&Acirc;&nbsp;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html</a> <span class='footnotereverse'><a href='#fnref-576-11'>&#8617;</a></span></li><li id='fn-576-12'>Which I find&Acirc;&nbsp;particularly&Acirc;&nbsp;ugly. But it needs to be done. <span class='footnotereverse'><a href='#fnref-576-12'>&#8617;</a></span></li><li id='fn-576-13'>After reformatting <span class='footnotereverse'><a href='#fnref-576-13'>&#8617;</a></span></li><li id='fn-576-14'>For details see e.g.&Acirc;&nbsp;<a href="http://en.wikipedia.org/wiki/Content_negotiation">http://en.wikipedia.org/wiki/Content_negotiation</a> <span class='footnotereverse'><a href='#fnref-576-14'>&#8617;</a></span></li><li id='fn-576-15'>For details see <a href="https://cwiki.apache.org/WINK/jax-rs-request-and-response-entities.html">https://cwiki.apache.org/WINK/jax-rs-request-and-response-entities.html</a>, e.g. <span class='footnotereverse'><a href='#fnref-576-15'>&#8617;</a></span></li><li id='fn-576-16'><a href="http://bridging-it.de/">http://bridging-it.de/</a> <span class='footnotereverse'><a href='#fnref-576-16'>&#8617;</a></span></li><li id='fn-576-17'><a href="http://www.eclipsecon.org/summiteurope2010/">http://www.eclipsecon.org/summiteurope2010/</a> <span class='footnotereverse'><a href='#fnref-576-17'>&#8617;</a></span></li><li id='fn-576-18'>This guy is fast: It&#8217;s the third time he published something I was working on that point in time. <span class='footnotereverse'><a href='#fnref-576-18'>&#8617;</a></span></li><li id='fn-576-19'>Image credit:<a href=" http://rosewine.deviantart.com/#/d2sw85k"> http://rosewine.deviantart.com/#/d2sw85k</a>, <a href="http://www.etsy.com/listing/33909593/fight-club-vegan-soap-unofficial-parody">http://www.etsy.com/listing/33909593/fight-club-vegan-soap-unofficial-parody</a>, <a href="http://www.flickr.com/photos/onesec/4464260372/">http://www.flickr.com/photos/onesec/4464260372/</a>, <a href="http://www.conti-online.com/generator/www/de/de/contisoccerworld/themes/02_fanzone/04_stars/20_world_cup_stars/1990-matthaeus-de.html">http://www.conti-online.com/generator/www/de/de/contisoccerworld/themes/02_fanzone/04_stars/20_world_cup_stars/1990-matthaeus-de.html</a> <span class='footnotereverse'><a href='#fnref-576-19'>&#8617;</a></span></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://blog.wolfgang-werner.net/restful-http-with-jax-rs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OSGi Console in Helios, Monkey See/Monkey Do and a strange loop</title>
		<link>http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/</link>
		<comments>http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 22:52:18 +0000</pubDate>
		<dc:creator>Wolfgang Werner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[equinox]]></category>
		<category><![CDATA[helios]]></category>
		<category><![CDATA[management console]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[pde]]></category>

		<guid isPermaLink="false">http://blog.wolfgang-werner.net/?p=489</guid>
		<description><![CDATA[Helios comes with an OSGi console that is accessible from the GUI directly. This reminded me of the existence of an API to add custom commands to the console. I found this to be a simple and powerful concept; yet I perceive this feature to be rarely used in practice.
With equinox being used on the server more and more, adding your own custom application management commands is a simple way to provide for executing application specific maintenance tasks.  How about a command that gathers all logs, creates a heap dump, zips everything, puts it onto an FTP server and sends you the download link by mail? Or perhaps you simply want to run some sanity checks? 

In this post, we'll create a custom command for the OSGi console that simply executes a JUnit test and prints the results. 


More importantly, we'll have to snoop around in internal eclipse packages to figure out how to attach the command to the existing console. We'll try to do our snooping effectively. And we'll exploit the dynamic nature of OSGi to streamline our development/build/test cycle (and thats gonna be fun). ]]></description>
			<content:encoded><![CDATA[<div class='toc wptoc'>
<h2>Contents</h2>
<ol class='toc-odd level-1'>
	<li>
		<a href="#Preparation">Preparation</a>
	</li>
	<li>
		<a href="#Test_First">Test First</a>
	</li>
	<li>
		<a href="#Monkey_See_...">Monkey See, ...</a>
	</li>
	<li>
		<a href="#Monkey_Do">...Â Monkey Do</a>
	</li>
	<li>
		<a href="#Strange_Loops">Strange Loops</a>
	</li>
	<li>
		<a href="#Conclusion">Conclusion</a>
	</li>
</ol>
</ol>
</div>
<br />
<span id="Preparation"><h2>Preparation</h2></span>
First, you need to grab the Helios Classic Editon build<sup class='footnote'><a href='#fn-489-1' id='fnref-489-1' onclick='return fdfootnote_show(489)'>1</a></sup> as this version includes the sources as well. We&#8217;ll use the <span class="caps">OSG</span>i console for the currently running eclipse instance that is available via the UI since 3.6M7<sup class='footnote'><a href='#fn-489-2' id='fnref-489-2' onclick='return fdfootnote_show(489)'>2</a></sup>

<p>Now start eclipse, create a new workspace and go to the workbench.</p>

<p>Open the console view (Alt-Shift-Q,Q) and select &#8220;OSGi console&#8221; from the view menu. &Acirc;&nbsp;You now have an <span class="caps">OSG</span>i console that allows you to interact with the running eclipse<sup class='footnote'><a href='#fn-489-3' id='fnref-489-3' onclick='return fdfootnote_show(489)'>3</a></sup>.</p>


<a href='http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/osgi-console-2/' title='osgi-console-1'><img width="150" height="134" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/05/osgi-console-2-150x134.png" class="attachment-thumbnail" alt="osgi-console-1" title="osgi-console-1" /></a>
<a href='http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/osgi-console-1/' title='osgi-console-2'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/05/osgi-console-1-150x150.png" class="attachment-thumbnail" alt="osgi-console-2" title="osgi-console-2" /></a>
<a href='http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/osgi-console-3/' title='osgi-console-3'><img width="150" height="150" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/05/osgi-console-3-150x150.png" class="attachment-thumbnail" alt="osgi-console-3" title="osgi-console-3" /></a>


<p>Type &#8220;help&#8221; to get a list of available commands. You should do that even if you are a eclipse veteran, the list of available commands has grown considerably during the last years. There are commands to start/stop/install/refresh bundles, to view registered services, to configure runtime properties, to query the extension registry, to start and stop equinox applications and enable and disable components.</p>

Let&#8217;s assume we want to be able to run integrity tests on a live system to check whether incoming issue reports could be due to some irregularities with system load, data or deployment issues. Lets also assume that application has a set of JUnit tests to do so. We want to be able to log onto the console and see what the results of our test suite are.<br />
<span id="Test_First"><h2>Test First</h2></span>
No, not <em>that </em>test first. To add a command to run our tests we need tests first, see? We simply create a new <span class="caps">OSG</span>i bundle targeting the equinox runtime using the &#8220;New project&#8221; wizard and add some tests to it. Make sure to have at least on failing test as we&#8217;ll print only failures from our command.



<script src="http://gist.github.com/419277.js"></script>

<p>We also need some piece of code to let us run our tests. Luckily, JUnit provides a simple <span class="caps">API </span>for that<sup class='footnote'><a href='#fn-489-4' id='fnref-489-4' onclick='return fdfootnote_show(489)'>4</a></sup>.</p>

<script src="http://gist.github.com/419280.js"></script><br />
<span id="Monkey_See_8230"><h2>Monkey See, &#8230;</h2></span>
The basic steps are to implement the org.eclipse.osgi.framework.console.CommandProvider interface and to register it with the <span class="caps">OSG</span>i service registry. But this is covered in at least two&Acirc;&nbsp;tutorials by Chris Aniszczyk<sup class='footnote'><a href='#fn-489-5' id='fnref-489-5' onclick='return fdfootnote_show(489)'>5</a></sup> and his evil, quake playing twin<sup class='footnote'><a href='#fn-489-6' id='fnref-489-6' onclick='return fdfootnote_show(489)'>6</a></sup>. You should definitely read them. Less chitchat than this post.

<p>Instead of repeating this<sup class='footnote'><a href='#fn-489-7' id='fnref-489-7' onclick='return fdfootnote_show(489)'>7</a></sup>, I&#8217;d rather show you how to figure it out for yourself. Reading code is an excellent way to learn<sup class='footnote'><a href='#fn-489-8' id='fnref-489-8' onclick='return fdfootnote_show(489)'>8</a></sup>.</p>

<p>First, we need an entry point, a piece of code we know that has something to do with the console. So what do we know? Well, there is a console view, let&#8217;s go hunting for it&#8217;s implementation. To make sure that our searches include the code from the platform plug-ins, we will add them to the Java search. &Acirc;&nbsp;Helios has a handy new button in the Plug-Ins view for that. <sup class='footnote'><a href='#fn-489-9' id='fnref-489-9' onclick='return fdfootnote_show(489)'>9</a></sup></p>

<div class="wpgalleryimage_shortcode" style="width: 384px; height: 131px; float: none;"><img width="382" height="129" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/0-add-to-java-search.png" class="attachment-full" alt="0-add-to-java-search" title="0-add-to-java-search" /></div>

<p>Fire up the search dialog <sup class='footnote'><a href='#fn-489-10' id='fnref-489-10' onclick='return fdfootnote_show(489)'>10</a></sup>, select the Plug-in Search tab, enter &#8220;org.eclipse.ui.views&#8221; as search string and select &#8220;Search for-&gt; Extension Point&#8221;, &#8220;Limit to -&gt; References&#8221; and &#8220;External Scope -&gt; All&#8221;.</p>

<div class="wpgalleryimage_shortcode" style="width: 614px; height: 450px; float: none;"><img width="612" height="448" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/1-search-view.png" class="attachment-full" alt="1-search-view" title="1-search-view" /></div>

<p>This search gives us 28 matches. One match is the one we are looking for: org.eclipse.ui.console.</p>

<div class="wpgalleryimage_shortcode" style="width: 412px; height: 133px; float: none;"><img width="410" height="131" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/2-search-view-result.png" class="attachment-full" alt="2-search-view-result" title="2-search-view-result" /></div>

<p>Let&#8217;s open the declaration and switch over to the extensions tab. We can see the contribution the console view we were looking for, but also something that looks even more promising: An extension point called &#8220;org.eclipse.ui.console.consoleFactories&#8221;. Let&#8217;s see who contributes to this extension point. Choose &#8220;Find References&#8221; from its context menu.</p>

<div class="wpgalleryimage_shortcode" style="width: 416px; height: 326px; float: none;"><img width="414" height="324" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/3-search-console-factory-references.png" class="attachment-full" alt="3-search-console-factory-references" title="3-search-console-factory-references" /></div>

<div class="wpgalleryimage_shortcode" style="width: 374px; height: 119px; float: none;"><img width="372" height="117" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/4-search-console-factory-references-result.png" class="attachment-full" alt="4-search-console-factory-references-result" title="4-search-console-factory-references-result" /></div>

<p>Only four matches. I think we can rule out the one in team.cvs and debug.ui. &Acirc;&nbsp;We&#8217;ll find what we are looking for in the org.eclipse.pde.ui bundle<sup class='footnote'><a href='#fn-489-11' id='fnref-489-11' onclick='return fdfootnote_show(489)'>11</a></sup>.</p>

<div class="wpgalleryimage_shortcode" style="width: 336px; height: 242px; float: none;"><img width="334" height="240" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/5-found-osgi-console-contribution.png" class="attachment-full" alt="5-found-osgi-console-contribution" title="5-found-osgi-console-contribution" /></div>

<p>The contribution contains the implementation class, so we open this class next. Copy the qualified name of the class, press Ctrl-Shift-T and paste the class name.</p>

<div class="wpgalleryimage_shortcode" style="width: 350px; height: 138px; float: none;"><img width="348" height="136" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/6-open-type.png" class="attachment-full" alt="6-open-type" title="6-open-type" /></div>

<p>In the console factory, we find that a new console is instantiated in the getConsole() method. Let&#8217;s open the implementation by Ctrl-Click on the class name.</p>

<div class="wpgalleryimage_shortcode" style="width: 393px; height: 108px; float: none;"><img width="391" height="106" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/11-open-OSGiConsole.png" class="attachment-full" alt="11-open-OSGiConsole" title="11-open-OSGiConsole" /></div>

<p>A first glance at this class does not&Acirc;&nbsp;immediately reveal where the console commands come from. We need to dig a little deeper aka start guessing and poking around wildly. To be able to run a command, the console input needs to be evaluated, thats for sure. So lets see if we can find where the input is read. In the <span class="caps">OSG</span>i console constructure, a new anonymous ConsoleSession is created. The ConsoleSession has a method called getInput() that returns an input stream. Let&#8217;s see who calls this method: place the cursor on the method name and press Ctrl-Alt-H to open the call hierarchy.</p>

<script src="http://gist.github.com/457091.js"></script>

<div class="wpgalleryimage_shortcode" style="width: 601px; height: 149px; float: none;"><img width="599" height="147" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/12-call-hierarchy.png" class="attachment-full" alt="12-call-hierarchy" title="12-call-hierarchy" /></div>

<p>The first&amp;direct caller, FrameworkConsole, seems not overly interesting in terms of command definitions. Let&#8217;s see what the next one, ConsoleManger looks like. A little hidden, somewhere in the middle we find a field of the type FrameworkCommandProvider. Now we&#8217;re pretty close to what we want to know. This is the place were &#8211; at least some &#8211; console commands are defined. The constructor&#8217;s comment pretty much tells us what to do:</p>

<script src="http://gist.github.com/457103.js"></script>

<p>So we need to implement a CommandProvider and register it with the service registry. For each command we want to implement, we need to have a method called &#8220;_&lt;command name&gt;&#8221;. We&#8217;ll implement only one command that calls our test runner. Additionally, I think we should implement the the getHelp() method to describe our command to the user.</p>

<p>It may be useful for your analysis to make changes to eclipse plug-ins to see how they behave. There is a simple recipe how you can do this without the risk of doing much harm: Import the respective plug-in from the target platform to the workspace, then create a launch configuration containing the workspace instead of the target platform bundle. You can now edit the standard eclipse bundle to gain a deeper understanding. When you are done, simply delete the bundle from the workspace (and from the disk as well).</p>

<div class="wpgalleryimage_shortcode" style="width: 484px; height: 162px; float: none;"><img width="482" height="160" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/17-import-project-from-target.png" class="attachment-full" alt="17-import-project-from-target" title="17-import-project-from-target" /></div><br />
<span id="AcircnbspMonkey_Do"><h2>&#8230;&Acirc;&nbsp;Monkey Do</h2></span>
Use the bundle project we have created in the first chapter. Add a new dependency to &#8220;org.eclipse.osgi.framework.console&#8221;&iuml;&raquo;&iquest;, the package containing the CommandProvider interface.

<div class="wpgalleryimage_shortcode" style="width: 496px; height: 213px; float: none;"><img width="494" height="211" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/13-additional-dependency.png" class="attachment-full" alt="13-additional-dependency" title="13-additional-dependency" /></div>

<p>Create a new class using the new class wizard, have it implement CommandProvider and generate the inherited methods.</p>

<div class="wpgalleryimage_shortcode" style="width: 499px; height: 600px; float: none;"><img width="497" height="598" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/14-new-class-wizard.png" class="attachment-full" alt="14-new-class-wizard" title="14-new-class-wizard" /></div>

<p>Implement the getHelp() method so the output looks similar to the other commands. Have a look at the FrameworkCommandProvider for reference. Note that you can use Alt-Left/Alt-Right to navigate in the edit/browse location history. Useful as you can easily switch back and forth between your class and the reference class without using your mouse.</p>

<p>We call our command &#8220;check&#8221;, so we also need to implement &#8220;<em>check(CommandInterpreter intp)&#8221;. The command interpreter is used to output the results from our tests. Take a look at the &#8220;</em>*&#8221; methods in FrameworkCommandProvider for examples.</p>

<p>The complete class looks like this<sup class='footnote'><a href='#fn-489-12' id='fnref-489-12' onclick='return fdfootnote_show(489)'>12</a></sup>:</p>

<script src="http://gist.github.com/457157.js"></script>

<p>Now we need to register/de-register our command provider in the Activators start() resp. stop methods:</p>

<script src="http://gist.github.com/457181.js"></script>

Having implemented all this, it&#8217;s time to look at our options for giving it a test drive<br />
<span id="Strange_Loops"><h2>Strange Loops</h2></span>
We can either<br />
<ul>
	<li>start our bundle as eclipse application, open the console view and test our command</li>
	<li>create a minimal run configuration and start the framework with the console and test there</li>
	<li>build the bundle and install it into the running framework (the running eclipse instance)</li>
	<li>or even install the bundle directly from it&#8217;s files in the workspace</li>
</ul>
While option two is probably the most reasonable approach (for separation of concerns and debugging issues), option four is certainly the most fun<sup class='footnote'><a href='#fn-489-13' id='fnref-489-13' onclick='return fdfootnote_show(489)'>13</a></sup>. Since I wrote about run configs in an earlier post<sup class='footnote'><a href='#fn-489-14' id='fnref-489-14' onclick='return fdfootnote_show(489)'>14</a></sup> guess what we&#8217;ll do now. The only thing we need to do to make our bundle installable directly is to add the bin/ folder of our project to the runtime classpath.

<div class="wpgalleryimage_shortcode" style="width: 603px; height: 231px; float: none;"><img width="601" height="229" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/15-runtime-classpath.png" class="attachment-full" alt="15-runtime-classpath" title="15-runtime-classpath" /></div>

<p>Then we can use the console to install the bundle from the workspace. First, check that our command is not yet available by calling our &Acirc;&nbsp;&#8221;check&#8221; command. Our command is not found, so the help contents are displayed. Note that our command&#8217;s help text is missing as well. Then we can install the bundle if we know the project&#8217;s path on the harddrive.</p>

<div class="wpgalleryimage_shortcode" style="width: 706px; height: 231px; float: none;"><img width="704" height="229" src="http://blog.wolfgang-werner.net/wp-content/uploads/2010/06/16-project-location.png" class="attachment-full" alt="16-project-location" title="16-project-location" /></div>

<p>-</p>

<script src="http://gist.github.com/457911.js"></script>

<p>We have now &Acirc;&nbsp;installed a bundle that we are currently developing into our running eclipse instance. Isn&#8217;t that awesome? Of course you need to be careful with this approach as you can pretty much screw things up when fiddling with the hot bundle configuration of your <span class="caps">IDE, </span>but I think this approach actually makes sense when you are integrating with the <span class="caps">IDE </span>rather than building a standalone application.</p>

Besides, I just love self-referential stuff.<br />
<blockquote>What I mean by &#8220;strange loop&#8221; is &acirc;€” here goes a first stab, anyway &acirc;€” not a physical circuit but an abstract loop in which, in the series of stages that constitute the cycling-around, there is a shift from one level of abstraction (or structure) to another, which feels like an upwards movement in a hierarchy, and yet somehow the successive &#8220;upward&#8221; shifts turn out to give rise to a closed cycle. That is, despite one&#8217;s sense of departing ever further from one&#8217;s origin, one winds up, to one&#8217;s shock, exactly where one had started out. In short, a strange loop is a paradoxical level-crossing feedback loop. &#8211; Douglas R. Hofstadter</blockquote>
See also&Acirc;&nbsp;<a href="http://www.xkcd.com/555/">http://www.xkcd.com/555/</a>, don&#8217;t forget to read the tooltip.<br />
<span id="Conclusion"><h2>Conclusion</h2></span>
Besides highlighting the Host <span class="caps">OSG</span>i console included in Helios and trying to revive the memory of custom <span class="caps">OSG</span>i console commands, this article showed you how you can find out how stuff is done in eclipse by following the monkey see/monkey do rule and gave some tips how to apply this rule in practice.

<p>I&#8217;d be happy to see more custom <span class="caps">OSG</span>i console commands in the wild. As I said in the teaser, I still think this concept is underused. Also remember that the <span class="caps">OSG</span>i console can be configured to be accessible remotely using telnet. Now don&#8217;t tell me you can&#8217;t think of use cases for that.</p>

<p>I&#8217;ll push the complete sources of the example to github during the next days. In the meantime: Let me know if you get stuck.</p>

<p>I hope you enjoyed reading and that I gave you one or the other idea that may help you in future projects. Thanks for reading.</p>

<div class='footnotes' id='footnotes-489'><div class='footnotedivider'></div><ol><li id='fn-489-1'><a href="http://www.eclipse.org/downloads/packages/eclipse-classic-360/heliosr">http://www.eclipse.org/downloads/packages/eclipse-classic-360/heliosr</a> <span class='footnotereverse'><a href='#fnref-489-1'>&#8617;</a></span></li><li id='fn-489-2'><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.6M7-201004291549/eclipse-news-M7.html#osgiconsole">http://download.eclipse.org/eclipse/downloads/drops/S-3.6M7-201004291549/eclipse-news-M7.html#osgiconsole</a> <span class='footnotereverse'><a href='#fnref-489-2'>&#8617;</a></span></li><li id='fn-489-3'>The screenshots were taken on 3.6M7, it looks a little different in the final release. The draft of this post has seen some idle cycles&#8230; <span class='footnotereverse'><a href='#fnref-489-3'>&#8617;</a></span></li><li id='fn-489-4'><a href="http://www.junit.org/junit/javadoc/4.3/org/junit/runner/JUnitCore.html">http://www.junit.org/junit/javadoc/4.3/org/junit/runner/JUnitCore.html</a> <span class='footnotereverse'><a href='#fnref-489-4'>&#8617;</a></span></li><li id='fn-489-5'><a href="http://www.ibm.com/developerworks/library/os-ecl-osgiconsole/index.html">http://www.ibm.com/developerworks/library/os-ecl-osgiconsole/index.html</a> <span class='footnotereverse'><a href='#fnref-489-5'>&#8617;</a></span></li><li id='fn-489-6'>&Acirc;&nbsp;<a href="http://eclipsesource.com/blogs/2008/08/01/tip-custom-osgi-equinox-console-commands/">http://eclipsesource.com/blogs/2008/08/01/tip-custom-osgi-equinox-console-commands/</a> <span class='footnotereverse'><a href='#fnref-489-6'>&#8617;</a></span></li><li id='fn-489-7'>Good Artists Copy, Great Artists Steal &#8211; Pablo Picasso, probably. Also look for <span class="caps">T.S.</span> Eliot quotes in that context. Steve Jobs stole it, too. In the late eighties, if you judge by his hair. <span class='footnotereverse'><a href='#fnref-489-7'>&#8617;</a></span></li><li id='fn-489-8'>Valiantly deciphering <span class="caps">XML </span>(plugin/application context/deployment descriptors) to learn how dependencies are wired at runtime, too. Provided the tooling is good. Otherwise it can be quite frustrating. Luckily the <span class="caps">PDE </span>tooling for navigating plugin.xml &amp; manifest files is excellent. The search also feels a lot faster on Helios. <span class='footnotereverse'><a href='#fnref-489-8'>&#8617;</a></span></li><li id='fn-489-9'>You can do the same in pre-helios builds: In the Plug-ins view, select all plug-ins and choose &#8216;add to Java search&#8217; from the context menu <span class='footnotereverse'><a href='#fnref-489-9'>&#8617;</a></span></li><li id='fn-489-10'>Ctrl-H <span class='footnotereverse'><a href='#fnref-489-10'>&#8617;</a></span></li><li id='fn-489-11'>This is not pre-recorded. I&#8217;m making it up as we go along. Perhaps I left out some dead ends, though. See if you can spot them in the screen shots. <span class='footnotereverse'><a href='#fnref-489-11'>&#8617;</a></span></li><li id='fn-489-12'>Yep, we simplified the getHelp() method. Using constants is good style, &Acirc;&nbsp;but only if you use them more than once. <span class="caps">KISS, </span>for this example. <span class='footnotereverse'><a href='#fnref-489-12'>&#8617;</a></span></li><li id='fn-489-13'>In a weird, nerdy way, at least. <span class='footnotereverse'><a href='#fnref-489-13'>&#8617;</a></span></li><li id='fn-489-14'><a href="http://blog.wolfgang-werner.net/building-on-equinox-and-restlet-1/#Running">http://blog.wolfgang-werner.net/building-on-equinox-and-restlet-1/#Running</a> <span class='footnotereverse'><a href='#fnref-489-14'>&#8617;</a></span></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://blog.wolfgang-werner.net/osgi-console-in-helios-monkey-see-monkey-do-and-a-strange-loop/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building web services on Equinox and Restlet #3</title>
		<link>http://blog.wolfgang-werner.net/building-web-services-on-equinox-and-restlet-3/</link>
		<comments>http://blog.wolfgang-werner.net/building-web-services-on-equinox-and-restlet-3/#comments</comments>
		<pubDate>Wed, 05 May 2010 00:09:35 +0000</pubDate>
		<dc:creator>Wolfgang Werner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[equinox]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[extension point]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restlet]]></category>

		<guid isPermaLink="false">http://blog.wolfgang-werner.net/?p=341</guid>
		<description><![CDATA[After having implemented the server application, we want to prepare ourselves for future changes. We want to be able to add new services to our application without impacting existing ones. We also may want to change the structure of the URIs in case they are not cool. 

To do so, we'll create extension points and the supporting code for the Restlet types used and contribute our implementations and see how that this helps us making our application more flexible and maintainable.

We'll learn how to define an extension point, how to contribute to it and how to work with the contributions.]]></description>
			<content:encoded><![CDATA[<br />
<b>Fatal error</b>:  Allowed memory size of 50331648 bytes exhausted (tried to allocate 7680 bytes) in <b>/var/www/web241/html/blog/wp-content/plugins/textile-2/class/Textile.php(3245) : runtime-created function</b> on line <b>1</b><br />

