<?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; OSGi</title>
	<atom:link href="http://eclipsesource.com/blogs/tag/osgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsesource.com/blogs</link>
	<description>Eclipse Equinox OSGi</description>
	<lastBuildDate>Fri, 18 May 2012 15:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The new Application API in RAP</title>
		<link>http://eclipsesource.com/blogs/2012/05/09/the-new-application-api-in-rap/</link>
		<comments>http://eclipsesource.com/blogs/2012/05/09/the-new-application-api-in-rap/#comments</comments>
		<pubDate>Wed, 09 May 2012 12:58:56 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[juno]]></category>
		<category><![CDATA[new & noteworthy]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=7640</guid>
		<description><![CDATA[RAP 1.5 includes a new API to define and start RAP applications programmatically (up to RAP 1.4, this was only possible using Eclipse extensions or web.xml properties). With this new API, RAP can also be used for leightweight applications based on OSGi, but without the entire Eclipse stack, even with other OSGi containers like Apache [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclipse.org/rap/downloads/1.5/">RAP 1.5</a> includes a new API to define and start RAP applications programmatically (up to RAP 1.4, this was only possible using Eclipse extensions or web.xml properties). With this new API, RAP can also be used for leightweight applications based on OSGi, but without the entire Eclipse stack, even with other OSGi containers like <a href="http://felix.apache.org/">Apache Felix</a>. Also traditional web applications, that use RWT as a library without OSGi, benefit from the new API.</p>
<p>This API contains a couple of interfaces that we had trouble to find suitable names for. If you&#8217;ve used this API already you know that there were two interfaces side-by-side in the same package with almost the same name: <em>ApplicationConfigurator</em> and <em>ApplicationConfiguration</em>. Even though these names seemed to be correct, it <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=369942">turned out</a> that they were hard to tell apart, and if mixed up in a service declaration, the application did not start, without any warning.</p>
<p>So we reviewed the case and eventually came up with better names for the interfaces without changing the structure. Let me explain the new API and our reasoning behind it.</p>
<h2>Implementing an ApplicationConfiguration</h2>
<p>A RAP application consists of various parts, such as entrypoints, URL mappings, themes, service handlers, etc. All these parts constitute an <em>ApplicationConfiguration</em>. The configuration is like the blueprint for an application. Based on an ApplicationConfiguration, the framework can create and start an application instance. There can be more than one application instances at runtime, e.g. running on different network ports or different servlet contexts.</p>
<p>Hence, when you write a RAP application, you have to provide an <em>ApplicationConfiguration</em>.</p>
<p>An <em>ApplicationConfiguration</em> is used to configure an application before it is started. For this step, RAP follows a callback approach to leave the responsibility for creating and starting the application with the framework. Therefore, the configuration must actively configure the application. To do so, it has one method <em>configure( Application )</em>. The framework provides a reference to the created <em>Application</em> as a parameter to this method. Here&#8217;s how a simple implementation looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleConfiguration <span style="color: #000000; font-weight: bold;">implements</span> ApplicationConfiguration <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> configure<span style="color: #009900;">&#40;</span> Application application <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    application.<span style="color: #006633;">addEntryPoint</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;/simple&quot;</span>, SimpleEntryPoint.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    application.<span style="color: #006633;">addEntryPoint</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;/other&quot;</span>, AnotherEntryPoint.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Registering the ApplicationConfiguration</h2>
<p>When using OSGi, the <em>ApplicationConfiguration</em> can be registered as a service. I&#8217;d recommend using OSGi declarative services (DS) like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scr:component</span> <span style="color: #000066;">xmlns:scr</span>=<span style="color: #ff0000;">&quot;http://www.osgi.org/xmlns/scr/v1.1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;implementation</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.example.SimpleConfiguration&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provide</span> <span style="color: #000066;">interface</span>=<span style="color: #ff0000;">&quot;org.eclipse.rwt.application.ApplicationConfiguration&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scr:component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The bundle <em>org.eclipse.rap.rwt.osgi</em> will automatically start this application on every available HttpService. When using Equinox, don&#8217;t forget to also include the <em>org.eclipse.equinox.ds</em> bundle. You can find an example of a simple RAP application using DS on <a href="https://github.com/ralfstx/rap-helpers/tree/master/example.rwt.simple">github</a>.</p>
<p>When using RWT as a library in a traditional web application, i.e. without OSGi, you can register your <em>ApplicationConfiguration</em> in the <em>web.xml</em> by adding a <em>context-param</em> with the fully qualified class name of the implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.rap.applicationConfiguration<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.example.ExampleConfiguration<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You can always look up the param-name in the constant <em>ApplicationConfiguration#CONFIGURATION_PARAM</em>. The RAP FAQ has a <a href="http://wiki.eclipse.org/RAP/FAQ#How_do_I_develop_an_RWT_standalone_application_with_RAP_.3E.3D_1.5">complete example</a>.</p>
<h2>Starting an Application</h2>
<p>When an ApplicationConfiguration has been registered as described above, the application is automatically started by the framework. Alternatively, it can also be started explicitly using an <em>ApplicationRunner</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ApplicationConfiguration configuration <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ApplicationRunner runner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ApplicationRunner<span style="color: #009900;">&#40;</span> configuration, servletContext <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
runner.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There&#8217;s a <a href="http://martinfowler.com/bliki/TwoHardThings.html">saying</a> that there were only two hard things in computer science, cache invalidation and naming things. I don&#8217;t happen to know what&#8217;s so tricky about cache invalidation <img src='http://eclipsesource.com/blogs/wp-includes/images/smilies/icon_wink.gif' alt="icon wink The new Application API in RAP" class='wp-smiley' title="The new Application API in RAP" />  But I can hardly remember any <em>technical</em> problem that caused me as much of a headache as these few names did. I hope that after so many discussions, this new API will prove to be simple to understand and to use.</p>
<p>Thanks to <a href="http://www.codeaffine.com/author/fappel/">Frank</a>, <a href="http://www.codeaffine.com/author/rherrmann/">Rüdiger</a>, <a href="http://eclipsesource.com/blogs/author/hstaudacher/">Holger</a> and <a href="http://eclipsesource.com/blogs/author/jordi/">Jordi</a> for great discussions and especially to Frank for contributing this new API to RAP!</p>
<p>The changes are part of RAP 1.5M7, published this Friday, May 11.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/05/09/the-new-application-api-in-rap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An OSGi JAX-RS connector Part 1: Publishing REST services</title>
		<link>http://eclipsesource.com/blogs/2012/01/23/an-osgi-jax-rs-connector-part-1-publishing-rest-services/</link>
		<comments>http://eclipsesource.com/blogs/2012/01/23/an-osgi-jax-rs-connector-part-1-publishing-rest-services/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 07:48:24 +0000</pubDate>
		<dc:creator>Holger Staudacher</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[jax-rs]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restlet]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6959</guid>
		<description><![CDATA[In a recent blog post Peter Kriens commented that the OSGi service model is as important as object-orientation. I feel the same &#8211; I don&#8217;t want to write software without this concept anymore. But for me, the service model only makes sense when it&#8217;s used together with the modularity OSGi provides. I think the modularisation [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent blog post Peter Kriens commented that <a href="http://www.osgi.org/blog/2012/01/moving-on.html">the OSGi service model is as important as object-orientation</a>. I feel the same &#8211; I don&#8217;t want to write software without this concept anymore. But for me, the service model only makes sense when it&#8217;s used together with the modularity <a href="http://www.osgi.org/">OSGi</a> provides. I think the modularisation layer is the greatest advantage of the OSGi platform and the services are really only there to simplify the communication between modules.</p>
<p>When it comes to developing a <a href="http://tomayko.com/writings/rest-to-my-wife">REST API</a> with Java, this advantage is missing in most of today&#8217;s libraries (e.g. <a href="http://www.restlet.org/">Restlet</a> or <a href="http://jersey.java.net/">Jersey</a>), because the <a href="http://cr.openjdk.java.net/~mr/jigsaw/notes/jigsaw-big-picture-01">Java language still lacks modularity</a>. But especially for the design of a REST API this concept can be a great benefit, because it overcomes the limitation of only being able to separate REST services by url and Java packages. With modularity the service implementations can be separated into modules which improves the maintainability and the beauty of the whole system a lot.</p>
<p>A few months ago I discovered <a href="http://jsr311.java.net/">JAX-RS</a> for developing REST services. (Before that I used Restlet.) I have to say that the <a href="http://jsr311.java.net/nonav/releases/1.1/index.html">JAX-RS API</a> makes it really easy to develop REST services. <a href="http://www.vogella.de/articles/REST/article.html">See this article for a how-to</a>. A reference implementation of this API is <a href="http://jersey.java.net/">Jersey</a>. The cool thing about this implementation is that it plays really well together with the<a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/HttpService.html"> OSGi HttpService</a> and it ships as bundles. In this way we have the option to actively deploy REST services into the HttpService. But is this how we want to publish REST services? To me, it&#8217;s not!</p>
<p>In my ideal world I would write my @Path annotated Pojos and publish them as OSGi services. That&#8217;s it. The runtime should take care of publishing and service wiring. Sadly, Jersey has no built-in feature for that. This is the reason I wrote a little <a href="https://github.com/hstaudacher/osgi-jax-rs-connector">OSGi-JAX-RS connector</a>. The only thing the connector does is that it publishes OSGi services as REST services using JAX-RS. Of course, there are <a href="http://wiki.eclipse.org/EIG:Getting_Started_with_OSGi_Remote_Services">OSGi remote services</a>, but using them does not allow the use of JAX-RS the way I&#8217;d prefer, namely as a lightweight additional bundle.</p>
<p>You can find the connector in <a href="https://github.com/hstaudacher/osgi-jax-rs-connector">GitHub</a>. To make it work simply install it into your OSGi instance by using <a href="http://hstaudacher.github.com/osgi-jax-rs-connector/plugins/com.eclipsesource.jaxrs.connector_1.0.0.201201191236.jar">this jar</a>. (You&#8217;ll also find a <a href="http://hstaudacher.github.com/osgi-jax-rs-connector">p2 repository</a> there). That&#8217;s it. The only thing you have to take care of is writing the REST services like the one in this example.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Path<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;/osgi-jax-rs&quot;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleService <span style="color: #009900;">&#123;</span>
&nbsp;
  @GET
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> seyHello<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;">return</span> <span style="color: #0000ff;">&quot;JAX-RS and OSGi are a lovely couple.&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The activator can then look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Activator</span> <span style="color: #000000; font-weight: bold;">implements</span> BundleActivator <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> ServiceRegistration<span style="color: #339933;">&lt;?&gt;</span> registration<span style="color: #339933;">;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span> BundleContext context <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    ExampleService exampleService <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ExampleService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    registration <span style="color: #339933;">=</span> context.<span style="color: #006633;">registerService</span><span style="color: #009900;">&#40;</span> ExampleService.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, exampleService, <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> stop<span style="color: #009900;">&#40;</span> BundleContext context <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    registration.<span style="color: #006633;">unregister</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: #009900;">&#125;</span></pre></div></div>

<p>Further instructions can be found in the <a href="https://github.com/hstaudacher/osgi-jax-rs-connector/blob/master/README.md">README</a> of the git repository. It also contains two examples for using this connector with and without declarative services. In the second part of this blog series I will show you how to configure the services using the <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html">OSGi Configuration Admin Service</a> and publish services on different ports within the same OSGi instance. I hope you enjoy this connector as much as I do.</p>
<p><a href="http://twitter.com/hstaudacher"><img src="http://download.eclipsesource.com/~hstaudacher/followme.png" title="Follow @hstaudacher" width="191" height="58" border="0" alt="followme An OSGi JAX RS connector Part 1: Publishing REST services" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/01/23/an-osgi-jax-rs-connector-part-1-publishing-rest-services/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Introducing restfuse &#8211; a JUnit Extension to test REST APIs</title>
		<link>http://eclipsesource.com/blogs/2011/11/14/introducing-restfuse-a-junit-extension-to-test-rest-apis/</link>
		<comments>http://eclipsesource.com/blogs/2011/11/14/introducing-restfuse-a-junit-extension-to-test-rest-apis/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 08:01:11 +0000</pubDate>
		<dc:creator>Holger Staudacher</dc:creator>
				<category><![CDATA[craftsmanship]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restfuse]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6670</guid>
		<description><![CDATA[For several projects at EclipseSource we are creating REST APIs. I&#8217;m involved in most of them and there is one thing that bothers me with every project. That is, testing. I mean, of course we are writing our unit tests first and we mock our services to get fast unit tests, but at some point [...]]]></description>
			<content:encoded><![CDATA[<p>For several projects at <a href="http://eclipsesource.com/">EclipseSource</a> we are creating <a href="http://en.wikipedia.org/wiki/Representational_state_transfer">REST APIs</a>. I&#8217;m involved in most of them and there is one thing that bothers me with every project. That is, testing. I mean, of course we are writing our unit tests first and we mock our services to get fast unit tests, but at some point you also have to make sure that the whole system works with integration tests. And, when writing integration tests for REST APIs in Java, as far as I know, there are currently only two solutions.</p>
<p>The first one is to write plain <a href="http://junit.org">JUnit</a> tests and do all the requests yourself within the test methods (maybe with the help of utilities). The other option is to use a library called <a href="http://code.google.com/p/rest-assured/">rest-assured</a>. This library provides a kind of DSL for testing REST APIs. You can write your tests with JUnit and use <a href="http://eclipsesource.com/blogs/2011/09/19/effective-mockito-part-1/">mockito</a>-like syntax to send a request and test the response. But this doesn&#8217;t feel like the right solution, because you always have to configure your request with real Java code within your test method. I would prefer a solution where I can simply configure the request using something like annotations and just execute the test after the request is sent.</p>
<p>Another thing that bugs me are asynchronous services. When it comes to handling asynchronous services you always have two options: callbacks or polling. How can I test those services? For polling it&#8217;s easier &#8211; you can loop the request code &#8211; but does this sound right to you? For callbacks you have to open a server, again within your test method or before. It seems there are no cool solutions for this right now &#8211; even rest-assured can&#8217;t handle these services very well. That&#8217;s why I took a little time and tried to solve these problems. The result is a small library called <a href="http://restfuse.com/">restfuse</a>.</p>
<p>Restfuse is a JUnit extension. It introduces an annotation called <a href="http://restfuse.com/doc/index.html?com/eclipsesource/restfuse/annotation/HttpTest.html"><code>@HttpTest</code></a> which can be used to configure a request. The request is sent before the annotated method is executed as a test method. The response is then injected into the test object and can be used within the test method. It also provides some new asserts like assertNotFound or <code>assertOk</code> to test response codes. A simple <code>@HttpTest</code> looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@RunWith<span style="color: #009900;">&#40;</span> HttpJUnitRunner.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RestfuseTest <span style="color: #009900;">&#123;</span>
&nbsp;
  @Rule
  <span style="color: #000000; font-weight: bold;">public</span> Destination destination <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Destination<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;http://restfuse.com&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
  @<span style="color: #003399;">Context</span>
  <span style="color: #000000; font-weight: bold;">private</span> Response response<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will be injected after every request</span>
&nbsp;
  @HttpTest<span style="color: #009900;">&#40;</span> method <span style="color: #339933;">=</span> <span style="color: #003399;">Method</span>.<span style="color: #006633;">GET</span>, path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkRestfuseOnlineStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    assertOk<span style="color: #009900;">&#40;</span> response <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>  
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And of course, it also solves the problem with asynchronous services by introducing two annotations called <a href="http://restfuse.com/doc/index.html?com/eclipsesource/restfuse/annotation/Callback.html"><code>@Callback</code></a> and <a href="http://restfuse.com/doc/index.html?com/eclipsesource/restfuse/annotation/Poll.html"><code>@Poll</code></a> which can be used together with the @HttpTest annotation. For more information on these tests for asynchronous services <a href="http://restfuse.com/asynchron/">take a look at the restfuse site</a>.</p>
<p><a href="http://restfuse.com">Restfuse</a> is open source, licensed under the <a href="http://www.eclipse.org/legal/epl-v10.html">EPL v &#8211; 1.0</a> and is hosted at <a href="https://github.com/eclipsesource/restfuse">github</a>. The 1.0 version is also in the <a href="http://search.maven.org/#artifactdetails%7Ccom.restfuse%7Ccom.eclipsesource.restfuse%7C1.0.0%7Cjar">Maven Central</a> and online as a <a href="http://restfuse.com/p2/">p2 repository</a> (yes, it&#8217;s an OSGi bundle).  I hope this small library will help you as much as it helped me. I would appreciate feedback on how to make restfuse even better.</p>
<p><a href="http://twitter.com/hstaudacher"><img src="http://download.eclipsesource.com/~hstaudacher/followme.png" title="Follow @hstaudacher" width="191" height="58" border="0" alt="followme Introducing restfuse   a JUnit Extension to test REST APIs" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/11/14/introducing-restfuse-a-junit-extension-to-test-rest-apis/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Lightweight OSGi Applications using RAP&#8217;s Widget Toolkit</title>
		<link>http://eclipsesource.com/blogs/2011/08/29/lightweight-osgi-applications-using-raps-widget-toolkit/</link>
		<comments>http://eclipsesource.com/blogs/2011/08/29/lightweight-osgi-applications-using-raps-widget-toolkit/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 20:04:06 +0000</pubDate>
		<dc:creator>Ralf Sternberg</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[milestone]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6394</guid>
		<description><![CDATA[Update 2: The new interfaces have been renamed again in RAP 1.5M7. Please refer to this post for the details and check out the updated code example. Update: APIs have changed a bit meanwhile, so I updated the code below accordingly. Entry points are now registered by path, and JEE_COMPLATIBILTIY has become the default mode, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 2:</strong> The new interfaces have been renamed again in RAP 1.5M7. Please refer to <a href="http://eclipsesource.com/blogs/2012/05/09/the-new-application-api-in-rap/">this post</a> for the details and check out the updated <a href="https://github.com/ralfstx/rap-helpers/tree/master/example.rwt.simple">code example</a>.</p>
<p><strong>Update:</strong> APIs have changed a bit meanwhile, so I updated the code below accordingly. Entry points are now registered by path, and JEE_COMPLATIBILTIY has become the default mode, which makes the main loop obsolete in this kind of applications.</p>
<p>RAP is well known as an &#8220;RCP for the web browser&#8221;, including workbench, extension points, and all that stuff. Indeed, one of the greatest features of RAP is its ability to reuse RCP code in web applications. But did you know that you can also use RAP&#8217;s widget toolkit (RWT) to create simple web UIs for your applications, without the heavy weight Eclipse UI stack?</p>
<p>With RAP 1.5, you can now simply include RWT in any OSGi application. You only need two bundles: <code>org.eclipse.rap.rwt</code> (the RAP widget toolkit itself) and <code>org.eclipse.rap.rwt.osgi</code> which integrates RWT with the OSGi HTTP service. There are no tie-ins with Equinox anymore, thus RAP also works with other OSGi containers.</p>
<p>To create a UI with RWT, you have to implement the interface <code>IEntryPoint</code>, here&#8217;s a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> createUI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Create a maximized top-level shell without trimmings that represents the main &quot;page&quot;</span>
    Display display <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Display<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Shell page <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Shell<span style="color: #009900;">&#40;</span> display, SWT.<span style="color: #006633;">NO_TRIM</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    page.<span style="color: #006633;">setMaximized</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>
    page.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">GridLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Create contents of main shell</span>
    <span style="color: #003399;">Label</span> label <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span> page, SWT.<span style="color: #006633;">NONE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    label.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Hello&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Button</span> button <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span> page, SWT.<span style="color: #006633;">PUSH</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    button.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;World&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Open the top-level shell and run the main loop to process events</span>
    page.<span style="color: #006633;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    page.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now what&#8217;s new is that, instead of registering this entry point with an extension point, you can now implement the new <code>ApplicationConfigurator</code> interface like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> configure<span style="color: #009900;">&#40;</span> <span style="color: #003399;">Context</span> context <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    context.<span style="color: #006633;">addEntryPoint</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;/simple&quot;</span>, SimpleEntryPoint.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    context.<span style="color: #006633;">addBranding</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> AbstractBranding<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getServletName<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;">return</span> <span style="color: #0000ff;">&quot;simple&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTitle<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;">return</span> <span style="color: #0000ff;">&quot;Simple RWT Example&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>When this implementation is registered as an OSGi service, you can access the UI with a web browser:<br />
<a href="http://eclipsesource.com/blogs/wp-content/uploads/2011/08/RWTSimple.png"><br />
<img src="http://eclipsesource.com/blogs/wp-content/uploads/2011/08/RWTSimple.png" alt="RWTSimple Lightweight OSGi Applications using RAPs Widget Toolkit" title="RWT Simple Example" width="550" height="251" class="aligncenter size-full wp-image-6399" /></a><br />
You can check out the example project <code>example.rwt.simple</code> from my <a href="https://github.com/ralfstx/rap-helpers">rap-helpers repository on github</a>. Please note that for this example to run you need declarative services in your target platform, which are not included in the RAP 1.5M1 target but in the latest nightly build. Also be aware that the new API is still provisional and may change again until the final release.</p>
<p>Kudos to Frank Appel, who contributed the new OSGi integration. He has a more detailed introduction to the new OSGi integration and examples for configuration in <a href="http://www.codeaffine.com/2011/08/26/raprwt-osgi-integration/">his blog</a>. BTW, Frank and me plan to demo the possibilities of this approach in our talk <a href="http://www.eclipsecon.org/sessions/dynamic-web-applications-osgi-and-rap">Dynamic web applications with OSGi and RAP</a> at the EclipseCon Europe &#8211; vote for it if you&#8217;re interested!</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/08/29/lightweight-osgi-applications-using-raps-widget-toolkit/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to build a cluster with Jetty / OSGi</title>
		<link>http://eclipsesource.com/blogs/2011/08/12/how-to-build-a-cluster-with-jetty-osgi/</link>
		<comments>http://eclipsesource.com/blogs/2011/08/12/how-to-build-a-cluster-with-jetty-osgi/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 13:56:43 +0000</pubDate>
		<dc:creator>Florian Waibel</dc:creator>
				<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[jetty]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6365</guid>
		<description><![CDATA[In this blog post I describe how to set up a cluster node with an embedded Jetty Server inside Equinox. Basically I followed the instructions available at the Jetty Wiki page Session Clustering Using a Database [1]. There are two Jetty configuration files involved: /etc/jetty.xml defining a JDBCSessionIdManager /WEB-INF/jetty-web.xml defining a JDBCSessionManager The main jetty.xml [...]]]></description>
			<content:encoded><![CDATA[<p>In this blog post I describe how to set up a cluster node with an embedded Jetty Server inside Equinox.</p>
<p>Basically I followed the instructions available at the Jetty Wiki page <a href="http://wiki.eclipse.org/Jetty/Feature/Session_Clustering_Using_a_Database">Session Clustering Using a Database</a> [1].</p>
<p>There are two Jetty configuration files involved:</p>
<ul>
<li>/etc/jetty.xml defining a JDBCSessionIdManager</li>
<li>/WEB-INF/jetty-web.xml defining a JDBCSessionManager</li>
</ul>
<p>The main jetty.xml resides in the folder etc of the jetty.home.bundle which itself is a fragment of org.eclipse.jetty.osgi.boot. The jetty.osgi.boot bundle is provided by the Jetty team and is responsible for bootstrapping Jetty in an OSGi environment.</p>
<p>The main configuration file contains the JDBCSessionIdManager definition using a H2 database:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionIdManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;New</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcidmgr&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.eclipse.jetty.server.session.JDBCSessionIdManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ref</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Server&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;workerName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SystemProperty</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;worker.name&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;primary&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Call</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;setDriverInfo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.h2.Driver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdbc:h2:tcp://localhost:9101/sessions<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Call<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;scavengeInterval&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>60<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/New<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Call</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;setAttribute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdbcIdMgr<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ref</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcidmgr&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Call<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Note</strong>: To reuse the configuration in multiple cluster nodes I use a SystemProperty tag to give every node a unique &#8220;worker.name&#8221;.  The database configuration is hardwired to a local H2 database.</p>
<p>With additional system properties I can tell the Jetty bootstrapper where to look for the global Jetty configuration and which port the Jetty instance should bind to:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">-Dworker.name=primary
-Djetty.port=18081
-Djetty.home.bundle=com.eclipsesource.cluster.jetty.home.bundle</pre></div></div>

<p>To enable the Jetty server to load the H2 database drivers I added a dynamic import directive via the fragment org.eclipse.jetty.serverdynamic.import:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Fragment-Host: org.eclipse.jetty.server;bundle-version=&quot;7.4.2&quot;
DynamicImport-Package: *</pre></div></div>

<p>The web application specific configuration /WEB-INF/jetty-web.xml is located in the web bundle, com.eclipsesource.cluster.jetty.demo.webbundle. This configuration file contains the JDBCSessionManager definition.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Configure</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.eclipse.jetty.webapp.WebAppContext&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Get</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;server&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Get</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcIdMgr&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionIdManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Get<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionHandler&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;New</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.eclipse.jetty.server.session.SessionHandler&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;New</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.eclipse.jetty.server.session.JDBCSessionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;idManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Ref</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcIdMgr&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/New<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/New<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Configure<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Note</strong>: &#8220;jdbcIdMgr&#8221; is a <strong>Ref</strong>erence to the jetty.xml from jetty.home.bundle.</p>
<p>If you want to try it out yourself, the code is available at <a href="https://github.com/eclipsesource/com.eclipsesource.cluster">GitHUB</a> [2].</p>
<p><strong>Note</strong>: The bundle com.eclipsesource.cluster.h2 contains an Eclipse launch configuration to start a local H2 database which is needed to run the example.</p>
<p>[1] <a href="http://wiki.eclipse.org/Jetty/Feature/Session_Clustering_Using_a_Database">http://wiki.eclipse.org/Jetty/Feature/Session_Clustering_Using_a_Database</a><br />
[2] <a href="https://github.com/eclipsesource/com.eclipsesource.cluster">https://github.com/eclipsesource/com.eclipsesource.cluster</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/08/12/how-to-build-a-cluster-with-jetty-osgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to extend the Virgo Jetty Server to support the RAP Widget Toolkit</title>
		<link>http://eclipsesource.com/blogs/2011/08/10/how-to-extend-the-virgo-jetty-server-to-support-the-rap-widget-toolkit/</link>
		<comments>http://eclipsesource.com/blogs/2011/08/10/how-to-extend-the-virgo-jetty-server-to-support-the-rap-widget-toolkit/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 08:20:41 +0000</pubDate>
		<dc:creator>Florian Waibel</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[rwt]]></category>
		<category><![CDATA[virgo]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6318</guid>
		<description><![CDATA[First, a bit of news for developers following the Virgo project:  The release day for Virgo Maya is getting closer[1] with the successful RC1 release a few weeks ago. Meantime, in this blog post I&#8217;ll describe another way of running RWT (the RAP Widget Tookit) based applications on the Virgo Jetty Server. I want to [...]]]></description>
			<content:encoded><![CDATA[<p>First, a bit of news for developers following the Virgo project:  The release day for <a href="http://eclipse.org/virgo">Virgo</a> Maya is <a href="http://underlap.blogspot.com/2011/07/virgo-30-maya-release-candidate-1.html">getting closer</a>[1] with the successful RC1 release a few weeks ago.</p>
<p>Meantime, in this blog post I&#8217;ll describe another way of running RWT (the <a href="http://eclipse.org/rap/">RAP</a> Widget Tookit) based applications on the Virgo Jetty Server. I want to use Virgo&#8217;s RFC66 support to deploy web applications in OSGi.<br />
The RFC66 Web Container specification creates an open standard that enables developers to deploy WAR files on OSGi. With a few modifications (see below) it is possible to deploy an RWT standalone application into an RFC66 container like Virgo.</p>
<p><strong>Note</strong>: In addition to using the HttpService described <a href="http://eclipsesource.com/blogs/2010/10/28/running-rap-on-virgo/">here</a>[2] with RAP 1.5 you can register RWT directly with an OSGi HTTP service. We&#8217;ll describe this in a follow-up post.</p>
<p>To extend Virgo you need to:</p>
<ol>
<li>Get a <a href="http://www.eclipse.org/virgo/download/milestones.php">Virgo Jetty Server Release Candidate</a>[3].</li>
<li>Install our <strong>ext</strong>ension of Virgo as suggested <a href="http://codewax.org/osgi/extending-virgo-with-a-httpservice/ ">here</a>[4] into /repository/ext.</li>
</ol>
<p><strong>Note</strong>: You can get a patched RWT bundle <a href="http://download.eclipsesource.com/~fwaibel/virgo/org.eclipse.rap.rwt_1.5.0.201108081102.jar">here</a> that  supports RFC66 deployment of RWT applications and the plan <a href="http://download.eclipsesource.com/~fwaibel/virgo/org.eclipse.rap.rwt-1.5.0.plan">here</a>. The Virgo deployment plan describes all bundles needed to support RWT applications in Virgo.</p>
<p>Copy the two downloaded artifacts into repository/ext:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">~virgo-jetty-server&gt; ls -1 repository/ext/*rwt*
repository/ext/org.eclipse.rap.rwt-1.5.0.plan
repository/ext/org.eclipse.rap.rwt_1.5.0.201108081102.jar</pre></div></div>

<p>Next I added our RWT extension to the initial Virgo artifacts. This is configured in<br />
config/org.eclipse.virgo.kernel.userregion.properties. We simply add our plan:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">initialArtifacts=repository:plan/org.eclipse.virgo.kernel.userregion.springdm,\
         repository:plan/org.eclipse.virgo.jetty.web,\
         repository:plan/org.eclipse.rap.rwt</pre></div></div>

<p>That&#8217;s all that has to be done on the Virgo side. If you start Virgo Jetty Server you should<br />
see the extension starting properly:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[2011-08-08 12:23:45.909] system-artifacts              Installing plan 'org.eclipse.rap.rwt' version '1.5.0'.
[2011-08-08 12:23:47.626] system-artifacts              Installing bundle 'org.eclipse.rap.rwt' version '1.5.0.201108081102'.
[2011-08-08 12:23:47.663] system-artifacts              Installed bundle 'org.eclipse.rap.rwt' version '1.5.0.201108081102'.
[2011-08-08 12:23:47.665] system-artifacts              Installed plan 'org.eclipse.rap.rwt' version '1.5.0'.
[2011-08-08 12:23:47.725] system-artifacts              Starting plan 'org.eclipse.rap.rwt' version '1.5.0'.
[2011-08-08 12:23:47.729] system-artifacts              Starting bundle 'org.eclipse.rap.rwt' version '1.5.0.201108081102'.
[2011-08-08 12:23:47.734] start-signalling-2            Started bundle 'org.eclipse.rap.rwt' version '1.5.0.201108081102'.
[2011-08-08 12:23:47.737] start-signalling-2            Started plan 'org.eclipse.rap.rwt' version '1.5.0'.</pre></div></div>

<p>Because an RWT standalone application doesn’t know about OSGi classloading, I thought that one solution might be to use buddy classloading. First, I enabled buddy classloading in org.eclipse.rap.rwt.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Bundle-SymbolicName: org.eclipse.rap.rwt
Bundle-Version: 1.5.0.qualifier
...
Eclipse-BuddyPolicy: registered</pre></div></div>

<p>Then I registered the RWT application com.eclipsesource.sovereign.swt.layout.web as a buddy:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Bundle-SymbolicName: com.eclipsesource.sovereign.swt.dialog
...
Require-Bundle:
 org.eclipse.rap.rwt
Export-Package: com.eclipsesource.sovereign.swt.dialog
Eclipse-RegisterBuddy: org.eclipse.rap.rwt
Web-ContextPath: /rap</pre></div></div>

<p><strong>Note</strong>: In the MANIFEST.MF of the web bundle we specified the context path to &#8220;/rap&#8221;.</p>
<p>Next I setup the RAP web application. The web.xml almost looks like that of a standard RWT standalone application. For more details please go to the <a href="http://wiki.eclipse.org/RAP/FAQ#How_do_I_use_an_RWT_standalone_application_in_Tomcat">RAP Wiki</a> [5]:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.rwt.entryPoints<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.eclipsesource.sovereign.swt.dialog.SwtDialogEntryPoint<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.rwt.internal.engine.RWTServletContextListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>rwtDelegate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.rwt.internal.engine.RWTDelegate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>rwtDelegate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You&#8217;ll see an additional section for the RWT resources:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>rwtResources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.jetty.servlet.DefaultServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>rwtResources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/rwt-resources/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now I was ready to deploy my RAP application. I simply copied the webbundle into Virgo&#8217;s pickup folder.</p>
<p><strong>Note</strong>: You can get the sample RAP webbundle <a href="http://download.eclipsesource.com/~fwaibel/virgo/com.eclipsesource.sovereign.swt.dialog_0.1.0.201108081127.jar">here</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[2011-08-08 12:25:34.421] fs-watcher                    Hot deployer processing 'CREATED' event for file 'com.eclipsesource.sovereign.swt.dialog_0.1.0.201108081127.jar'.
[2011-08-08 12:25:34.476] fs-watcher                    Installing bundle 'com.eclipsesource.sovereign.swt.dialog' version '0.1.0.201108081127'.
[2011-08-08 12:25:34.486] fs-watcher                    Installed bundle 'com.eclipsesource.sovereign.swt.dialog' version '0.1.0.201108081127'.
[2011-08-08 12:25:34.492] fs-watcher                    Starting bundle 'com.eclipsesource.sovereign.swt.dialog' version '0.1.0.201108081127'.
[2011-08-08 12:25:34.494] start-signalling-3            Started bundle 'com.eclipsesource.sovereign.swt.dialog' version '0.1.0.201108081127'.</pre></div></div>

<p>And the application is available at <a href="http://localhost:8080/rap">localhost:8080/rap</a></p>
<p>[1] <a href="http://underlap.blogspot.com/2011/07/virgo-30-maya-release-candidate-1.html">Virgo 3.0 (Maya) Release Candidate 1</a><br />
[2] <a href="http://eclipsesource.com/blogs/2010/10/28/running-rap-on-virgo/">Running RAP on Virgo</a><br />
[3] <a href="http://www.eclipse.org/virgo/download/milestones.php">Milestone Downloads</a><br />
[4] <a href="http://codewax.org/osgi/extending-virgo-with-a-httpservice/">Extending Virgo with a HttpService</a><br />
[5] <a href="http://wiki.eclipse.org/RAP/FAQ#How_do_I_use_an_RWT_standalone_application_in_Tomcat">How do I use an RWT standalone application in Tomcat </a><a></a></p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/08/10/how-to-extend-the-virgo-jetty-server-to-support-the-rap-widget-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RAP on the Maven Central Repository</title>
		<link>http://eclipsesource.com/blogs/2011/07/18/rap-on-the-maven-central-repository/</link>
		<comments>http://eclipsesource.com/blogs/2011/07/18/rap-on-the-maven-central-repository/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 08:00:00 +0000</pubDate>
		<dc:creator>Beyhan Veliev</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[indigo]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6248</guid>
		<description><![CDATA[Have you ever heard about RWT standalone?  RWT standalone applications use the widget toolkit of RAP called RWT for their user interface.  These applications can be standard Java applications with no need to create an OSGi based application. For Java applications it can be quite challenging to find the required dependencies but Maven can help [...]]]></description>
			<content:encoded><![CDATA[<p>Have  you ever heard about RWT standalone?  RWT standalone applications use  the widget toolkit of <a title="RAP" href="http://www.eclipse.org/rap/">RAP</a> called <a title="RWT" href="http://wiki.eclipse.org/WidgetToolkit">RWT</a> for their user interface.  These  applications can be standard Java applications with no need to create an  <a title="OSGi" href="http://www.osgi.org/Main/HomePage">OSGi</a> based application.</p>
<p>For Java applications it can be quite challenging to find the required dependencies but Maven can help here.  And, to make the life easier for RWT standalone developers, we  contributed the RAP bundles and the dependencies needed for a RWT  standalone application to the<a href="http://search.maven.org/"> Maven Central Repository</a>. To find the RAP bundles in the Maven Central Repository just search for “org.eclpse.rap”.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/mvc.jpg"><img class="size-full wp-image-6252 aligncenter" title="mvc" src="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/mvc.jpg" alt="mvc RAP on the Maven Central Repository" width="572" height="296" /></a></p>
<p>To try it yourself,  I recommend that you download the latest Eclipse for RCP and RAP Developers package from<a href="http://www.eclipse.org/downloads/packages/eclipse-rcp-and-rap-developers/indigor"> here</a>. Then you can install the<a href="http://www.eclipse.org/m2e/"> Eclipse Maven Integration</a> into your IDE from<a href="http://download.eclipse.org/technology/m2e/milestones/1.0"> here</a>.  After that you can import the<a href="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/example.zip"> example project</a> into your IDE. The example project contains a launch configuration  which you can start with the <a title="RWT-Launcher" href="http://help.eclipse.org/indigo/topic/org.eclipse.rap.help/help/html/getting-started/launcher.html">RWT-Launcher</a> included in the RCP and RAP  Developers package.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/07/18/rap-on-the-maven-central-repository/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building OSGi applications that use AspectJ with Tycho / Maven 3</title>
		<link>http://eclipsesource.com/blogs/2011/07/13/building-osgi-applications-that-use-aspectj-with-tycho-maven-3/</link>
		<comments>http://eclipsesource.com/blogs/2011/07/13/building-osgi-applications-that-use-aspectj-with-tycho-maven-3/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 11:19:03 +0000</pubDate>
		<dc:creator>Florian Waibel</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[aspectj]]></category>
		<category><![CDATA[tycho]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6228</guid>
		<description><![CDATA[I just pushed a template for creating AspectJ applications with Tycho and will give you a quick tour of it here. You&#8217;ll find the template on github [1] The template contains four infrastructure projects. One defines an OSGi command to calculate faculties and another contains an aspect to measure the duration of the calculation. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I just pushed a template for creating AspectJ applications with Tycho and will give you a quick tour of it here. You&#8217;ll find the template on <a href="https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo">github</a> [1]</p>
<p>The template contains four infrastructure projects.  One defines an OSGi command to calculate faculties and another contains an aspect to measure the duration of the calculation.</p>
<p>Let&#8217;s take a closer look.  <strong>com.eclipsesource.weaving.demo.releng </strong> contains the Maven parent pom.xml file which defines the modules of the application:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.eclipsesource.sandbox.weaving.demo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.eclipsesource.sandbox.weaving.demo.parent<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pom<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/packaging<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>../platform<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>../weaving.demo.chronometry<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>../weaving.demo.faculty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>../weaving.demo.feature<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>../repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>com.eclipsesource.weaving.demo.platform</strong> &#8211; contains the target definition</p>
<p><img src="http://download.eclipsesource.com/~fwaibel/aspectj-with-tycho/weaving-demo-target.png" alt="weaving demo target Building OSGi applications that use AspectJ with Tycho / Maven 3"  title="Building OSGi applications that use AspectJ with Tycho / Maven 3" /></p>
<p><strong>com.eclipsesource.weaving.demo.feature</strong> &#8211; defines the application scope</p>
<p><img src="http://download.eclipsesource.com/~fwaibel/aspectj-with-tycho/weaving-demo-feature.png" alt="weaving demo feature Building OSGi applications that use AspectJ with Tycho / Maven 3"  title="Building OSGi applications that use AspectJ with Tycho / Maven 3" /></p>
<p><strong>com.eclipsesource.weaving.demo.repository</strong> contains the product definition. One very important VM argument, almost hidden from the debug arguments, registers the framework weaving extension:</p>
<p>-Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook</p>
<p><img src="http://download.eclipsesource.com/~fwaibel/aspectj-with-tycho/weaving-demo-arguments.png" alt="weaving demo arguments Building OSGi applications that use AspectJ with Tycho / Maven 3"  title="Building OSGi applications that use AspectJ with Tycho / Maven 3" /></p>
<p>The weaving service has to be started early.</p>
<p><img src="http://download.eclipsesource.com/~fwaibel/aspectj-with-tycho/weaving-demo-startlevel.png" alt="weaving demo startlevel Building OSGi applications that use AspectJ with Tycho / Maven 3"  title="Building OSGi applications that use AspectJ with Tycho / Maven 3" /></p>
<p>As well as the four infrastructure projects, the template contains the application code:<br />
<strong>com.eclipsesource.weaving.demo.faculty</strong> – provides an OSGi console command to calculate faculty.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FacultyCommandProvider <span style="color: #000000; font-weight: bold;">implements</span> CommandProvider <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> _faculty<span style="color: #009900;">&#40;</span>CommandInterpreter ci<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> argument <span style="color: #339933;">=</span> ci.<span style="color: #006633;">nextArgument</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> argumentAsInteger <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>argument<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Faculty of &quot;</span> <span style="color: #339933;">+</span> argumentAsInteger <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; is &quot;</span>
          <span style="color: #339933;">+</span> recur<span style="color: #009900;">&#40;</span>argumentAsInteger<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
...</pre></div></div>

<p><strong>com.eclipsesource.weaving.demo.chronometry</strong> – contains the Aspect to measure the faculty execution time.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> aspect CommandProviderChronometer <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">void</span> around<span style="color: #009900;">&#40;</span>CommandInterpreter ci<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
        execution<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">void</span> CommandProvider<span style="color: #339933;">+</span>._faculty<span style="color: #009900;">&#40;</span>CommandInterpreter<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> args<span style="color: #009900;">&#40;</span>ci<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">long</span> start <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">nanoTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    proceed<span style="color: #009900;">&#40;</span>ci<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">long</span> duration <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">nanoTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> start<span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result calculated in &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>duration <span style="color: #339933;">/</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; micro seconds&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></pre></div></div>

<p>The following snippet from the project&#8217;s pom.xml file tells Tycho to use the aspectj compiler:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>aspectj-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.3.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;verbose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/verbose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complianceLevel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complianceLevel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>compile<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></div></div>

<p>We build the application the Tycho way, from the command line with Maven 3.x:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; cd releng
&gt; mvn package
...
[INFO] --- tycho-p2-director-plugin:0.12.0:archive-products (archive-products) @ com.eclipsesource.sandbox.weaving.demo.repository ---
[INFO] Building zip: .../weaving.demo_...-macosx.cocoa.x86_64.zip
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] com.es..weaving.demo.parent ..... SUCCESS [0.002s]
[INFO] com.es..weaving.demo.platform ... SUCCESS [0.269s]
[INFO] com.es..weaving.demo.faculty .... SUCCESS [1.995s]
[INFO] com.es..weaving.demo.chronometry  SUCCESS [0.482s]
[INFO] com.es..weaving.demo.feature .... SUCCESS [0.533s]
[INFO] com.es..weaving.demo.repository . SUCCESS [7.262s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------</pre></div></div>

<p>We can now unzip the artifact and launch the application:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; unzip weaving.demo_selfcontained-macosx.cocoa.x86_64.zip
&gt; Eclipse.app/Contents/MacOS/eclipse</pre></div></div>

<p>The following output shows that weaving was successful:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">osgi&gt; [org.eclipse.equinox.weaving.aspectj] info Starting AspectJ weaving service ...
...
[com.eclipsesource.weaving.demo.faculty] info register aspect com.es..CommandProviderChronometer
[org.eclipse.equinox.weaving.aspectj] info weaving bundle 'com.eclipsesource.weaving.demo.faculty'
[com.eclipsesource.weaving.demo.faculty] weaveinfo Join point 'method-execution(void com.es..FacultyCommandProvider._faculty(org.eclipse..CommandInterpreter))'
in Type 'com.es..FacultyCommandProvider' (FacultyCommandProvider.java:9)
advised by around advice from 'com.es..CommandProviderChronometer' (CommandProviderChronometer.aj:8)</pre></div></div>

<p>Running the OSGi console command shows the measurement in action:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">osgi&gt; faculty 23
Faculty of 23 is 862453760
Result calculated in 1165 micro seconds</pre></div></div>

<p>[1] https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/07/13/building-osgi-applications-that-use-aspectj-with-tycho-maven-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Single-Sourcing with declarative services</title>
		<link>http://eclipsesource.com/blogs/2011/07/08/single-sourcing-with-declarative-services/</link>
		<comments>http://eclipsesource.com/blogs/2011/07/08/single-sourcing-with-declarative-services/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 09:51:16 +0000</pubDate>
		<dc:creator>Holger Staudacher</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[declarative services]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[rt]]></category>
		<category><![CDATA[Single Sourcing]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6229</guid>
		<description><![CDATA[In my last blog post I introduced the idea of using OSGi services for single sourcing a RAP/RCP application. I think this approach is quite elegant, but it has one major drawback. When you use normal OSGi services in your application you will mix your application code with the OSGi Framework code everytime you reference [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://eclipsesource.com/blogs/2011/06/20/using-osgi-services-to-single-source-an-rcp-and-rap-application/">my last blog post</a> I introduced the idea of using <a href="http://osgi.org">OSGi</a> services for single sourcing a <a href="http://eclipse.org/rap">RAP</a>/RCP application. I think this approach is quite elegant, but it has one major drawback. When you use normal OSGi services in your application you will mix your application code with the OSGi Framework code everytime you reference or register a service. Not only does this look ugly, it&#8217;s also hard to test.</p>
<p>Luckily there is a lifesaver called Declarative Services. (For those of you who are familiar with declarative services, skip to the next paragraph.) The OSGi declarative services (ds) are specified in the <a href="http://www.osgi.org/Download/File?url=/download/r4v42/r4.cmpn.pdf">OSGi compendium</a> so they are standardized. It&#8217;s just a component framework on top of OSGi services. It gives you the ability to register and consume services in a declarative way using some xml files and simple accessors in your classes.</p>
<p>I&#8217;ll take the same example from in <a href="http://eclipsesource.com/blogs/2011/06/20/using-osgi-services-to-single-source-an-rcp-and-rap-application/">my last blog post</a> and use it to look at ds for single sourcing.  In that blog, we single sourced a themed button widget.  We can use the same interfaces and service implementations, and the only differences will be how the services will be registered and referenced.</p>
<p>First, let&#8217;s take a look at the service registration. In our example we need to register the services in the rap and rcp bundles. It&#8217;s common practice to put all service declarations in a folder called OSGI-INF in the root of your project. Once you&#8217;ve created this folder you can create a &#8220;component definition&#8221; using the wizard. After this you need to fill in three things: first, the filename of your choice, second, the component name which needs to be unique in the framework and third, the component itself.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/componentWizard.png"><img class="aligncenter size-full wp-image-6232" title="componentWizard" src="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/componentWizard.png" alt="componentWizard Single Sourcing with declarative services" width="537" height="570" /></a></p>
<p>The component is the fully qualified classname of your implementation. In the case of service registration, it&#8217;s your service implementation. To add the service registration, press &#8216;Finish&#8217; to open the component editor. We only want to register a service, so we jump to the service tab. In the bottom section you can add the service interface.</p>
<p>To understand what happens in the background let&#8217;s recap what we have declared. We defined a service interface, a service implementation, a component name and a filename. The component framework takes care of instantiating the service implementation and registering it as a service using the service interface. It registers the component using the component name. The filename will be automatically added to your bundle&#8217;s manifest. That&#8217;s all, the next time we start this bundle the service will be registered. Your component definition should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scr:component</span> <span style="color: #000066;">xmlns:scr</span>=<span style="color: #ff0000;">&quot;http://www.osgi.org/xmlns/scr/v1.1.0&quot;</span> <span style="color: #000066;">immediate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.app.rap.service.provider&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;implementation</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.app.rap.RAPSingelSourcingService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provide</span> <span style="color: #000066;">interface</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.app.ISingleSourcingService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scr:component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now we get to the service referencing. As you recall, we need to reference the service in our app bundle. Therefore, we need to create a component in this bundle too. In this example I decided to reference the service in the bundle&#8217;s activator and provide it with a static accessor. But you can reference it wherever you want. In this case the component is our Activator. The only difference to the service registration is in the service tab of the component editor. Instead of providing a service, we are now referencing one. You can do this by clicking &#8216;Add&#8217; in the upper section of this tab.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/serviceReferencing.png"><img class="aligncenter size-full wp-image-6233" title="serviceReferencing" src="http://eclipsesource.com/blogs/wp-content/uploads/2011/07/serviceReferencing.png" alt="serviceReferencing Single Sourcing with declarative services" width="521" height="315" /></a></p>
<p>After this you need to declare the Interface of the service you want to reference, in our case the ISingleSoucingService. The question is now, &#8220;how does this service finds its way to the Activator?&#8221; The answer is binding methods. In the reference you can specify a bind and an unbind method e.g. setService and unsetService. You need to add these methods to your activator with the service as a parameter. That&#8217;s all &#8211; we are referencing the service now. Your component should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scr:component</span> <span style="color: #000066;">xmlns:scr</span>=<span style="color: #ff0000;">&quot;http://www.osgi.org/xmlns/scr/v1.1.0&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.app.servic.consumer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;implementation</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.internal.app.Activator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reference</span> <span style="color: #000066;">bind</span>=<span style="color: #ff0000;">&quot;setSingleSourcingService&quot;</span> <span style="color: #000066;">cardinality</span>=<span style="color: #ff0000;">&quot;1..1&quot;</span> <span style="color: #000066;">interface</span>=<span style="color: #ff0000;">&quot;com.eclipsesource.app.ISingleSourcingService&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ISingleSourcingService&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;dynamic&quot;</span> <span style="color: #000066;">unbind</span>=<span style="color: #ff0000;">&quot;unsetSingleSourcingService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scr:component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The last thing we need is a little bit of glue to bring these components together. The glue is in the <code>org.eclipse.equinox.ds</code> bundle. This bundle contains the component framework implementation, and to make everything work together you need to add this bundle to your launch configuration. It&#8217;s not included in the <a href="http://eclipse.org/rap">RAP</a> target components, but you can download it using the <a href="http://wiki.eclipse.org/Eclipse_Project_Update_Sites">Indigo release site</a> or the <a href="http://download.eclipse.org/equinox/">Equinox SDK</a>.</p>
<p>I added a branch called &#8220;ds&#8221; to the <a href="https://github.com/eclipsesource/rap-single-sourcing">repository on github</a> from the last blog. This branch represents an example implementation using ds for single sourcing.</p>
<p>Have fun declaring services <img src='http://eclipsesource.com/blogs/wp-includes/images/smilies/icon_wink.gif' alt="icon wink Single Sourcing with declarative services" class='wp-smiley' title="Single Sourcing with declarative services" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/07/08/single-sourcing-with-declarative-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using OSGi services to single-source an RCP and RAP Application</title>
		<link>http://eclipsesource.com/blogs/2011/06/20/using-osgi-services-to-single-source-an-rcp-and-rap-application/</link>
		<comments>http://eclipsesource.com/blogs/2011/06/20/using-osgi-services-to-single-source-an-rcp-and-rap-application/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 08:18:23 +0000</pubDate>
		<dc:creator>Holger Staudacher</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[syndicate]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Single Sourcing]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=6083</guid>
		<description><![CDATA[Probably one of RAP’s best known features is its single-sourcing capabilities. Some time ago we created a guide on Single-Sourcing RCP and RAP applications. The guide recommended a technique where a facade and fragments were used to invoke the RCP or RAP implementation during runtime. With this post I want to show you how to [...]]]></description>
			<content:encoded><![CDATA[<p>Probably one of <a href="http://eclipse.org/rap">RAP’s</a> best known features is its single-sourcing capabilities. Some time ago we created a <a href="http://eclipsesource.com/en/info/rcp-rap-single-sourcing-guideline/">guide on Single-Sourcing RCP and RAP applications</a>. The guide recommended a technique where a facade and fragments were used to invoke the RCP or RAP implementation during runtime. With this post I want to show you how to achieve the same the <a href="http://www.osgi.org/Main/HomePage">OSGi</a> way.</p>
<p>For single-sourcing a RAP or RCP application, its straightforward to use the power of <a href="http://www.osgi.org/Main/HomePage">OSGi </a>because it&#8217;s included in both platforms out-of-the-box. OSGi has a central concept called services which are simply POJOs and are used to allow communication between modules. And, you can register or resolve services at any time in your code.</p>
<p>The basic Idea behind using OSGi services for single-sourcing is as follows. We need to extract all the things that vary into separate, platform specific bundles. To use the different implementations, we have to create an interface in a “common” bundle that contains the methods we want to use. The platform specific bundles have to register an implementation of this interface as a service. In the “common” bundle we can reference the registered services and use them to get the platform specific stuff. More specifically, we register a <a href="http://eclipse.org/rap">RAP</a> implementation in a “rap” bundle and an RCP implementation in an “rcp” bundle. The only thing we need to do then is to start the right bundles on the associated platform to get the right service.</p>
<p>With this solution we can extract the platform specific stuff into separate bundles and we don&#8217;t have to rely on fragments. So enough talking. Let&#8217;s look at some code. I decided to create a very simple single-sourcing interface which can be used to get the WidgetUtil.CUSTOM_VARIANT constant value. This constant exists only in RAP so, it&#8217;s a good example for showing how to handle the differences.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ISingleSourcingService <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> getCustomVariantString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I have created three bundles: one that contains the application which is entitled &#8220;com.eclipsesource.app&#8221; and one for each platform. These are called &#8220;com.eclipsesource.app.rap&#8221; and &#8220;com.eclipsesource.app.rcp&#8221;. Both platform bundles implement the interface.<br />
RAP:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCustomVariantString<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;">return</span> WidgetUtil.<span style="color: #006633;">CUSTOM_VARIANT</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>RCP:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCustomVariantString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// There are no custom variants in RCP</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>And both bundles are registering the service in their Activator during the start method call.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span> BundleContext bundleContext <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Activator</span>.<span style="color: #006633;">context</span> <span style="color: #339933;">=</span> bundleContext<span style="color: #339933;">;</span>
    registration <span style="color: #339933;">=</span> context.<span style="color: #006633;">registerService</span><span style="color: #009900;">&#40;</span> ISingleSourcingService.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
                                            <span style="color: #000000; font-weight: bold;">new</span> RAPSingelSourcingService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
                                            <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>When it comes to using the service in the common &#8220;app&#8221; bundle we can use a ServiceTracker to get the service implementation (<a href="http://eclipsesource.com/blogs/2009/05/12/osgi-declarative-services/">you can also use DS</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">private</span> ISingleSourcingService getSingleSourcingService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// We use a tracker to get the service. We also can use DS to get it.</span>
    Bundle bundle <span style="color: #339933;">=</span> FrameworkUtil.<span style="color: #006633;">getBundle</span><span style="color: #009900;">&#40;</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    BundleContext context <span style="color: #339933;">=</span> bundle.<span style="color: #006633;">getBundleContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ServiceTracker tracker
      <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ServiceTracker<span style="color: #009900;">&#40;</span> context,
                            ISingleSourcingService.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
                            <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    tracker.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ISingleSourcingService service <span style="color: #339933;">=</span> tracker.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    tracker.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> service<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The only thing we have to do now is to create two launch configurations which contain the associated platform-specific bundle.</p>
<p>That’s it! You can find the sources in <a href="https://github.com/eclipsesource/rap-single-sourcing">this github repository</a>. Have fun using OSGi services to single-source applications.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2011/06/20/using-osgi-services-to-single-source-an-rcp-and-rap-application/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

