<?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>EclipseSource Blog &#187; Ralf Sternberg</title>
	<atom:link href="http://eclipsesource.com/blogs/author/rsternberg/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsesource.com/blogs</link>
	<description>Eclipse Equinox OSGi</description>
	<lastBuildDate>Fri, 17 May 2013 13:50:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>A Fast and Minimal JSON Parser for Java</title>
		<link>http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/</link>
		<comments>http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 08:25:25 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software craftsmanship]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=15349</guid>
		<description><![CDATA[In the RAP project, reading and writing JSON are critical operations, since the server processes and creates JSON messages for a large number of clients at a high rate. For this reason, we need something fast for this job. When we switched to JSON, we included the org.json parser, which is reasonably small but not <a href="http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://eclipse.org/rap/">RAP</a> project, reading and writing JSON are critical operations, since the server processes and creates JSON messages for a large number of clients at a high rate. For this reason, we need something fast for this job. When we switched to JSON, we included the <a href="http://www.json.org/java/index.html">org.json</a> parser, which is reasonably small but not famous for its performance.</p>
<p>There are many better JSON libraries out there, but most do much more than we need. We really only need a bare-bones parser that can read JSON into a simple Java representation and generate JSON from Java. As we like to keep the core library self-contained, we don&#8217;t want a dependency to an external JSON library.</p>
<p>One winter Sunday, I started to write a JSON parser just for the fun of it, and was quickly surprised how simple it is to parse JSON. That&#8217;s because the first character of every token uniquely defines its type (<code>'['</code> for an array, <code>'"'</code> for a string, <code>'t'</code> or <code>'f'</code> for a boolean, and so forth). There&#8217;s no backtracking involved. It went so well that I decided to continue and create a JSON parser tailored to our needs. Which are:</p>
<ul>
<li><strong>Fast</strong> &#8211; we read and create so much JSON that the parser directly affects the server performance</li>
<li><strong>Lightweight</strong> &#8211; it should deal with memory sparingly as we deal with lots of messages</li>
<li><strong>Minimal</strong> &#8211; the less code the better, as we have to maintain it</li>
<li><strong>Simple to use</strong> &#8211; we&#8217;ll expose the API for custom component developers, so it should be simple and clear</li>
<li><strong>No dependencies</strong> &#8211; only Java 5</li>
</ul>
<p>The result is called <a href="https://github.com/ralfstx/minimal-json">minimal-json</a> and it&#8217;s already included in RAP. It is fast, lightweight, consists only of 10 classes and I hope it&#8217;s simple to use:</p>
<h2>Usage</h2>
<p>You can read a JSON object or array from a <em>Reader</em> or from a <em>String</em>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">JsonObject jsonObject <span style="color: #339933;">=</span> JsonObject.<span style="color: #006633;">readFrom</span><span style="color: #009900;">&#40;</span> reader <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
JsonArray jsonArray <span style="color: #339933;">=</span> JsonArray.<span style="color: #006633;">readFrom</span><span style="color: #009900;">&#40;</span> string <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once you have a <em>JsonObject</em>, you can access its contents using the <em>get()</em> method:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> name <span style="color: #339933;">=</span> jsonObject.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">asString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> age <span style="color: #339933;">=</span> jsonObject.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;age&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">asInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// asLong(), asDouble(), ...</span></pre></td></tr></table></div>

<p>The elements of a JSON array can be accessed in a similar way:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> name <span style="color: #339933;">=</span> jsonArray.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">asString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> age <span style="color: #339933;">=</span> jsonArray.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">asInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// asLong(), asDouble(), ...</span></pre></td></tr></table></div>

<p>As you can see, the <em>get()</em> method always returns an instance of <em>JsonValue</em>, which can then be transformed to the target type using <em>asString()</em>, <em>asInt()</em>, <em>asDouble()</em>, etc. There&#8217;s no automatic conversion to Java types, no <em>instanceof</em> needed. If you&#8217;re not sure about the type of a value you can check it using <em>isString()</em>, <em>isNumber()</em>, etc.</p>
<p>Nested arrays and objects can be accessed using <em>asArray()</em> and <em>asObject()</em>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">JsonArray nestedArray <span style="color: #339933;">=</span> jsonObject.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;items&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">asArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can also iterate over the elements of an JsonArray and the names of a JsonObject, e.g.:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> name <span style="color: #339933;">:</span> jsonObject.<span style="color: #006633;">names</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  JsonValue value <span style="color: #339933;">=</span> jsonObject.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> name <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Writing JSON</h3>
<p>A <em>JsonObject</em> or <em>JsonArray</em> can output JSON to a <em>Writer</em> or as a string using the <em>toString()</em> method. The JSON is currently not pretty-printed, formatting support might be added later.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">jsonObject.<span style="color: #006633;">writeTo</span><span style="color: #009900;">&#40;</span> writer <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> json <span style="color: #339933;">=</span> jsonArray.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>To create a <em>JsonObject</em> or a <em>JsonArray</em>, use the <em>add()</em> methods that exist for the relevant types. These methods return the object instance to allow method chaining:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">jsonObject <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;name&quot;</span>, <span style="color: #0000ff;">&quot;John&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;age&quot;</span>, <span style="color: #cc66cc;">23</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jsonArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;John&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">23</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You may have noticed that also the object has an <em>add()</em> method instead of a <em>put()</em> or <em>set()</em>. That&#8217;s because the JsonObject stores and writes its members in the order they are added. It allows you to define the output order, it even allows you to add the same key twice, which is discouraged but not forbidden by the <a href="http://www.ietf.org/rfc/rfc4627.txt">JSON RFC</a>.</p>
<p>To replace an element in an array of object, you first have to <em>remove()</em> the old value and then <em>add()</em> the new one. A <em>replace()</em> method may be added later. However, <em>JsonArray</em> and <em>JsonObject</em> are designed to be containers for reading and writing JSON, not general purpose data structures.</p>
<h2>Performance</h2>
<p>I&#8217;ve compared the time required to read and write a typical RAP message with other popular parser implementations, namely <a href="http://www.json.org/java/index.html">org.json</a> (20091211), <a href="http://code.google.com/p/google-gson/">Gson</a> (2.2.2), <a href="http://wiki.fasterxml.com/JacksonHome">Jackson</a> (1.9.12), and <a href="http://code.google.com/p/json-simple/">JSON.simple</a> (1.1). Disclaimer: This benchmark is restricted to our use case and my limited knowledge on the other libraries. It may be unfair as it ignores other use cases and perhaps better ways to use these libraries. However, I think these results show that minimal-json can take comparison with state-of-the-art parsers.</p>
<p><center><br />
<a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/chart_31.png"><img class="aligncenter size-full wp-image-15393" alt="chart 31 A Fast and Minimal JSON Parser for Java" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/chart_31.png" width="585" height="289" title="A Fast and Minimal JSON Parser for Java" /></a><br />
</center></p>
<p>I also ran a number of micro-benchmarks using <a href="http://code.google.com/p/caliper/">Google caliper</a> while optimizing the implementation. One interesting detail was the choice of the data structure for the <em>JsonObject</em>. Since JSON objects are key-value maps, a HashMap seems like an obvious choice. However, after some experiments, I ended up with two separate ArrayLists for names and values.</p>
<p>Of course, looking up a key in a list requires a linear search while a hash lookup is much quicker. However, creating a HashMap and adding elements has a considerable overhead. It turns out that this overhead squashes the benefits of a HashMap for very small numbers of items (&lt; 10). Since JSON messages in RAP typically contain many objects with only a few items, a HashMap would even impair the overall performance. Moreover, the two ArrayLists require less than a third of the footprint of a HashMap.</p>
<p><center><br />
<a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/chart_21.png"><img class="aligncenter size-full wp-image-15394" alt="chart 21 A Fast and Minimal JSON Parser for Java" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/chart_21.png" width="583" height="342" title="A Fast and Minimal JSON Parser for Java" /></a><br />
</center></p>
<p>I was able to improve the lookup performance for small item counts by adding a very small hash structure to the names list. This structure consists of a 32-elements byte array. It does not handle collisions but resorts to <em>indexOf()</em> in case of a miss. This version (shown in the middle of the chart above) seems to be a good compromise between HashMap and plain ArrayList. Optimizations for bigger JSON objects are possible, but not needed at the moment.</p>
<h2>How to Use it</h2>
<p>If you&#8217;re looking for a bare-bones JSON parser with zero dependencies, you are welcome to use minimal-json. It goes without saying that it&#8217;s developed test-driven and complies with the RFC. The code lives at <a href="https://github.com/ralfstx/minimal-json">github</a> and is <a title="Eclipse Public License" href="http://www.eclipse.org/legal/epl-v10.html">EPL</a>-licensed. It is also included in RAP.</p>
<p>I didn&#8217;t setup a build. If you would like to use the code, I suggest that you simply copy these 10 Java files to your project.</p>
<p>Let me know if you find this useful, fork it on github, and feel free to open an issue if you find a problem.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=A+Fast+and+Minimal+JSON+Parser+for+Java&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/&amp;t=A+Fast+and+Minimal+JSON+Parser+for+Java" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/><a href="http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/#comments">8 Comments</a>. Tagged with <a href='http://eclipsesource.com/blogs/tag/api/' title='api Tag'>api</a>, <a href='http://eclipsesource.com/blogs/tag/java/' title='Java Tag'>Java</a>, <a href='http://eclipsesource.com/blogs/tag/software-craftsmanship/' title='Software craftsmanship Tag'>Software craftsmanship</a>, <a href='http://eclipsesource.com/blogs/tag/api/' title='api Tag'>api</a>, <a href='http://eclipsesource.com/blogs/tag/java/' title='Java Tag'>Java</a>, <a href='http://eclipsesource.com/blogs/tag/software-craftsmanship/' title='Software craftsmanship Tag'>Software craftsmanship</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Launched Today</title>
		<link>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/#comments</comments>
		<pubDate>Mon, 11 Feb 2013 12:55:07 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14202</guid>
		<description><![CDATA[The Eclipse RAP Project has just launched its long-awaited 2.0 version. With this release, the project has changed its name to “Remote Application Platform” to indicate the transition from a browser platform to a universal platform for remote applications. RAP 2.0 supports alternative clients and has new APIs to distinguish between clients, access client-specific features, and <a href="http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/rap-logo-201.png"><img class="alignright size-full wp-image-14257" alt="rap logo 201 RAP 2.0 Launched Today" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/rap-logo-201.png" width="225" height="113" title="RAP 2.0 Launched Today" /></a></p>
<p>The Eclipse <a href="http://eclipse.org/rap/">RAP Project</a> has just launched its long-awaited 2.0 version.</p>
<p>With this release, the project has changed its name to “Remote Application Platform” to indicate the transition from a browser platform to a universal platform for remote applications. RAP 2.0 supports alternative clients and has new APIs to distinguish between clients, access client-specific features, and write custom components that use the new protocol. During the past few days, I&#8217;ve written a series of blog posts to explain the most important changes and features in RAP 2.0:</p>
<p><a title="RAP 2.0 Countdown (1/5)" href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/">1. Remote – The New “R” in RAP</a><br />
<a title="RAP 2.0 Countdown (2/5)" href="http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/">2. The Pillars of the RAP 2.0 API</a><br />
<a title="RAP 2.0 Countdown (3/5)" href="http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/">3. Know Your Client</a><br />
<a title="RAP 2.0 Countdown (4/5)" href="http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/">4. What is Server Push and Why Should I Care?</a><br />
<a title="RAP 2.0 Countdown (5/5)" href="http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/">5. Custom Widgets with RAP 2.0</a></p>
<p>A detailed list of changes in this release can be found on the project&#8217;s <a href="http://eclipse.org/rap/noteworthy/2.0/">New &amp; Noteworthy page</a>. We are excited about the possibilities opened up by the new RAP and hope that you will enjoy working with this release.</p>
<p>The release is available as p2 update sites and as .zip files on the <a href="http://eclipse.org/rap/downloads/">RAP download page</a>.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Launched+Today&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/&amp;t=RAP+2.0+Launched+Today" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-launched-today/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Countdown (5/5)</title>
		<link>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/#comments</comments>
		<pubDate>Mon, 11 Feb 2013 11:16:37 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14197</guid>
		<description><![CDATA[Today&#8217;s our big day: RAP 2.0 is being released. Here&#8217;s my last post in this RAP 2.0 series. In my first post, I wrote about the new JSON protocol and how it connects the half objects on client and server. The question is, can you leverage this protocol for custom add-ons? You can, using the <a href="http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s our big day: <a href="http://eclipse.org/rap/">RAP 2.0</a> is being released. Here&#8217;s my last post in this RAP 2.0 series. In my <a href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/">first post</a>, I wrote about the new JSON protocol and how it connects the <em>half objects</em> on client and server. The question is, can you leverage this protocol for custom add-ons? You can, using the new <em>Remote API</em>. I saved this topic until last. It&#8217;s my favorite because I&#8217;m excited about its potential to make RAP more extensible.</p>
<h2>Custom Widgets with RAP 2.0</h2>
<p><center><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/custom.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/custom.png" alt="custom RAP 2.0 Countdown (5/5)" width="600" height="437" class="aligncenter size-full wp-image-14213" title="RAP 2.0 Countdown (5/5)" /></a></center></p>
<p>There are several alternatives to writing real custom widgets in RAP: you can compose widgets out of existing ones, draw on a Canvas, or embed mashups in a Browser widget. However, for advanced widgets you don&#8217;t get around writing a “real” custom widget with a server part and a client part that are connected by the protocol.</p>
<p>This has become a lot easier with RAP 2.0, since you don’t have to understand the internals of RWT anymore. The new Remote API allows both parts of an object to communicate with each other over the JSON protocol. In fact, its methods are direct representations of the protocol operations such as <em>set</em>, <em>call</em>, etc. Just like the protocol itself, this API is not restricted to widgets, it can be used to synchronize any kind of objects.</p>
<h3>The Remote API at a Glance</h3>
<p>Let’s have a quick look at this API. The central interface is called <em><a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/remote/RemoteObject.html">RemoteObject</a></em>. As the name says, it represents the corresponding object on the client. When an instance of the server-side object is created, we first need to create a client-side object as well and synchronize with this object. We do so by creating a <em>RemoteObject</em>. The constructor of our custom widget would be a suitable place to do so:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Connection</span> connection <span style="color: #339933;">=</span> RWT.<span style="color: #006633;">getUISession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
remoteObject <span style="color: #339933;">=</span> connection.<span style="color: #006633;">createRemoteObject</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;charts.PieChart&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This will render a <em>create</em> message that instructs the client to create an object of the type <em>charts.PieChart</em>. When a property is changed on the custom widget, we need to pass the new value to the remote object:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">remoteObject.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;radius&quot;</span>, <span style="color: #cc66cc;">200</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>When the custom widget is being disposed of, the remote object has to be destroyed as well:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">remoteObject.<span style="color: #006633;">destroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>There are also methods for the other protocol operations and a handler to receive updates from the client. I don&#8217;t want to go through all details here, just give you a rough idea how the Remote API looks like.</p>
<h3>JavaScript API</h3>
<p>We also need a client implementation to display your custom widget and allow users to interact. For the web client, this has become a lot easier. For the first time ever, RAP 2.0 provides a minimal <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/jsdoc/symbols/rap.html">JavaScript API</a>. It’s minimal because it just contains the methods needed to hook your JavaScript code into the RAP client. You don’t have to care about RAP’s client library anymore. Use whatever JavaScript library you like.</p>
<p>To look at an example, let&#8217;s see how the client notifies the server of an event:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> remoteObject <span style="color: #339933;">=</span> rap.<span style="color: #660066;">getRemoteObject</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
remoteObject.<span style="color: #660066;">notify</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Selection&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;index&quot;</span><span style="color: #339933;">:</span> index <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Of course, it uses a <em>remote object</em> to do so, and its API is quite similar to the Java RemoteObject.</p>
<h2>Let&#8217;s Create Widgets!</h2>
<p>With this new Remote API, custom widgets are no longer reserved for experts. Writing them is easier, requires less code, and it&#8217;s definitely more fun. That&#8217;s what we found when we employed the Remote API for existing components. As an example, switching the clientscripting component to the Remote API, allowed us to get rid of more than 30% of the Java code in this component!</p>
<p>Tim just updated his <a href="https://github.com/eclipsesource/rap-ckeditor">CKEditor widget for RAP</a> to use the new API. You can try it out in the <a href="http://rap.eclipsesource.com/rapdemo/examples#ckeditor">online demo</a>. If you’re looking for a rich text editor for RAP, here’s a 2.0-compatible version.</p>
<p>During the last days, I’ve created a prototype for a charting widget (the one seen above) based on the fascinating <a href="http://d3js.org/">d3 toolkit</a>. You can play with it already in the <a href="http://rap.eclipsesource.com/rapdemo/examples#chart">online demo</a>. It&#8217;s just a spike, but I’m going to publish a stable version soon and announce it in this blog.</p>
<p>The new Remote API is still provisional and might change slightly over time. We’ve already published it anyway to allow others to start experimenting. I&#8217;m looking forward to more custom widgets becoming available for RAP. Let us know about your custom widgets! Contributions are welcome in the RAP Incubator project.</p>
<p>Thank you for following me on this tour through the new RAP. <a href="http://eclipse.org/rap/noteworthy/2.0/">RAP 2.0</a> is now available for <a href="http://eclipse.org/rap/downloads/">download</a>. I hope you enjoy working with it.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Countdown+%285%2F5%29&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/&amp;t=RAP+2.0+Countdown+%285%2F5%29" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Countdown (4/5)</title>
		<link>http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 10:08:01 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14155</guid>
		<description><![CDATA[While we are waiting for the RAP 2.0 release to be published on Monday, I’m introducing you to the most important changes in this major release. For today, I’ve picked a slightly trickier part of RAP: the server push. RAP has built-in server push support, and a brand new push API in 2.0. Let me <a href="http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>While we are waiting for the <a href="http://eclipse.org/rap/noteworthy/2.0/">RAP 2.0</a> release to be published on Monday, I’m introducing you to the most important changes in this major release. For today, I’ve picked a slightly trickier part of RAP: the <em>server push</em>. RAP has built-in server push support, and a brand new push API in 2.0. Let me use the opportunity to shed some light on this topic.</p>
<h2>What is Server Push and Why Should I Care?</h2>
<p>An HTTP server cannot simply “push” information onto the client. It has to wait for the client to ask for changes. <a href="http://en.wikipedia.org/wiki/Push_technology">Server push techniques</a> allow clients to be notified immediately in the event of a server-side change. In RAP, server push comes into play whenever you access the UI from a thread that is not the UI thread, that is, outside of the normal event handler code.</p>
<h3>Normal Operation (The Blue Part)</h3>
<p>Let&#8217;s start with the simple case. I&#8217;d like to ask you to focus only on the blue part of the diagram below and try to cut out everything else for now.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/ServerPush.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/ServerPush.png" alt="ServerPush RAP 2.0 Countdown (4/5)" width="700" height="494" class="aligncenter size-full wp-image-14175" title="RAP 2.0 Countdown (4/5)" /></a></p>
<p>Whenever an event occurs (e.g. a button press), the client sends a POST request to the server with a JSON message that contains the event. All event handler code is executed in the UIThread on the server. Any changes to the UI made in this thread are immediately sent to the client.</p>
<h3>Background Processing (The Red Part)</h3>
<p>Now let’s add the dark red line to the picture (green is still invisible). Another thread is forked from the UI thread to execute some background task. We use to call those non-UI threads <em>background threads</em>. In SWT, the UI may only be accessed from the UI thread. When you want to update the UI from a background thread, you have to wrap the respective code in a runnable and hand it over to <em>Display.asyncExec()</em> or <em>syncExec()</em>. The runnable will be put into a queue to be executed in the UI thread.</p>
<p>The runnables in this queue can be processed in the UI thread only when the client sends another POST request. The updates will not appear on the user&#8217;s screen until there is some user interaction.</p>
<h3>Server Push (Green)</h3>
<p>Now for the green part. When server push is enabled, the client will send a GET request everytime a POST returns. This GET request is blocked on the server, so the client keeps waiting for a response. When <em>Display.asyncExec()</em> is called and a runnable put into the queue, the server releases the blocked request and sends an empty response. This notifies the client to send another POST request to fetch the updates from the server.</p>
<p>As you can see, this process results in a continuous serpentine line that keeps the client up to date.</p>
<h2>The New Server Push API</h2>
<p>In RAP 1.x, this feature was called <em>UICallBack</em>. Since “server push” has become an established term, we decided to use this for the new API. However, there&#8217;s no <em>ServerPush</em> class, but only a <em><a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/service/ServerPushSession.html">ServerPushSession</a></em>. Instead of activating the server push directly, you create and start a push <em>session</em>. There can be multiple overlapping push sessions throughout your code, and as long as at least one of them is active, the framework will keep the green part enabled.</p>
<p>To request server push, create a <em>new ServerPushSession</em> and call <em>start</em> on it. It&#8217;s crucial to do that in the UIThread <em>before</em> you fork a background thread. When your code doesn&#8217;t require the server push anymore, call <em>stop()</em> on the push session. That&#8217;s all. In contrast to the old API, you can stop the session from any thread you like.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> ServerPushSession pushSession <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ServerPushSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Runnable</span> runnable <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// do some background work ...</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// update the UI</span>
    display.<span style="color: #006633;">asyncExec</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>label.<span style="color: #006633;">isDisposed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          label.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;updated&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// close push session when no longer needed</span>
    pushSession.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// start push session before starting the thread</span>
pushSession.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Thread</span> thread <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span> runnable <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
thread.<span style="color: #006633;">setDaemon</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
thread.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The server push in RAP has gone through many iterations. It has been completely reworked in RAP 1.5 and again revised in 2.0. For example, one improvement in 2.0 is that the client is now immediately notified in case of a session timeout when server push is enabled. So I&#8217;m pleased to say that the server push in RAP 2.0 is now very robust and mature.</p>
<p>RAP 2.0 will be <a href="http://eclipse.org/rap/downloads/">published</a> on Monday around noon CET.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Countdown+%284%2F5%29&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/&amp;t=RAP+2.0+Countdown+%284%2F5%29" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/08/rap-2-0-countdown-45/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Countdown (3/5)</title>
		<link>http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 10:01:19 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14067</guid>
		<description><![CDATA[RAP 2.0 is approaching and I want to explain the most important changes in this short blog series. The key innovation of RAP 2.0 is its support for alternative clients. Today I&#8217;d like to introduce you to the new Client API that lets you find out which client is currently connected. This interface can also <a href="http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>RAP 2.0 is approaching and I want to explain the most important changes in this <a href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/">short blog series</a>. The key innovation of RAP 2.0 is its support for alternative clients. Today I&#8217;d like to introduce you to the new <em>Client</em> API that lets you find out which client is currently connected. This interface can also be used to access some of the client&#8217;s specific features.</p>
<h2>Know Your Client</h2>
<p>When developing a RAP application, you normally don’t have to know which client is connected. SWT screens written for a native client can be accessed with the default web client just as well. You can check the <em>Display</em> for the client&#8217;s display resolution and adapt your SWT layout to the available screen estate (the client area).</p>
<p>However,  in some cases you may want to make certain adjustments to your application, depending on the client. In this case, you can find out what client is connected to the current UI session by calling <em>UISession.getClient()</em> (you can also use the shortcut <em>RWT.getClient()</em>). The result is an instance of the interface <em><a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/client/Client.html">Client</a></em>. When accessed with the web client, it will be an instance of <em><a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/client/WebClient.html">WebClient</a></em>, for <a href="http://developer.eclipsesource.com/tabris/">Tabris</a>, it will be a <em><a href="https://github.com/eclipsesource/tabris/blob/master/com.eclipsesource.tabris/src/com/eclipsesource/tabris/TabrisClient.java">TabrisClient</a></em>.</p>
<h2>Accessing Client Features</h2>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/service-stores.png"><img class="aligncenter size-full wp-image-14068" alt="service stores RAP 2.0 Countdown (3/5)" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/service-stores.png" width="700" height="321" title="RAP 2.0 Countdown (3/5)" /></a></p>
<p>Most clients can provide information about their timezone and locale, some can also provide their geo position. Accessing this information can help to supply the user with more appropriate information. To make this information available, we could have added methods like <em>getTimeZone()</em> or <em>getGeoPosition()</em> to the Client interface. However, mobile clients can offer a lot more services, such as scanning bar codes, taking photos, or making phone calls. Moreover, some services are not specific to one client but can be provided by different clients. Adding methods for every possible feature to the Client interface was clearly not an option but we also wanted to avoid code that looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> client instance of ThisClient <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ThisClient<span style="color: #009900;">&#41;</span> client<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doThis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> client instance of ThatClient <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ThatClient<span style="color: #009900;">&#41;</span> client<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doThat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> client instance of SomeOtherClient <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>SomeOtherClient<span style="color: #009900;">&#41;</span> client<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doSomethingElse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  …</pre></td></tr></table></div>

<h3>The Service Locator Pattern</h3>
<p>Using the <a href="http://martinfowler.com/articles/injection.html#UsingAServiceLocator">Service Locator</a> pattern allowed us to come up with an extensible API. Every client implements the method <em>getService( ClientService )</em>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">GeoLocation location <span style="color: #339933;">=</span> client.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span> GeoLocation.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> location <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
  location.<span style="color: #006633;">getLatitude</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Using this method is like going to a hardware store to buy a tool that you need. If you&#8217;re lucky, the item is in stock, otherwise you walk out with empty hands. If the client cannot provide the requested service, there&#8217;s nothing we can do. Whether a service is available or not depends on the client implementation, and it may even depend on the client device (does it have a camera?). The RAP API contains only the hardware store (the <em>Client</em>) and those tools that the default web client can provide. Alternative clients may implement these services, but they can also provide their own specific service interfaces.</p>
<p>Employing a service locator started as an experiment. There is some <a href="http://blog.gauffin.org/2012/09/service-locator-is-not-an-anti-pattern/">controversy</a> about this pattern and I’m sure there are plenty of ways to misuse it. However, since we introduced the client services, we found much more use cases than we initially expected. The WebClient already supports <a href="http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/">six different services</a> (<a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/client/service/ClientInfo.html">ClientInfo</a>, <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/client/service/JavaScriptExecutor.html">JavaScriptExecutor</a>, <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/client/service/JavaScriptLoader.html">JavaScriptLoader</a>, just to name a few), and more will follow. In Tabris, there are plenty of client services, such as AppLauncher, GeoLocation, Camera, etc. (some of them are not implemented as client services yet as they predate this API).</p>
<p>So it feels like a good choice. I can’t wait to see more stores opening along that road!</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Countdown+%283%2F5%29&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/&amp;t=RAP+2.0+Countdown+%283%2F5%29" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/06/rap-2-0-countdown-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Countdown (2/5)</title>
		<link>http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 11:08:52 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14022</guid>
		<description><![CDATA[There’s only one week to go until the RAP 2.0 release. In this short blog series, I’d like to introduce you to the most important changes. Besides the new protocol, the main theme in RAP 2.0 is the consolidation of our APIs. After six years of RAP 1.x, it was time for a cleanup. In this <a href="http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>There’s only one week to go until the <a href="http://eclipse.org/rap/noteworthy/2.0/">RAP 2.0</a> release. In this short blog series, I’d like to introduce you to the most important changes. Besides the <a href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/">new protocol</a>, the main theme in RAP 2.0 is the consolidation of our APIs. After six years of RAP 1.x, it was time for a cleanup. In this post, I will explain the foundation of the RAP 2.0 API.</p>
<h2>The Pillars of the RAP 2.0 API</h2>
<p>In a multi-user and multi-application environment, you have to distinguish between different scopes to avoid mixing up your user’s data. There has been some confusion around the session scope in RAP 1.x. In the new API, the scopes are more explicit as they&#8217;re represented by interfaces. The two most important interfaces that you should be familiar with are <em>UISession</em> and <em>ApplicationContext</em>. However, let’s start with the basics, the servlet container.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/RAP-API.png"><img class="aligncenter size-full wp-image-14023" alt="RAP API RAP 2.0 Countdown (2/5)" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/RAP-API.png" width="685" height="507" title="RAP 2.0 Countdown (2/5)" /></a></p>
<h3>ServletContext and ApplicationContext</h3>
<p>RAP runs on a standard servlet container. A servlet container hosts a number of webapps, each containing servlets and static resources. All servlets of a webapp share the same <a href="http://docs.oracle.com/javaee/5/api/javax/servlet/ServletContext.html">ServletContext</a>. That is, the ServletContext represents a web application.</p>
<p>A RAP application is represented by an <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/service/ApplicationContext.html">ApplicationContext</a>. Also because it&#8217;s a web application in itself, this ApplicationContext is bound to a ServletContext. You can run multiple RAP applications in parallel, e.g. in different web applications, or even different servlet containers in the same VM (e.g. different Jetty instances on different ports). ServletContext and the RAP ApplicationContext have a <em>1 to 1 relationship</em>. The actual instance of ApplicationContext can be obtained from <em>RWT.getApplicationContext()</em>.</p>
<p>The ApplicationContext provides access to application-scoped framework services such as the ResourceManager (actually, <em>RWT.getResourceManager()</em> is now just a shortcut for <em>RWT.getApplicationContext().getResourceManager()</em>). It can also be used to store arbitrary objects as attributes. Whenever you need to share information application-wide, you should store them in the ApplicationContext, rather than keeping them statically.</p>
<h3>HttpSession and UISession</h3>
<p>When a user connects to a web application, the servlet container creates an <a href="http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpSession.html">HttpSession</a>. To recognize the user in subsequent requests, the session ID is usually stored in a session cookie. The <em>HttpSession</em> is valid until either the browser is closed or it is left unattended for a configurable time (the session timeout).</p>
<p>For every instance of a RAP UI, a separate <em>UISession</em> is created. That means that when a user accesses an entry point, that&#8217;s a new UISession. When the user reloads the page in the browser, that&#8217;s also a new UISession – but the HTTPSession remains the same. There is a <em>1 to many relationship</em> between HTTPSesssion and the RAP UISession.</p>
<p>The current instance of a UISession is available from <em>RWT.getUISession()</em>. Just like the ApplicationContext, you can use the UISession to store attributes (actually, UISession replaces the old SessionStore). If you need to share information that is related to the EntryPoint instance (e.g. a selection that the user has made), keep it in the UISession. User-related information should rather be stored in the HttpSession, because it survives a single UISession.</p>
<h3>Better Support for Testing</h3>
<p>One advantage of the new API structure is that it facilitates test-driven development. In contrast to the <em>RWT</em> class, the new interfaces UISession and ApplicationContext provide non-static methods to access framework services. Hence, these instances can be replaced with mocks in a unit test. We also plan to add methods to the test fixture that allow framework instances to be replaced with mocks.</p>
<h3>Better Multi-Tab Support</h3>
<p>I particularly like the new structure because it will simplify adding better Multi-Tab support in RAP. When a user opens a RAP application in multiple browser tabs, there are of course different UI sessions but they share the same HttpSession because cookies are shared across all browser tabs. At the moment, RAP does not handle this particular case and you need a <a href="http://wiki.eclipse.org/RAP/FAQ#How_to_run_a_RAP_application_in_multiple_browser_tabs.2Fwindows.3F">workaround</a>. RAP 2.1 (June 2013) will include multi-tab support out-of-the-box. With this change, a single HttpSession can have multiple UISessions at the same time.</p>
<p>You can find more details about the new API in the <a href="http://eclipse.org/rap/developers-guide/index.php?version=2.0">RAP developer&#8217;s guide</a>. If you update an existing application to RAP 2.0, also check out the <a href="http://eclipse.org/rap/noteworthy/2.0/migration-guide/">migration guide</a>.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Countdown+%282%2F5%29&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/&amp;t=RAP+2.0+Countdown+%282%2F5%29" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/04/rap-2-0-countdown-25/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 Countdown (1/5)</title>
		<link>http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/</link>
		<comments>http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/#comments</comments>
		<pubDate>Fri, 01 Feb 2013 10:05:58 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=13915</guid>
		<description><![CDATA[After more than six years of RAP 1.x, we will release version 2.0 on February 11. As the version number suggests, there are some substantial changes in this release. During the last few days before the release, I will guide you through the most important changes in RAP 2.0. It’s not so much about new <a href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>After more than six years of <a href="http://eclipse.org/rap">RAP</a> 1.x, we will release <a href="http://eclipse.org/rap/noteworthy/2.0/">version 2.0</a> on February 11. As the version number suggests, there are some substantial changes in this release. During the last few days before the release, I will guide you through the most important changes in RAP 2.0. It’s not so much about new features, but also about some realignments we made and the ideas behind them.</p>
<h2>Remote – The New “R” in RAP</h2>
<p>At the very core of RAP, there is an implementation of the <a href="http://c2.com/cgi/wiki?HalfObjectPlusProtocol">“Half Object plus Protocol” (HOPP)</a> pattern. The widgets in RAP are cut in half, one half is located on the server, the other on the client. Both halves are connected by a protocol. One big advantage of this design is that the application doesn’t have to take care of the client/server communication at all, the platform covers this.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/half-objects.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/half-objects.png" alt="half objects RAP 2.0 Countdown (1/5)" width="601" height="215" class="aligncenter size-full wp-image-14008" title="RAP 2.0 Countdown (1/5)" /></a></p>
<p>RAP always had half objects but the protocol part was missing. The communication was based on undocumented JavaScript commands and HTTP parameters. Starting with RAP 1.5, we migrated the entire platform to a new, open JSON protocol. This protocol opens the platform for alternative clients, and those clients already exist. With <a href="http://developer.eclipsesource.com/tabris/">Tabris</a> we provide native clients for mobile devices with iOS and Android. For me the best proof that the protocol works is that although the Tabris team works next door, there’s very little need for technical discussions. In fact, the protocol is the interface between us.</p>
<p>Writing a RAP client isn&#8217;t rocket science, all you need is an HTTP client, a JSON parser, and part of a graphics library for displaying widgets. You don&#8217;t have to implement the full widget set, only those widgets that your applications require. We&#8217;ve already seen some PoC clients and we can&#8217;t wait to see RAP on more devices.</p>
<p>The RAP protocol has been under development for quite a while and has been simplified a couple of times. Let’s have a quick look at the structure of client and server exchange JSON messages. A message consists of a header part and a list of operations:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="js" style="font-family:monospace;">{
 head: { … },
 operations: [ … ]
}</pre></td></tr></table></div>

<p>The operations are executed by the receiver one by one. There are six types of operations: <em>create</em> &#8211; to create a remote object, <em>set</em> &#8211; to set one or more properties on the remote object, and <em>destroy</em> &#8211; to well, you guessed it. Besides <em>set</em> there is also <em>call</em> to call a method on a remote object. In addition, finally <em>listen</em> and <em>notify</em> to exchange events. Every remote object is identified by an id and every operation addresses exactly one target object. That is basically it. To give an example, here&#8217;s a message that creates a Button with a Selection listener:</p>
<pre lang="js" class="lang-js">
{
  "head": {
    "requestCounter": 1
  },
  "operations": [
    [ <strong>"create"</strong>, "w4", "rwt.widgets.Button", {
        "parent": "w2",
        "style": [ "PUSH" ],
        "bounds": [ 5, 68, 131, 32 ],
        "text": "I am a button" } ],
    [ <strong>"listen"</strong>, "w4", { "Selection": true } ]
  ]
}
</pre>
<p>You can see that the create operation already contains the initial properties for the Button. With the listen operation, the client is informed that there are Selection listeners attached. When the button is pressed, the client will send this message to the server:</p>
<pre lang="js" class="lang-js">
{
  "head": {
    "requestCounter": 1
  },
  "operations": [
    [ <strong>"notify"</strong>, "w4", "Selection", {
        "shiftKey": false,
        "ctrlKey": false,
        "altKey": false
      } ],
    [ <strong>"set"</strong>, "w1", {
        "cursorLocation": [ 121, 104 ],
        "focusControl": "w4"
      } ]
  ]
}
</pre>
<p>A more detailed description of the protocol syntax can be found in <a href="http://wiki.eclipse.org/RAP/Protocol">our wiki</a>.</p>
<p>It’s important to point out that although most half objects in RAP are widgets, there are no UI specifics in the protocol. It is also used to synchronize service objects like the script executor or the geo location service in Tabris. The protocol no longer depends on HTTP. Even though RAP is still bound to HTTP, a future version could additionally work with other protocols.</p>
<p>With the completion of the protocol and the new RAP clients we decided to <a href="http://eclipsesource.com/blogs/2012/11/26/rap-becomes-the-remote-application-platform/">rename the project</a> to “Remote Application Platform”. So the “R” in RAP now stands for “remote” and that&#8217;s how we see RAP: as a versatile platform for modular remote applications of all scales. These range from full-blown business applications with forms and tables in a web browser to minimal apps on a handheld device. All with the same programming model.</p>
<p>In my next post, I will introduce you to the interfaces that constitute the pillars of the RAP 2.0 API.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+Countdown+%281%2F5%29&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/&amp;t=RAP+2.0+Countdown+%281%2F5%29" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RAP on Grails</title>
		<link>http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/</link>
		<comments>http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 18:18:37 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=12711</guid>
		<description><![CDATA[Last week Benjamin Wolff, a long-known RAP fellow, announced that he has just created an RWT plug-in for Grails. Grails is a ready-to-use web framework with some great featues such as a persistence layer with ORM, dependency injection, unit testing, and advanced web APIs. It comes with a command line that helps you create and <a href="http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Last week <a href="https://github.com/bwolff">Benjamin Wolff</a>, a long-known RAP fellow, <a href="http://www.eclipse.org/forums/index.php/t/440326/" title="RWT meets Grails">announced</a> that he has just created an <a href="http://grails.org/plugin/rwt">RWT plug-in for Grails</a>.</p>
<p><center><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/rap-grails1.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/rap-grails1.png" alt="rap grails1 RAP on Grails" title="RAP on Grails" width="353" height="231" class="aligncenter size-full wp-image-12720" /></a></center></p>
<p><a href="http://grails.org/">Grails</a> is a ready-to-use web framework with some great featues such as a persistence layer with ORM, dependency injection, unit testing, and advanced web APIs. It comes with a command line that helps you create and run web applications and can also export them as <em>.war</em> files. Grails is based on <a href="http://groovy.codehaus.org/">Groovy</a>, and since Groovy runs on the JVM, it allows to leverage existing Java libraries–such as the RAP Widget Toolkit.</p>
<p>Benjamin says that he was “always missing the nice API and widgets that RAP provides” when working with Grails. So he tried to integrate RWT into a Grails application. With the <a href="http://eclipsesource.com/blogs/2012/05/09/the-new-application-api-in-rap/">new decoupled design introduced in RAP 1.5</a>, this was an easy task for someone who knows both RAP and Grails.</p>
<p>After this worked out well, he decided to make his integration available for others as a <a href="http://grails.org/plugin/rwt">Grails plug-in</a>. Now you can start writing RWT applications in Grails right away by simply including a plug-in. An RWT application is set up the Grails way, using a configuration:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">rwt <span style="color: #009900;">&#123;</span>
  entrypoints <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Configuration of an entry point named 'hello', the relative URL path will be '/hello'</span>
    hello <span style="color: #009900;">&#123;</span>
      bean <span style="color: #339933;">=</span> <span style="color: #0000ff;">'helloEntryPointService'</span> <span style="color: #666666; font-style: italic;">// The name of the entry point bean (required)</span>
      pageTitle <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello RWT!'</span> <span style="color: #666666; font-style: italic;">// The browser title that will be displayed (optional)</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can find a simple example RWT application using some Grails features on the <a href="http://bwolff.github.com/grails-rwt/guide/gettingStarted.html">GitHub page of the RWT plug-in</a>. As you see, the plug-in not only provides plain RWT, but also JFace, making it easy to bind complex data to your UI. And Grails&#8217; O/R mapping and dependency injection make it even simpler.</p>
<p>This is just the first release of the plug-in. Benjamin is planning some improvements and is interested in any feedback. At the moment, the plug-in incorporates RWT in the latest version <a href="http://eclipse.org/rap/noteworthy/2.0/?build=M3">2.0M3</a>. But when RAP 2.0 is released in February 2013, there will be a update of this plug-in available that includes the RAP artifacts directly from Maven.</p>
<p>We are always happy to see RAP being used in new contexts, and in particular it&#8217;s great to see that our decoupling in RAP 1.5 proves helpful for others.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+on+Grails&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/&amp;t=RAP+on+Grails" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/11/28/rap-on-grails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 M3 is available</title>
		<link>http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/</link>
		<comments>http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/#comments</comments>
		<pubDate>Fri, 16 Nov 2012 15:14:30 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[kepler]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=12557</guid>
		<description><![CDATA[The RAP team has been working hard over the last weeks and made another milestone build for RAP 2.0 available today. RAP 2.0 M3 contains a brand new event system implementation that allowed us to get rid of some old bugs and to attach listeners more precisely in the protocol. Many RAP developers will like <a href="http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://eclipse.org/rap">RAP</a> team has been working hard over the last weeks and made another milestone build for RAP 2.0 available today.</p>
<p>RAP 2.0 M3 contains a brand new event system implementation that allowed us to get rid of some old bugs and to attach listeners more precisely in the protocol. Many RAP developers will like the new <em>Client</em> API that provides access to client features through a service locator interface. With this new interface, RAP finally offers a public API to <em>execute JavaScript on the client</em>, using the new <em>JavaScriptExecutor</em> service (check <a href="http://eclipsesource.com/blogs/2012/10/17/javascriptexecutor-is-now-api/">Ivan&#8217;s post</a> for details):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">JavaScriptExecutor executor <span style="color: #339933;">=</span> RWT.<span style="color: #006633;">getClient</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span> JavaScriptExecutor.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> executor <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  executor.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;alert( <span style="color: #000099; font-weight: bold;">\&quot;</span>Hello World!<span style="color: #000099; font-weight: bold;">\&quot;</span> );&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Some public classes and interfaces, most notably the resource manager, have been cleaned up in M3 and made ready for RAP 2.0. After 6+ years of development, RAP&#8217;s API simply needs some cleanup. But don&#8217;t worry, we will keep the number of breaking changes low and let deprecated classes in place where possible to ease the migration. And we&#8217;re maintaining a <a href="http://eclipse.org/rap/noteworthy/2.0/migration-guide/">RAP 2.0 migration guide</a> to assist you.</p>
<p>For a more detailed list of changes and bugfixes in this milestone, have a look at our <a href="http://eclipse.org/rap/noteworthy/2.0/?build=M3">New and Noteworthy</a> page. The build is available for download on the project&#8217;s <a href="http://eclipse.org/rap/downloads/">download page</a> and is also included in the Eclipse Kepler repository: <a href="http://download.eclipse.org/releases/kepler/">http://download.eclipse.org/releases/kepler/</a>.</p>
<p>RAP 2.0 is going to be released in February 8, 2013. For next year&#8217;s simultaneous release, Eclipse Kepler, we&#8217;ll plan a follow-up release. We hope you are as excited about RAP 2.0 as we are and the migration goes smooth for you. Let us know what you think!</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+M3+is+available&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/&amp;t=RAP+2.0+M3+is+available" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/11/16/rap-2-0-m3-is-available/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 M2 &#8211; JSON protocol migration complete</title>
		<link>http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/</link>
		<comments>http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/#comments</comments>
		<pubDate>Fri, 05 Oct 2012 10:03:51 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[kepler]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=11305</guid>
		<description><![CDATA[During the last weeks the RAP team has been busy lifting RAP&#8217;s client-to-server communication to the JSON protocol. That was a lot of work, and we finished it just in time for Kepler M2. With this milestone, the migration to the new protocol is eventually complete. All communication uses JSON now, and no undocumented HTTP <a href="http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>During the last weeks the <a href="http://eclipse.org/rap">RAP</a> team has been busy lifting RAP&#8217;s client-to-server communication to the JSON protocol. That was a lot of work, and we finished it just in time for Kepler M2. With this milestone, the migration to the new protocol is eventually complete. All communication uses JSON now, and no undocumented HTTP parameters are involved anymore.</p>
<p><center><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/RAP-Firebug-JSON.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/RAP-Firebug-JSON.png" alt="RAP Firebug JSON RAP 2.0 M2   JSON protocol migration complete" title="RAP JSON protocol in Firebug" width="600" height="301" class="aligncenter size-full wp-image-11309" /></a></center></p>
<p>In RAP 1.5, <a href="http://eclipsesource.com/blogs/2011/12/16/eclipse-juno-m4-rap-speaks-json/">we replaced</a> the communication between <em>server and client</em> with a new, documented <a href="http://wiki.eclipse.org/RAP/Protocol">JSON-based format</a>. Now, the <em>client</em> uses the same format to report changes to the server.</p>
<p>See the <a href="http://eclipse.org/rap/noteworthy/2.0/?build=M2">new and noteworthy</a> for a complete list of changes and bug fixes in 2.0 M2. The milestone build is available on our <a href="http://eclipse.org/rap/downloads/">download site</a> and in the <a href="http://download.eclipse.org/releases/kepler/">Kepler repository</a>. If you&#8217;re migrating from RAP 1.x, please also check out our <a href="http://eclipse.org/rap/noteworthy/2.0/migration-guide/">RAP 2.0 migration guide</a>.</p>
<p>For the next milestone, we plan some new features like public API to access client information such as the timezone and to execute Javascript on the client. We&#8217;re also started to rework the event system in RWT to get rid of some nasty bugs related to events and listeners. M3 will be available on November 16.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+M2+%26%238211%3B+JSON+protocol+migration+complete&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/&amp;t=RAP+2.0+M2+%26%238211%3B+JSON+protocol+migration+complete" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
