<?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</title>
	<atom:link href="http://eclipsesource.com/blogs/category/syndicate/feed/?author_name=vasko" rel="self" type="application/rss+xml" />
	<link>http://eclipsesource.com/blogs</link>
	<description>Eclipse Equinox OSGi</description>
	<lastBuildDate>Thu, 23 May 2013 16:16:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Playing Video in a Single-Sourced RAP/RCP Application</title>
		<link>http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/</link>
		<comments>http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 07:16:25 +0000</pubDate>
		<dc:creator>Vassiliy Tchoumatchenko</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[rcp]]></category>
		<category><![CDATA[Single Sourcing]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=11414</guid>
		<description><![CDATA[This post outlines the challenges we encountered when implementing video playback in a single-sourced [1] Eclipse RCP/ RAP [2] application. Our team at EclipseSource is developing medical software which runs both as a web application and an Eclipse RCP application. Hospitals are using this tool as part of the patient’s briefing. During the briefing, the <a href="http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>This post outlines the challenges we encountered when implementing video playback in a <a href="http://eclipsesource.com/en/downloads/webcasts/">single-sourced</a> [1] Eclipse RCP/ <a href="http://www.eclipse.org/rap/">RAP</a> [2] application.</p>
<p>Our team at EclipseSource is developing medical software which runs both as a web application and an Eclipse RCP application. Hospitals are using this tool as part of the patient’s briefing. During the briefing, the patient is informed about the medical treatments he is going to receive and is also asked to fill out a questionnaire. An essential part of the briefing is to show the patient a few video clips.</p>
<p>Figure 1 depicts the major components related to the video delivery. Thanks to the versatile SWT <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FBrowser.html">Browser </a>widget, the same video playback technology can be used for both the RCP and RAP versions. For this demo we will use <a href="http://videojs.com/">Video-JS player</a> [3], which supports both native HTML5 video and Adobe Flash fallback. Each video clip is available in Webm and MP4 formats. The Video-JS player offers both formats to the HTML5 capable browsers and loads MP4 in a flash video player for the older browsers. The video files are delivered via the OSGi HTTP service.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/architecture1.png"><img class="aligncenter size-full wp-image-11427" title="architecture" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/architecture1.png" alt="architecture1 Playing Video in a Single Sourced RAP/RCP Application" width="458" height="343" /></a></p>
<p>Figure 1. Application architecture.</p>
<p>The video is shown in a pop-up dialog (figure 2), which contains the Browser widget. Depending on the video assigned to a particular patient, a helper class – VideoHelper, prepares the HTML for the browser. The preparation consists of customizing an HTML template with the particular video file names and URLs.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/video-rcp-screen.png"><img class="alignnone size-thumbnail wp-image-11424" title="video-rcp-screen" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/video-rcp-screen-150x150.png" alt="video rcp screen 150x150 Playing Video in a Single Sourced RAP/RCP Application" width="150" height="150" /></a>  <a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/video-rap-screen.png"><img class="alignnone size-thumbnail wp-image-11425" title="video-rap-screen" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/video-rap-screen-150x150.png" alt="video rap screen 150x150 Playing Video in a Single Sourced RAP/RCP Application" width="150" height="150" /></a></p>
<p>Figure 2. Video in RCP and RAP (click to enalrge).</p>
<p>To construct the correct URLs, we need to know a few details of the HTTP service. In particular, we have to figure out which port the HTTP service is bound to, and, in the case of the RAP application, the context path. Obtaining this information is different for RCP and RAP, so we will have to apply single-sourcing. The class HostInfo (see figure 3) has two implementations, which are located in platform-specific fragments.</p>

<div class="wp_syntax"><table><tr><td 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;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> HostInfo  <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> HostInfo _instance<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> HostInfo getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_instance <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            _instance <span style="color: #339933;">=</span> ImplementationLoader.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span>HostInfo.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> _instance<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> initialize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getHost<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> doGetHost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getPort<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> doGetPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getContext<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> doGetContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">String</span> doGetScheme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">String</span> doGetHost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">int</span> doGetPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">String</span> doGetContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> doSetScheme<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> scheme<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> doSetHost<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> host<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> doSetPort<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> doSetContext<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Figure 3. HostInfo.java</p>
<p>The RAP HostInfoImpl uses the RWT singleton to get the current HttpServletRequest and from there to extract the required details (figure 4). The RCP implementation relies on a ServiceTracker, registered in the bundle activator, to obtain the port number of the HTTP service (figure 5).</p>

<div class="wp_syntax"><table><tr><td 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> HostInfoImpl <span style="color: #000000; font-weight: bold;">extends</span> HostInfo <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> host<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> context<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> scheme<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> HostInfoImpl getSessionSingletonInstance<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> SessionSingleton.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>HostInfoImpl.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> doGetHost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> host <span style="color: #339933;">=</span> getSessionSingletonInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">host</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>host <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HostInfo is not initialized.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> host<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> doGetPort<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> getSessionSingletonInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">port</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doSetHost<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> host<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		getSessionSingletonInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">host</span> <span style="color: #339933;">=</span> host<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	...
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		doSetHost<span style="color: #009900;">&#40;</span>RWT.<span style="color: #006633;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServerName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doSetPort<span style="color: #009900;">&#40;</span>RWT.<span style="color: #006633;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getLocalPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doSetContext<span style="color: #009900;">&#40;</span>RWT.<span style="color: #006633;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doSetScheme<span style="color: #009900;">&#40;</span>RWT.<span style="color: #006633;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getScheme</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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></td></tr></table></div>

<p>Figure 4. HostInfoImpl &#8211; RAP version (some getters/setters were deleted for brevity).</p>

<div class="wp_syntax"><table><tr><td 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> HostInfoImpl <span style="color: #000000; font-weight: bold;">extends</span> HostInfo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> scheme <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//$NON-NLS-1$</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> host <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//$NON-NLS-1$</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> context <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//$NON-NLS-1$</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> doGetHost<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> host<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> doGetPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> port <span style="color: #339933;">=</span> <span style="color: #003399;">Activator</span>.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServerPort</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> port<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doSetHost<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> host<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">host</span> <span style="color: #339933;">=</span> host<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doSetPort<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// do nothing</span>
    <span style="color: #009900;">&#125;</span>
  ...
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PortTrackerCustomizer <span style="color: #000000; font-weight: bold;">implements</span> ServiceTrackerCustomizer <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> httpPort <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
...
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> addingService<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServiceReference reference<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        extractPort<span style="color: #009900;">&#40;</span>reference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> context.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span>reference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> modifiedService<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServiceReference reference, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> service<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        extractPort<span style="color: #009900;">&#40;</span>reference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> extractPort<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServiceReference reference<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// ignore if the help is starting</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;org.eclipse.help&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>reference.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;other.info&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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: #339933;">;</span><span style="color: #009900;">&#125;</span> 
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// The http.port property is not defined if the ServletBridge is</span>
            <span style="color: #666666; font-style: italic;">// used to load Equinox.</span>
            <span style="color: #003399;">Object</span> httpPortObject <span style="color: #339933;">=</span> reference.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http.port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
            httpPort <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>httpPortObject.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Do not throw exception - it will prevent the application from</span>
            <span style="color: #666666; font-style: italic;">// starting when deployed with the ServletBridge.</span>
            httpPort <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getHttpPort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>httpPort <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No OSGi HTTP Service running&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> httpPort<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<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;">extends</span> AbstractUIPlugin <span style="color: #009900;">&#123;</span>
...
	<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>
...
        <span style="color: #006633;">portTrackerCustomizer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PortTrackerCustomizer<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        portTracker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ServiceTracker<span style="color: #009900;">&#40;</span>context, HttpService.<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>, portTrackerCustomizer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        portTracker.<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: #009900;">&#125;</span>
...
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getServerPort<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> portTrackerCustomizer.<span style="color: #006633;">getHttpPort</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></td></tr></table></div>

<p>Figure 5. HostInfoImpl and the relevant parts from the ServiceTrackrCustomizer and the bundle activator &#8211; RCP version.</p>
<p>In the RCP case, there is one more catch worth mentioning – the embedded Jetty server binds by default to port 80. If another process is already bound to this port, then our application will not be able to deliver videos. A simple solution is to provide a <a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fequinox%2Fhttp%2Fjetty%2FJettyCustomizer.html">JettyCustomizer</a> implementation, which selects a free port from the pool of ephemeral TCP ports. This customizer is in a separate fragment, with org.eclipse.equinox.http.jetty as a host plugin (figure 6).</p>

<div class="wp_syntax"><table><tr><td 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> DemoJettyCustomizer <span style="color: #000000; font-weight: bold;">extends</span> JettyCustomizer <span style="color: #009900;">&#123;</span>
&nbsp;
    @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;rawtypes&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> customizeHttpConnector<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> connector, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Dictionary</span> settings<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>connector <span style="color: #000000; font-weight: bold;">instanceof</span> Connector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Connector jettyConnector <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Connector<span style="color: #009900;">&#41;</span>connector<span style="color: #339933;">;</span>
            jettyConnector.<span style="color: #006633;">setPort</span><span style="color: #009900;">&#40;</span>findFreePort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">customizeHttpConnector</span><span style="color: #009900;">&#40;</span>connector, settings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> findFreePort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">ServerSocket</span> socket <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            socket <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ServerSocket</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            socket.<span style="color: #006633;">setReuseAddress</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>
            <span style="color: #000000; font-weight: bold;">return</span> socket.<span style="color: #006633;">getLocalPort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// ignore</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>socket <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                    socket.<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: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                   <span style="color: #666666; font-style: italic;">// ignore</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</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>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Figure 6. Finding a free TCP port &#8211; JettyCustomizer.</p>
<p>This demo application is available on GitHub &#8211; <a href="https://github.com/vtchoumatchenko/rap_rcp_video_demo.git">https://github.com/vtchoumatchenko/rap_rcp_video_demo.git</a></p>
<p>The repository contains a short trailer from the <a href="http://www.bigbuckbunny.org/">Big Buck Bunny video project</a> [4].</p>
<p>Feedback on the code is welcome!</p>
<p>References</p>
<ol>
<li>Single sourcing &#8211; <a href="http://eclipsesource.com/en/downloads/webcasts/">http://eclipsesource.com/en/downloads/webcasts/</a></li>
<li>Eclipse RAP &#8211; <a href="http://www.eclipse.org/rap/">http://www.eclipse.org/rap/</a></li>
<li>HTML5 Video Player &#8211; <a href="http://videojs.com/">http://videojs.com/</a></li>
<li>Big Buck Bunny video project &#8211; <a href="http://www.bigbuckbunny.org/">http://www.bigbuckbunny.org/</a></li>
</ol>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Playing+Video+in+a+Single-Sourced+RAP%2FRCP+Application&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/&amp;t=Playing+Video+in+a+Single-Sourced+RAP%2FRCP+Application" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/rcp/' title='rcp Tag'>rcp</a>, <a href='http://eclipsesource.com/blogs/tag/single-sourcing/' title='Single Sourcing Tag'>Single Sourcing</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/rcp/' title='rcp Tag'>rcp</a>, <a href='http://eclipsesource.com/blogs/tag/single-sourcing/' title='Single Sourcing Tag'>Single Sourcing</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/10/12/playing-video-in-a-single-sourced-raprcp-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
