<?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>The OSGi Look &#187; osgi</title>
	<atom:link href="http://www.osgilook.com/category/osgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.osgilook.com</link>
	<description>There&#039;s life beyond J(2)EE</description>
	<lastBuildDate>Thu, 10 Dec 2009 21:20:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GWT and OSGi in the Cloud</title>
		<link>http://www.osgilook.com/2009/12/10/gwt-and-osgi-in-the-cloud/</link>
		<comments>http://www.osgilook.com/2009/12/10/gwt-and-osgi-in-the-cloud/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 21:20:23 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/2009/12/10/gwt-and-osgi-in-the-cloud/</guid>
		<description><![CDATA[I hear every day more talks about bringing OSGi applications to the Cloud, and I think that&#8217;s a very exciting opportunity (since I will talk about that at the upcoming JaxLondon/OSGi Devcon Europe).
In this article Scott Lewis go even further and showcase a Twitter user status service with GWT, OSGi and Amazon Web services:

  [...]]]></description>
			<content:encoded><![CDATA[<p>I hear every day more talks about bringing OSGi applications to the Cloud, and I think that&#8217;s a very exciting opportunity (since I will talk about that at the upcoming J<a href="http://www.jaxlondon.com/">axLondon/OSGi Devcon Europe</a>).</p>
<p>In <a href="http://eclipseecf.blogspot.com/2009/12/cloud-osgi-gwt-ecf-rest-twitter-api.html">this article Scott Lewis</a> go even further and showcase a Twitter user status service with GWT, OSGi and Amazon Web services:</p>
<blockquote><p>
  Using several technologies, I&#8217;ve recently created a Twitter user status service&#8230;i.e. a web service that retrieves the latest user status for a given user.
</p></blockquote>
<p>Read <a href="http://eclipseecf.blogspot.com/2009/12/cloud-osgi-gwt-ecf-rest-twitter-api.html">the complete article here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/12/10/gwt-and-osgi-in-the-cloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache CXF: OSGi remote service implementation</title>
		<link>http://www.osgilook.com/2009/12/09/apache-cxf-osgi-remote-service-implementation/</link>
		<comments>http://www.osgilook.com/2009/12/09/apache-cxf-osgi-remote-service-implementation/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 09:20:49 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[dosgi]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[specification]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/2009/12/09/apache-cxf-osgi-remote-service-implementation/</guid>
		<description><![CDATA[
  Last week the Apache CXF implementation of the OSGi Remote Service specification, CXF-DOSGi version 1.1 was released.The CXF-DOSGi code base has already been supporting the OSGi Remote Service spec (chapter 13 in the OSGi 4.2 Compendium Specification) for some time. Now it&#8217;s in a released version as well.

Read the complete article on David [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>
  Last week the Apache CXF implementation of the OSGi Remote Service specification, CXF-DOSGi version 1.1 was released.The CXF-DOSGi code base has already been supporting the OSGi Remote Service spec (chapter 13 in the OSGi 4.2 Compendium Specification) for some time. Now it&#8217;s in a released version as well.
</p></blockquote>
<p>Read the <a href="http://osgithoughts.blogspot.com/2009/12/cxf-dosgi-11-implements-osgi-remote.html">complete article on David Bosschaert&#8217;s blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/12/09/apache-cxf-osgi-remote-service-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSGi testing with PaxExam</title>
		<link>http://www.osgilook.com/2009/12/08/osgi-testing-with-paxexam/</link>
		<comments>http://www.osgilook.com/2009/12/08/osgi-testing-with-paxexam/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 08:55:14 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[conference]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[pax]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/2009/12/08/osgi-testing-with-paxexam/</guid>
		<description><![CDATA[OSGi Testing : Pax Exam
View more presentations from Toni Menzel.

]]></description>
			<content:encoded><![CDATA[<div style="width:425px;text-align:left" id="__ss_2527633"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/tonimenzel/osgi-testing-pax-exam" title="OSGi Testing : Pax Exam">OSGi Testing : Pax Exam</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=paxexamdevoxx2009-091118080018-phpapp01&#038;rel=0&#038;stripped_title=osgi-testing-pax-exam" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=paxexamdevoxx2009-091118080018-phpapp01&#038;rel=0&#038;stripped_title=osgi-testing-pax-exam" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/tonimenzel">Toni Menzel</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/12/08/osgi-testing-with-paxexam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Dynamic Modules: OSGi meets the Spring Framework</title>
		<link>http://www.osgilook.com/2009/09/19/spring-dynamic-modules-osgi-meets-the-spring-framework/</link>
		<comments>http://www.osgilook.com/2009/09/19/spring-dynamic-modules-osgi-meets-the-spring-framework/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 19:35:22 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[conference]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[spring dm]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=584</guid>
		<description><![CDATA[Brief presentation about OSGi and Spring Dynamic Modules I presented last week at the Spring Framework Italian User Group in Cagliari, Sardinia.

]]></description>
			<content:encoded><![CDATA[<p>Brief presentation about OSGi and Spring Dynamic Modules I presented last week at the Spring Framework Italian User Group in Cagliari, Sardinia.</p>
<p><object type="application/x-shockwave-flash" data="http://static.slideshare.net/swf/ssplayer2.swf?doc=id=2023163&#038;doc=springdynamicmodules-090919142544-phpapp02" width="425" height="348"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=id=2023163&#038;doc=springdynamicmodules-090919142544-phpapp02" ></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/09/19/spring-dynamic-modules-osgi-meets-the-spring-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSGi HTTP Service: Registering Servlets on-the-fly</title>
		<link>http://www.osgilook.com/2009/09/08/osgi-http-service-registering-servlets-on-the-fly/</link>
		<comments>http://www.osgilook.com/2009/09/08/osgi-http-service-registering-servlets-on-the-fly/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 08:00:05 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ferlix]]></category>
		<category><![CDATA[http service]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=568</guid>
		<description><![CDATA[There&#8217;s a lot of talk lately about Web application development in OSGi, and there&#8217;s even an ongoing standardization effort (RFC 66) trying to define an OSGi web application model in the upcoming R4.2 release.
However, it is worth noting that the OSGi HTTP Service is one of the oldest compendium services; and that, while simplistic and [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot of talk lately about Web application development in OSGi, and there&#8217;s even an <a href="http://blog.springsource.com/2009/05/27/introduction-to-the-osgi-web-container/">ongoing standardization effort (RFC 66)</a> trying to define an OSGi web application model in the upcoming R4.2 release.<br />
However, it is worth noting that the OSGi HTTP Service is one of the oldest compendium services; and that, while simplistic and limited, there are many applications using it (we already mentioned the <a href="http://www.osgilook.com/2009/07/31/monitor-your-osgi-container-with-the-apache-felix-web-console/">Apache Felix Web Console</a>).</p>
<p>The OSGi HTTP Service provides a simple OSGi service to deploy servlets and resources at runtime; in this article I&#8217;ll focus on the first part, implementing and deploying a simple Servlet.<span id="more-568"></span></p>
<p>First of all, you will need an OSGi HTTP Service implementation. As usual, <a href="http://felix.apache.org">Apache Felix</a> provides a framework-independent bundle; so, without further ado, you can <a href="http://apache.prosite.de/felix/org.apache.felix.http.jetty-1.0.1.jar">download it and install it in your OSGi container</a>, or simply type</p>
<pre class="brush: bash;">
$ pax-run.sh http://www.osgilook.com/static/samples/osgi-http-service.txt
</pre>
<p>(By the way: have a look at our <a href="http://www.osgilook.com/osgi-demos/">OSGi Demos</a> for other easy, pre-cooked, demos)</p>
<p>Let&#8217;s now develop a simple Servlet. You don&#8217;t need to make it OSGi dependent in any way, so the usual Hello World Servlet would work:</p>
<pre class="brush: java;">
public class DateServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
           resp.getWriter().write(&quot;Hi, today is &quot;+ new Date());
	}
}
</pre>
<p>Easy. Now let&#8217;s write the usual deployment descript&#8230; no way! We want to deploy it on the fly, and without any boring XML descriptor!<br />
What we need is to get access to the OSGi <b>HttpService</b>, and declare the new servlet. We can do that, as usual, in the bundle activator.</p>
<pre class="brush: java;">
public class Activator implements BundleActivator
{
   public void start(BundleContext context) throws Exception
   {
      ServiceReference sRef = context.getServiceReference(HttpService.class.getName());
      if (sRef != null)
      {
         HttpService service = (HttpService) context.getService(sRef);
         service.registerServlet(&quot;/date&quot;, new DateServlet(), null, null);
      }
   }

   public void stop(BundleContext context) throws Exception
   {
      ServiceReference sRef = context.getServiceReference(HttpService.class.getName());
      if (sRef != null)
      {
         HttpService service = (HttpService) context.getService(sRef);
         service.unregister(&quot;/date&quot;);
      }
   }
}
</pre>
<p>Now package your bundle (don&#8217;t forget to specify the <em>Bundle-Activator</em>) and deploy it in the running OSGi container. If everything works fine, you&#8217;ll be able to reach your servlet at <a href="http://localhost:8080/date">http://localhost:8080/date</a>.</p>
<p>There are a few things the OSGi HTTP Service can also do, like registering resources. I&#8217;ll talk about that in the next blog post. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/09/08/osgi-http-service-registering-servlets-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Use your build directory as a bundle with Apache Felix</title>
		<link>http://www.osgilook.com/2009/09/07/use-your-build-directory-as-a-bundle-with-apache-felix/</link>
		<comments>http://www.osgilook.com/2009/09/07/use-your-build-directory-as-a-bundle-with-apache-felix/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:39:33 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[pax]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=564</guid>
		<description><![CDATA[Alin Dreghiciu has posted an interesting and easy tutorial to use a directory as a bundle; that&#8217;s of course very useful when developing new bundles. Alin used Pax-URL to do this little trick.
You can find more details on his &#8220;Pax My Framework&#8221; blog.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://adreghiciu.wordpress.com">Alin Dreghiciu</a> has posted an <a href="http://adreghiciu.wordpress.com/2009/09/06/install-your-directory-as-a-bundle-in-apache-felix/">interesting and easy tutorial</a> to use a directory as a bundle; that&#8217;s of course very useful when developing new bundles. Alin used <a href="http://wiki.ops4j.org/display/paxurl/Download">Pax-URL</a> to do this little trick.</p>
<p>You can find <a href="http://wiki.ops4j.org/display/paxurl/Download">more details on his &#8220;Pax My Framework&#8221; blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/09/07/use-your-build-directory-as-a-bundle-with-apache-felix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test driving the Knopflerfish HTTP Console</title>
		<link>http://www.osgilook.com/2009/08/27/test-driving-the-knopflerfish-http-console/</link>
		<comments>http://www.osgilook.com/2009/08/27/test-driving-the-knopflerfish-http-console/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 08:00:45 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[knopflerfish]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=529</guid>
		<description><![CDATA[Some weeks ago in this blog we saw how to install the Apache Felix Web Console to manage your OSGi framework.
The Felix Web Console is a quite complex and customizable tool, but if you are more looking for a very lightweight alternative, you may want to have a look at the Knopflerfish HTTP Console.

Let&#8217;s take [...]]]></description>
			<content:encoded><![CDATA[<p>Some weeks ago in this blog we saw how to install the <a href="http://www.osgilook.com/2009/07/31/monitor-your-osgi-container-with-the-apache-felix-web-console/">Apache Felix Web Console</a> to manage your OSGi framework.<br />
The Felix Web Console is a quite complex and customizable tool, but if you are more looking for a very lightweight alternative, you may want to have a look at the Knopflerfish HTTP Console.</p>
<p><a href="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-11.png"><img src="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-11.png" alt="knopflerfish http console" title="knopflerfish http console" width="562" height="380" class="aligncenter size-full wp-image-530" /></a></p>
<p>Let&#8217;s take it for a test drive.<span id="more-529"></span></p>
<p>First of all, to install the Knopflerfish HTTP Console you will need:</p>
<ul>
<li>the OSGi Compendium Bundle: <a href="http://repository.ops4j.org/maven2/org/osgi/org.osgi.compendium/4.1.0/org.osgi.compendium-4.1.0.jar">http://repository.ops4j.org/maven2/org/osgi/org.osgi.compendium/4.1.0/org.osgi.compendium-4.1.0.jar</a></li>
<li>an OSGi HTTP Service Implementation: <a href="http://apache.prosite.de/felix/org.apache.felix.http.jetty-1.0.1.jar">http://apache.prosite.de/felix/org.apache.felix.http.jetty-1.0.1.jar</a></li>
<li>and of course the Knopflerfish HTTP Console jar: <a href="http://www.knopflerfish.org/repo/jars/httpconsole/httpconsole-2.0.1.jar">http://www.knopflerfish.org/repo/jars/httpconsole/httpconsole-2.0.1.jar</a></li>
</ul>
<p>The other important thing you need is to set the <b>org.osgi.service.http.port</b> property value; in fact, by default, the Http Service will try to start at port on port 80, causing an exception of Unix systems.</p>
<p>Feeling lazy (every developer is lazy..)? I&#8217;ve prepared a <a href="http://www.osgilook.com/2009/07/28/starting-with-osgi-try-pax-runner/">Pax-Runner</a> <a href="http://osgilook.com/static/samples/kf-http-console.txt">file</a> for you. Assuming you have Pax Runner installed, just type</p>
<pre class="brush: bash;">
$ pax-run.sh http://osgilook.com/static/samples/kf-http-console.txt
</pre>
<p>and you are ready to rock!</p>
<p>Now opening your browser at <a href="http://localhost:8080/servlet/console">http://localhost:8080/servlet/console</a> you have access to the Knopflerfish console in all its glory.</p>
<p>The functionalities offered by this tool are pretty basic. There&#8217;s the Bundle View, where you can see its headers and services exposed:<br />
<a href="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-12.png"><img src="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-12.png" alt="kf-bundle" title="kf-bundle" width="636" height="561" class="aligncenter size-full wp-image-538" /></a><br />
<br/></p>
<p>It is possible to select a single service to display all its properties:<br />
<br/><br />
<a href="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-3.png"><img src="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-3.png" alt="Picture 3" title="Picture 3" width="590" height="417" class="aligncenter size-full wp-image-539" /></a></p>
<p>And it&#8217;s of course possible to install a bundle directly from the web interface:<br />
<br/></p>
<p><a href="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-2.png"><img src="http://www.osgilook.com/wp-content/uploads/2009/08/Picture-2.png" alt="kf-install" title="kf-install" width="593" height="330" class="aligncenter size-full wp-image-540" /></a><br />
<br/></p>
<p>In summary, the functionalities offered are just basic compared to the Apache Felix Web Console; however, being the user interface so simple (and usable also with small screens), it&#8217;s quite ideal if you want to check the status of your OSGi framework deployed on a mobile device.<br />
Want to know more? </p>
<pre class="brush: bash;">
$ pax-run.sh http://osgilook.com/static/samples/kf-http-console.txt
</pre>
<p>Cannot be simpler than that!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/08/27/test-driving-the-knopflerfish-http-console/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>No more excuses with OSGi Demos</title>
		<link>http://www.osgilook.com/2009/08/25/no-more-excuses-with-osgi-demos/</link>
		<comments>http://www.osgilook.com/2009/08/25/no-more-excuses-with-osgi-demos/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 08:00:07 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[pax]]></category>
		<category><![CDATA[demo]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=559</guid>
		<description><![CDATA[As I already explained in my articles on Pax-Runner, installing and setting up bundles and OSGi applications with this tool is really a piece of cake.
Since I use it when I&#8217;m writing articles for the OSGi Look, I decided to publish the provisioning files I write in the new OSGi Demos section. That will give [...]]]></description>
			<content:encoded><![CDATA[<p>As I already explained <a href="http://www.osgilook.com/2009/07/28/starting-with-osgi-try-pax-runner/">in my articles</a> on <a href="http://www.osgilook.com/2009/08/07/easy-osgi-provisioning-with-pax-runner-provisioning-files/">Pax-Runner</a>, installing and setting up bundles and OSGi applications with this tool is really a piece of cake.</p>
<p>Since I use it when I&#8217;m writing articles for the OSGi Look, I decided to publish the provisioning files I write in the new <a href="/osgi-demos/">OSGi Demos</a> section. That will give you the opportunity to try bundles and OSGi applications in less than 2 minutes, just running a one-line command.<br />
<a href="/osgi-demos/">Give it a try</a>! </p>
<p>Finally, if you know any interesting (and open source) OSGi application/demo that you can run with a Pax-Runner file, just <a href="mailto:filippo@knokode.com">send it to me</a> and I&#8217;ll publish it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/08/25/no-more-excuses-with-osgi-demos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSGi Preferences Service by Example</title>
		<link>http://www.osgilook.com/2009/08/24/osgi-preferences-service-by-example/</link>
		<comments>http://www.osgilook.com/2009/08/24/osgi-preferences-service-by-example/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 08:00:34 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[preferences]]></category>
		<category><![CDATA[settings]]></category>
		<category><![CDATA[specification]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=508</guid>
		<description><![CDATA[A common question asked by new Java developers is what&#8217;s the best solution to store user-specific or application settings. Of course, it is always possible to designate a particular folder (for instance /etc/myapp) in the filesystem to that use, but that often represents a limit for the application portability (what happens if it doesn&#8217;t run [...]]]></description>
			<content:encoded><![CDATA[<p>A common question asked by new Java developers is what&#8217;s the best solution to store user-specific or application settings. Of course, it is always possible to designate a particular folder (for instance <em>/etc/myapp</em>) in the filesystem to that use, but that often represents a limit for the application portability (what happens if it doesn&#8217;t run on Windows?). That&#8217;s the reason the Java Preference API was designed.</p>
<p>OSGi of course is not immune to that problem; an OSGi bundle may run in any device supporting a R4 OSGi container, and therefore needs a well defined and portable mechanism to store application and user settings. That&#8217;s the business of the OSGi Preferences Service.</p>
<p>In this article I&#8217;m going to show how you can use the Preferences Service in your OSGi applications.<span id="more-508"></span></p>
<p>First of all, you need an implementation of the OSGi Preferences Service. Apache Felix provides, as usual, a portable implementation that you can download and use in any R4 container: you can <a href="http://apache.linux-mirror.org/felix/org.apache.felix.prefs-1.0.2.jar">download the jar here</a> and <a href="http://felix.apache.org/site/apache-felix-preferences-service.html">check the documentation here</a>.</p>
<p>After you have downloaded and installed the bundle in your OSGi container, accessing to the Preferences Service is as simple as using any other service in OSGi:</p>
<pre class="brush: java;">
ServiceReference serviceref = context.getServiceReference(PreferencesService.class.getName());
if (serviceref != null)
{
   PreferencesService preferences = (PreferencesService) context.getService(serviceref);
   //store and retrieve your preferences here
}
</pre>
<p>Preferences are organized in a tree structure, so you can define quite complex preference models; the only limitation is give by the fact that you can store on &#8220;simple&#8221; values (boolan, double, float, int, long and strings) and not any type of Java object.</p>
<p><a href="http://www.osgilook.com/wp-content/uploads/2009/08/preferences.png"><img src="http://www.osgilook.com/wp-content/uploads/2009/08/preferences.png" alt="preferences" title="preferences" width="540" height="216" class="aligncenter size-medium wp-image-513" /></a></p>
<p>As mentioned before, the Preferences Service can be used to store application and user settings. To store application settings, you will place your settings under the <b>system root</b>.<br />
Let&#8217;s see in the following example how an application can store the information gathered during the installation:</p>
<pre class="brush: java;">
ServiceReference serviceref = context.getServiceReference(PreferencesService.class.getName());
if (serviceref != null)
{
   PreferencesService preferences = (PreferencesService) context.getService(serviceref);	

   //create a node 'installation' under the system root
   Preferences installationPreferences = preferences.getSystemPreferences().node(&quot;installation&quot;);
   installationPreferences.put(&quot;path&quot;, &quot;/opt/myapp&quot;);   //path chosen by the user
   installationPreferences.put(&quot;license-key&quot;, &quot;687-6GH-9JU-35H&quot;);   //license key
   installationPreferences.put(&quot;license-email&quot;, &quot;hacker@hackerz.com&quot;);   //license owner...
}
</pre>
<p>Reading these settings is equally simple (<em>note that every getter method has a second argument that specifies a default property value if the one required is not found</em>):</p>
<pre class="brush: java;">
ServiceReference serviceref = context.getServiceReference(PreferencesService.class.getName());
if (serviceref != null)
{
   PreferencesService preferences = (PreferencesService) context.getService(serviceref);	

   //retrieve the  'installation' node under the system root
   Preferences installationPreferences = preferences.getSystemPreferences().node(&quot;installation&quot;);
   String key = installationPreferences.get(&quot;license-key&quot;, null);   //get the license key
   String ownder = installationPreferences.get(&quot;license-email&quot;, null);   //get the license owner
}
</pre>
<p>Using the same API you can store and read user settings. Instead of accessing the <b>System Root</b> just access the <b>User Root</b> writing:</p>
<pre class="brush: java;">
ServiceReference serviceref = context.getServiceReference(PreferencesService.class.getName());
if (serviceref != null)
{
   PreferencesService preferences = (PreferencesService) context.getService(serviceref);	

   //retrieve the  'installation' node under the system root
   Preferences installationPreferences = preferences.getUserPreferences(&quot;John&quot;);
}
</pre>
<p><em><b>Need more OSGi articles and tutorial? Check the <a href="http://www.osgilook.com/osgi-recipes/">OSGi Recipes</a> section</b></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/08/24/osgi-preferences-service-by-example/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Apache Felix File Install part 2: Dynamic Configurations</title>
		<link>http://www.osgilook.com/2009/08/20/apache-felix-file-install-part-2-dynamic-configurations/</link>
		<comments>http://www.osgilook.com/2009/08/20/apache-felix-file-install-part-2-dynamic-configurations/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 20:45:18 +0000</pubDate>
		<dc:creator>fdiotalevi</dc:creator>
				<category><![CDATA[osgi]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[apache felix file install]]></category>
		<category><![CDATA[configuration admin]]></category>
		<category><![CDATA[fileinstall]]></category>

		<guid isPermaLink="false">http://www.osgilook.com/?p=487</guid>
		<description><![CDATA[This article refers to the OSGi Configuration Admin Service. Look at the Configuration Admin Page for more informations.
In the previous article this week I described a simple project structure using the Apache Felix File Install bundle to allow hot deployment of new bundles.
Another interesting feature of the File Install bundle is its ability to load [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>This article refers to the OSGi Configuration Admin Service. Look at the <a href="http://www.osgilook.com/osgi-configuration-admin-service/">Configuration Admin Page</a> for more informations.</strong></em></p>
<p>In the <a href="http://www.osgilook.com/2009/08/17/manage-your-osgi-application-with-apache-felix-fileinstall/">previous article</a> this week I described a simple project structure using the <a href="http://www.osgilook.com/apache-felix-file-install/">Apache Felix File Install</a> bundle to allow hot deployment of new bundles.<br />
Another interesting feature of the File Install bundle is its ability to load property files and send them to the OSGi <a href="http://www.osgilook.com/osgi-configuration-admin-service/">ConfigurationAdmin service</a>; that&#8217;s very useful if you want to be able to configure your applications just creating/deleting and updating properties file at runtime. In this post I&#8217;ll enhance the project presented in the previous article to include this new functionality.<br />
<span id="more-487"></span><br />
The new project structure we want to build is represented in the picture.</p>
<p><img src="http://www.osgilook.com/wp-content/uploads/2009/08/felix-fi2.png"/></p>
<p>The difference here is the additional <strong>config/application</strong> folder, that will be monitored by another instance of File Install; we will be able to create there new property files whose contents will be passed to the OSGi Configuration Admin Service.</p>
<p>First of all, we need an implementation of the OSGi Configuration admin service. We could download and store it in the <em>bundle</em> folder, and than add its path in the felix.auto.start property in the <em>config.properties</em> like we did in the previous article; but it much easier just to download it in the <em>dropins</em> folder&#8230; that&#8217;s why we created it!</p>
<pre class="brush: bash;">
$ cd dropins
$ wget http://apache.mirroring.de/felix/org.apache.felix.configadmin-1.0.10.jar
</pre>
<p>Now that the Configuration Admin bundle is in the <em>dropins</em> folder, we know that it will be automatically installed when we start up Felix.</p>
<p>To create another instance of File Install we will use&#8230; File Install. Just create a file called <strong>org.apache.felix.fileinstall-config.cfg</strong> in the <em>dropins</em> folder containing a single property:</p>
<pre class="brush: bash;">
felix.fileinstall.dir=config/application
</pre>
<p>Now start Felix</p>
<pre class="brush: bash;">
Welcome to Felix.
=================

DEBUG: WIRE: 1.0 -&gt; org.osgi.service.startlevel -&gt; 0
DEBUG: WIRE: 1.0 -&gt; org.osgi.framework -&gt; 0
DEBUG: WIRE: 1.0 -&gt; org.osgi.service.packageadmin -&gt; 0
DEBUG: WIRE: 2.0 -&gt; org.apache.felix.shell -&gt; 1.0
DEBUG: WIRE: 2.0 -&gt; org.osgi.framework -&gt; 0
-&gt; DEBUG: WIRE: 3.0 -&gt; org.osgi.util.tracker -&gt; 0
DEBUG: WIRE: 3.0 -&gt; org.osgi.framework -&gt; 0
DEBUG: WIRE: 3.0 -&gt; org.osgi.service.packageadmin -&gt; 0
felix.fileinstall.poll  (ms)   2000
felix.fileinstall.dir            /opt/myprojects/felix-1.8.0/dropins
felix.fileinstall.debug          -1
felix.fileinstall.bundles.new.start          true
Installed /opt/myprojects/felix-1.8.0/dropins/org.apache.felix.configadmin-1.0.10.jar
DEBUG: WIRE: 4.0 -&gt; org.osgi.framework -&gt; 0
DEBUG: WIRE: 4.0 -&gt; org.osgi.service.cm -&gt; 3.0
Started bundle: /opt/myprojects/felix-1.8.0/dropins/org.apache.felix.configadmin-1.0.10.jar
felix.fileinstall.poll  (ms)   2000
felix.fileinstall.dir            /opt/myprojects/felix-1.8.0/config/application
felix.fileinstall.debug          -1
felix.fileinstall.bundles.new.start          true
</pre>
<p>and we&#8217;re done! The log<br />
<strong>felix.fileinstall.dir            /opt/myprojects/felix-1.8.0/config/application</strong><br />
confirms that another instance of File Install is watching <em>config/application</em></p>
<p>All happened too fast? Let&#8217;s summarize.</p>
<p>File Install looks for two types of files: <strong>.jar</strong> and <strong>.cfg</strong>. When it finds a jar file, tries to install it as a bundle in the OSGi container; when it finds a cfg files, it reads its content, and </p>
<ul>
<li>if the file name is something like <strong>[service-name]-[service-pid].cfg</strong>, it uses the ConfiguratioAdmin service to send the configuration to the ManagedServiceFactory whose <em>service.pid</em> is [service-name]</li>
<li>if the file name does not contain a &#8211; (dash),  it sends the configuration to the ManagedService whose <em>service.pid</em> is equal to the file name (without the .cfg extension)</li>
</ul>
<p>So the trick here is that File Install is started by a ManagedServiceFactory with <em>service.pid</em> equal to <strong>org.apache.felix.fileinstall</strong>. So when File Install finds the file <em>org.apache.felix.fileinstall-config.cfg</em> in the <em>dropins</em> folder, it reads the contents and send it to its own ManagedServiceFactory that creates another instance of File Install watching the <em>config/applications</em> folder.</p>
<p>Now you are ready to experiment with this new project structure. I&#8217;ll leave you with some ideas to try out:</p>
<p>* Read this <a href="http://www.osgilook.com/2009/08/10/a-command-line-client-for-the-configuration-admin-service/">article explaining how to configure the Apache Felix HTTP service with the Configuration Admin Service</a>; after that, download Felix HTTP servlet in the <em>dropins</em> folder and configure the HTTP port creating a file named <em>org.apache.felix.http</em> containing the property <em>org.osgi.service.http.port</em></p>
<p>* Also the <a href="http://www.osgilook.com/2009/07/31/monitor-your-osgi-container-with-the-apache-felix-web-console/">Felix Web Console</a> exposes a ManagedService under the service.pid <em>org.apache.felix.webconsole.internal.servlet.OsgiManager</em>. Look in the <a href="http://felix.apache.org/site/apache-felix-web-console.html#ApacheFelixWebConsole-Configuration">Web Console documentation</a> to find out the properties to change username and password, and create a configuration file in <em>config/application</em> to change the default hacker-friendly admin/admin credentials!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.osgilook.com/2009/08/20/apache-felix-file-install-part-2-dynamic-configurations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
