felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > apache-felix-ipojo-dosgi
Date Mon, 03 May 2010 08:30:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/FELIX/apache-felix-ipojo-dosgi">apache-felix-ipojo-dosgi</a></h2>
    <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~clement.escoffier">Clement
Escoffier</a>
    </h4>
        <br/>
                         <h4>Changes (19)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* to use a &quot;remote&quot;
service <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >This demo can be used with any
DOSGi distribution, in this document the single-bundle distribution <span class="diff-added-words"style="background-color:
#dfd;">(1.1)</span> is used with iPOJO <span class="diff-changed-words">1.<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">2</span><span
class="diff-added-chars"style="background-color: #dfd;">6</span>.0</span> and
Felix <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">(trunk)</span>
<span class="diff-added-words"style="background-color: #dfd;">(2.0.5)</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{div:class=toc} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*NOTE:*
this demo requires CXF/DOSGi 1.1-SNAPSHOT <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2.Demo design <br>This demo
is quite similar to the DS demo of DOSGi demo in structure. It consists of 5 bundles: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Sources <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
demo bundles are available from [http://people.apache.org/~clement/ipojo/tutorials/dosgi/].
You can also checkout the code from [http://svn.apache.org/repos/asf/felix/sandbox/clement/ipojo-tutorials/dosgi/].
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
sources and a pre-configured version of Felix are available in the [dosgi-tutorial archive|http://people.apache.org/~clement/ipojo/tutorials/dosgi/dosgi-tutorial.zip].
Once downloaded unzip the archive. To compile, run from the root : {{mvn clean install}}.
To run the application. go to the {{felix}} directory containing a pre-configured Felix. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. The Adder Service Implementation
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;/instance&gt; <br>{code}
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">So
let&#39;s install the server side in Felix (trunk required), together with iPOJO. We will
also use the Single Bundle Distribution bundle. First, start Felix as follow: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">So
let&#39;s install the server side in Felix. Launch Felix from the {{felix}} directory
with: <br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=shell} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">java
-Dorg.osgi.framework.storage=dosgi-server -jar bin/felix.jar <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">java
-jar bin/felix.jar server <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br>Once the
shell prompt appears, execute the following command in the shell: <br>{div:class=shell}
<br></td></tr>
            <tr><td class="diff-changed-lines" >start <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo/1.2.0/org.apache.felix.ipojo-1.2.0.jar</span>
<span class="diff-added-words"style="background-color: #dfd;">file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar</span>
<br></td></tr>
            <tr><td class="diff-changed-lines" >start <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">http://ftp.halifax.rwth-aachen.de/apache/felix/org.osgi.compendium-1.2.0.jar</span>
<span class="diff-added-words"style="background-color: #dfd;">file:../AdderServiceProvider/target/AdderServiceProvider-0.0.1-SNAPSHOT.jar</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">start
https://repository.apache.org/content/groups/snapshots/org/apache/cxf/dosgi/cxf-dosgi-ri-singlebundle-distribution/1.1-SNAPSHOT/cxf-dosgi-ri-singlebundle-distribution-1.1-SNAPSHOT.jar
<br>start http://people.apache.org/~clement/ipojo/tutorials/dosgi/AdderServiceInterface-0.0.1-SNAPSHOT.jar
<br>start http://people.apache.org/~clement/ipojo/tutorials/dosgi/AdderServiceProvider-0.0.1-SNAPSHOT.jar
<br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*Note:*
if you&#39;re building the demo from the source,  replace the {{AdderServiceInterface}}
and {{AdderServiceProvider}} URLs with your local ones. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >At this point, the service should
be available remotely (wait until the console stops printing stuff), you can check this by
obtaining the WSDL: [http://localhost:9090/adder?wsdl] <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Now, let&#39;s start another instance
of Felix: <br>{div:class=shell} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">java
-Dorg.osgi.framework.storage=dosgi-client -jar bin/felix.jar <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">java
-jar bin/felix.jar client <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br>Then, execute the
following command in the shell: <br>{div:class=shell} <br></td></tr>
            <tr><td class="diff-changed-lines" >start <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo/1.2.0/org.apache.felix.ipojo-1.2.0.jar</span>
<span class="diff-added-words"style="background-color: #dfd;">file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar</span>
<br></td></tr>
            <tr><td class="diff-changed-lines" >start <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">http://ftp.halifax.rwth-aachen.de/apache/felix/org.osgi.compendium-1.2.0.jar</span>
<span class="diff-added-words"style="background-color: #dfd;">file:../AdderServiceConsumer/target/AdderServiceConsumer-0.0.1-SNAPSHOT.jar</span>
<br></td></tr>
            <tr><td class="diff-changed-lines" >start <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">https://repository.apache.org/content/groups/snapshots/org/apache/cxf/dosgi/cxf-dosgi-ri-singlebundle-distribution/1.1-SNAPSHOT/cxf-dosgi-ri-singlebundle-distribution-1.1-SNAPSHOT.jar</span>
<span class="diff-added-words"style="background-color: #dfd;">file:../AdderServiceImporter/target/AdderServiceImporter-0.0.1-SNAPSHOT.jar</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">start
http://people.apache.org/~clement/ipojo/tutorials/dosgi/AdderServiceInterface-0.0.1-SNAPSHOT.jar
<br>start http://people.apache.org/~clement/ipojo/tutorials/dosgi/AdderServiceImporter-0.0.1-SNAPSHOT.jar
<br>start http://people.apache.org/~clement/ipojo/tutorials/dosgi/AdderServiceConsumer-0.0.1-SNAPSHOT.jar
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br></td></tr>
            <tr><td class="diff-unchanged" >... log messages may appear, after
a little while the following message appears: <br>Using adder service: 1 + 1 = 2 <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/superfish.css); 
</style>

<style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/style.css); 
</style>

<p>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>

<script type="text/javascript" src="http://felix.apache.org/ipojo/site/jquery-1.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/hoverIntent.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/superfish.js"></script>

<script type="text/javascript" src="http://felix.apache.org/ipojo/site/supersubs.js"></script>


<script type="text/javascript"> 
 
    $(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    14,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 
 
</script>
<div class="main">
<div class="page-header"/>
<img src="http://felix.apache.org/ipojo/site/header.png" class="header">
<a href="http://ipojo.org"><img src="http://felix.apache.org/ipojo/site/ipojo.png"
width="225" class="header-logo"></a>
<ul class="sf-menu sf-js-enabled sf-shadow" id="ipojo-menu">
<li class="current">
<!-- Menu Overview -->
<a href="#" class="sf-with-ul">Overview<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO" title="Apache Felix iPOJO">Home</a>
						
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-why-choose-ipojo" title="apache-felix-ipojo-why-choose-ipojo">Why
choose iPOJO</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-successstories" title="apache-felix-ipojo-successstories">Success
stories</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO+Feature+Overview" title="Apache
Felix iPOJO Feature Overview">Features</a>
	</li>
</ul>
</li>	

<li class="">			
<!-- Menu download -->
<li>
<a href="/confluence/display/FELIX/Download" title="Download">Download </a>
</li>

<li class="">					
<!-- Menu Documentation -->
<a href="#" class="sf-with-ul">Documentation<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
    <!-- sub-menu : getting started -->
    <li class="">
    <a href="#" class="sf-with-ul">Getting Started<span class="sf-sub-indicator">
»</span><span class="sf-sub-indicator"> »</span></a>
    <ul>
     <li><a href="/confluence/display/FELIX/iPOJO+in+10+minutes" title="iPOJO in
10 minutes">iPOJO in 10 minutes</a></li>
     <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Annotations" title="How
to use iPOJO Annotations">Using Annotations</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Hello+Word+%28Maven-Based%29+tutorial"
title="iPOJO Hello Word (Maven-Based) tutorial">Maven tutorial</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Advanced+Tutorial" title="iPOJO
Advanced Tutorial">Advanced tutorial</a></li>
     <li><a href="/confluence/display/FELIX/apache-felix-ipojo-dosgi" title="apache-felix-ipojo-dosgi">Using
Distributed OSGi</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Composition+Tutorial" title="iPOJO
Composition Tutorial">Application Composition</a></li>
    </ul>
    </li> <!-- end of getting started -->
    <!-- sub menu : Describing Components -->
     <li class="">
        <a href="http://felix.apache.org/site/describing-components.html" class="sf-with-ul">Describing
components<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator">
»</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Service+Requirement+Handler" title="Service
Requirement Handler">Requiring a service</a></li>
        <li><a href="/confluence/display/FELIX/Providing+OSGi+services" title="Providing
OSGi services">Providing a service</a></li>
        <li><a href="/confluence/display/FELIX/Lifecycle+Callback+Handler" title="Lifecycle
Callback Handler">Lifecycle management</a></li>
        <li><a href="/confluence/display/FELIX/Configuration+Handler" title="Configuration
Handler">Configuration</a></li>
        <li><a href="/confluence/display/FELIX/Architecture+Handler" title="Architecture
Handler">Introspection</a></li>
        <li><a href="/confluence/display/FELIX/Controller+Lifecycle+Handler" title="Controller
Lifecycle Handler">Impacting the lifecycle</a></li>
        <li><a href="/confluence/display/FELIX/Event+Admin+Handlers" title="Event
Admin Handlers">Asynchronous communication</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+JMX+Handler" title="iPOJO JMX
Handler">JMX management</a></li>
        <li><a href="/confluence/display/FELIX/Extender+Pattern+Handler" title="Extender
Pattern Handler">Extender pattern</a></li>
        <li><a href="/confluence/display/FELIX/White+Board+Pattern+Handler" title="White
Board Pattern Handler">Whiteboard pattern</a></li>
        <li><a href="/confluence/display/FELIX/Temporal+Service+Dependency" title="Temporal
Service Dependency">Temporal dependencies</a></li>
        </ul>
     </li> <!-- End of describing components -->
    <!-- sub-menu : User Guide -->
    <li class="">
    <a href="" class="sf-with-ul">User Guide<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Combining+iPOJO+and+Configuration+Admin"
title="Combining iPOJO and Configuration Admin">iPOJO and config admin</a></li>
        <li><a href="/confluence/display/FELIX/How-to+use+iPOJO+factories" title="How-to
use iPOJO factories">Factories and Instances</a></li>
        <li><a href="/confluence/display/FELIX/Using+XML+Schemas" title="Using XML
Schemas">XML Schemas</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-api" title="apache-felix-ipojo-api">API</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-testing-components"
title="apache-felix-ipojo-testing-components">Testing components</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-eclipse-integration"
title="apache-felix-ipojo-eclipse-integration">Eclipse Integration</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+FAQ" title="iPOJO FAQ">FAQ</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO-Reference-Card" title="iPOJO-Reference-Card">Reference
Card</a></li>
        </ul>
    </li> <!-- end of user guide -->
    <!-- sub-menu : Dev Guide -->
    <li> 
    <a href="#" class="sf-with-ul">Advanced Topics<span class="sf-sub-indicator">
»</span><span class="sf-sub-indicator"> »</span></a>
       <ul>
        <li><a href="http://felix.apache.org/ipojo/api/1.6.0" class="external-link"
rel="nofollow">Javadoc</a></li>
        <li><a href="/confluence/display/FELIX/How+to+write+your+own+handler" title="How
to write your own handler">Handler development</a></li>
        <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Manipulation+Metadata"
title="How to use iPOJO Manipulation Metadata">Manipulation Metadata </a></li>
        <li><a href="/confluence/display/FELIX/Dive+into+the+iPOJO+Manipulation+depths"
title="Dive into the iPOJO Manipulation depths">Dive into the iPOJO Manipulation depths</a></li>
       </ul>
    </li> <!-- End of Dev guide -->
</ul> 
</li> <!-- End of doc -->
<!-- Menu 4 : Tools -->
<li class="">
<a href="#" class="sf-with-ul">Tools<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/iPOJO+Ant+Task" title="iPOJO Ant Task">Ant
Task</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Eclipse+Plug-in" title="iPOJO Eclipse
Plug-in">Eclipse Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Maven+Plug-in" title="iPOJO Maven
Plug-in">Maven Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO-Arch-Command" title="iPOJO-Arch-Command"><tt>arch</tt>
shell command</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-online-manipulator"
title="apache-felix-ipojo-online-manipulator">Online Manipulator</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Webconsole+Plugin" title="iPOJO Webconsole
Plugin">Webconsole plugin</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-junit4osgi" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li>
</ul>   
</li><!-- End of tools -->	
<!-- Menu 5 : Support -->
<li>
<a href="/confluence/display/FELIX/ipojo-support" title="ipojo-support">Support </a>
</li>
<!-- End of the menu 5 -->			
<!-- Menu 6 : Misc -->
<li class="">
<a href="#" class="sf-with-ul">Misc<span class="sf-sub-indicator"> »</span><span
class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedVMs" title="apache-felix-ipojo-supportedVMs">Supported
JVMs</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedOSGi" title="apache-felix-ipojo-supportedOSGi">Supported
OSGi Implementations</a></li>
   <li><a href="http://ipojo-dark-side.blogspot.com" class="external-link" rel="nofollow">iPOJO's
Dark Side Blog</a></li>
   <li><a href="/confluence/pages/viewpage.action?pageId=54954" title="Article &amp;
Presentations">Article &amp; Presentations</a></li>
   <li><a href="http://www.apache.org/">ASF</a></li>
   <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
   <li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li>
</ul>
</li><!-- End of misc -->
</ul> <!-- End of the menu -->
</div> <!-- Page header -->
</p>

<div class="content">

<h1><a name="apache-felix-ipojo-dosgi-UsingDistributedServiceswithiPOJO"></a>Using
Distributed Services with iPOJO </h1>

<p><em>Distributed Service defines how to deal with remote services in OSGi. This
page describes the CXF Distributed OSGi with iPOJO demo.This demo uses iPOJO to create a remote
OSGi service from an iPOJO component. The consumer side also uses iPOJO to create a component
that consumes the remote OSGi service. By using iPOJO, you don't need to write code to interact
with the OSGi Service Registry at all. That's all handled through injection, which hugely
simplifies the code. Moreover thanks to iPOJO's advanced features such as property propagation,
the service is exported without any impact on its implementation.</em></p>

<p>In this demo, you will show how to use iPOJO:</p>
<ul>
	<li>to expose a service</li>
	<li>to propagate properties to make the service remotely accessible</li>
	<li>to use a "remote" service</li>
</ul>


<p>This demo can be used with any DOSGi distribution, in this document the single-bundle
distribution (1.1) is used with iPOJO 1.6.0 and Felix (2.0.5)</p>

<div class="toc"><div>
<ul>
    <li><a href='#apache-felix-ipojo-dosgi-Demodesign'>Demo design</a></li>
    <li><a href='#apache-felix-ipojo-dosgi-Sources'>Sources</a></li>
    <li><a href='#apache-felix-ipojo-dosgi-TheAdderServiceImplementation'>The
Adder Service Implementation</a></li>
    <li><a href='#apache-felix-ipojo-dosgi-TheAdderServiceConsumer'>The Adder
Service Consumer</a></li>
    <li><a href='#apache-felix-ipojo-dosgi-Conclusion'>Conclusion</a></li>
</ul></div></div>

<h2><a name="apache-felix-ipojo-dosgi-Demodesign"></a>Demo design</h2>
<p>This demo is quite similar to the DS demo of DOSGi demo in structure. It consists
of 5 bundles:</p>
<ul>
	<li>An interface bundle defining the Adder Service interface.</li>
	<li>This bundle is deployed on both sides.</li>
	<li>An Adder Service implementation bundle. (The service will be exported)</li>
	<li>An Adder Service importer bundle containing the remote-service file explaining
to DOSGi how to import and from where to import the Adder service.</li>
	<li>An Adder Service consumer bundle.</li>
</ul>


<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/122271/design.png?version=1&amp;modificationDate=1246796939000"
style="border: 0px solid black" /></span></p>

<p>The service implementation and consumer bundle are built using iPOJO.<br/>
The Adder Service interface is as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">interface</span>
AdderService {
    <span class="code-object">int</span> add(<span class="code-object">int</span>
a,<span class="code-object">int</span> b);
}
</pre>
</div></div>

<h2><a name="apache-felix-ipojo-dosgi-Sources"></a>Sources</h2>
<p>The sources and a pre-configured version of Felix are available in the <a href="http://people.apache.org/~clement/ipojo/tutorials/dosgi/dosgi-tutorial.zip"
class="external-link" rel="nofollow">dosgi-tutorial archive</a>. Once downloaded
unzip the archive. To compile, run from the root : <tt>mvn clean install</tt>.
To run the application. go to the <tt>felix</tt> directory containing a pre-configured
Felix.</p>

<h2><a name="apache-felix-ipojo-dosgi-TheAdderServiceImplementation"></a>The
Adder Service Implementation</h2>
<p>The service implementation is a simplistic implementation of the Adder service, which
is instantiated as an iPOJO component. This implementation uses annotations to define its
component type. The <tt>@provides</tt> annotation just says that it provides a
service. Moreover, the <tt>propagation=true</tt> attribute enables property propagation.</p>

<p>In the <a href="http://svn.apache.org/repos/asf/felix/sandbox/clement/ipojo-tutorials/dosgi/AdderServiceProvider/src/main/resources/metadata.xml"
class="external-link" rel="nofollow">metadata.xml</a> file, an instance of the component
type is declared. Note that this instance declaration defines three properties used by DOSGi
to exports the service. These properties instruct Distributed OSGi into making the service
available on <a href="http://localhost:9090/adder" class="external-link" rel="nofollow">http://localhost:9090/adder</a>.
Those properties are not declared in the component type itself. Indeed, the component type
enables property propagation; so all defined properties will be published on exported services.
This propagation also works with the configuration admin. This feature is pretty nice, as
it does not impact the component implementation and its description.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;instance component=<span class="code-quote">"org.apache.felix.ipojo.remote.adder.impl.AdderServiceImpl"</span>&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.interfaces"</span>value=<span
class="code-quote">"*"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.configuration.type"</span>value=<span
class="code-quote">"pojo"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.configuration.pojo.address"</span>value=<span
class="code-quote">"http://localhost:9090/adder"</span>/&gt;</span>
<span class="code-tag">&lt;/instance&gt;</span>
</pre>
</div></div>
<p>So let's install the server side in Felix. Launch Felix from the <tt>felix</tt>
directory with:</p>
<div class="shell"><p>java -jar bin/felix.jar server</p></div>

<p>Once the shell prompt appears, execute the following command in the shell:</p>
<div class="shell"><p>start <a href="file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar"
class="external-link" rel="nofollow">file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar</a><br/>
start <a href="file:../AdderServiceProvider/target/AdderServiceProvider-0.0.1-SNAPSHOT.jar"
class="external-link" rel="nofollow">file:../AdderServiceProvider/target/AdderServiceProvider-0.0.1-SNAPSHOT.jar</a></p></div>

<p>At this point, the service should be available remotely (wait until the console stops
printing stuff), you can check this by obtaining the WSDL: <a href="http://localhost:9090/adder?wsdl"
class="external-link" rel="nofollow">http://localhost:9090/adder?wsdl</a></p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/122271/wsdl.png?version=1&amp;modificationDate=1246796939000"
width="600px" style="border: 0px solid black" /></span></p>

<h2><a name="apache-felix-ipojo-dosgi-TheAdderServiceConsumer"></a>The Adder
Service Consumer</h2>
<p>The service consumer is also created using iPOJO. Thanks to DOSGi, iPOJO can inject
the service as any regular OSGi service. So, the code is pretty simple:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Component
<span class="code-keyword">public</span> class AdderConsumer {

  @Requires
  <span class="code-keyword">private</span> AdderService adder;

  <span class="code-keyword">public</span> AdderConsumer() {
    <span class="code-object">System</span>.out.println(<span class="code-quote">"Using
adder service: 1 + 1 = "</span>+ adder.add(1, 1));
 }
}
</pre>
</div></div>
<p>This implementation use iPOJO field injection to receive the AdderService. Then,
it uses it as a regular field. This bundle also contains a <a href="http://svn.apache.org/repos/asf/felix/sandbox/clement/ipojo-tutorials/dosgi/AdderServiceConsumer/src/main/resources/metadata.xml"
class="external-link" rel="nofollow">metadata.xml</a> file declaring an instance
of this type without any special configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;instance component=<span class="code-quote">"org.apache.felix.ipojo.remote.consumer.AdderConsumer"</span>/&gt;</span>
</pre>
</div></div>
<p>However, now we have to tell to DOSGi to import our Adder service. To achieve that,
we create a very simple bundle that just contains the <a href="http://svn.apache.org/repos/asf/felix/sandbox/clement/ipojo-tutorials/dosgi/AdderServiceImporter/src/main/resources/OSGI-INF/remote-service/remote-services.xml"
class="external-link" rel="nofollow">remote-services.xml</a> file. This file is analyzed
by CXF in order to import the service.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;service-descriptions xmlns=<span class="code-quote">"http://www.osgi.org/xmlns/sd/v1.0.0"</span>&gt;</span>
  <span class="code-tag">&lt;service-description&gt;</span>
    <span class="code-tag">&lt;provide interface=<span class="code-quote">"org.apache.cxf.dosgi.samples.ds.AdderService"</span>/&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.interfaces"</span>&gt;</span>*<span
class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.configuration.type"</span>&gt;</span>pojo<span
class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"osgi.remote.configuration.pojo.address"</span>&gt;</span>http://localhost:9090/adder<span
class="code-tag">&lt;/property&gt;</span>
  <span class="code-tag">&lt;/service-description&gt;</span>
<span class="code-tag">&lt;/service-descriptions&gt;</span>
</pre>
</div></div>

<p>Now, let's start another instance of Felix:</p>
<div class="shell"><p>java -jar bin/felix.jar client</p></div>
<p>Then, execute the following command in the shell:</p>
<div class="shell"><p>start <a href="file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar"
class="external-link" rel="nofollow">file:../AdderServiceInterface/target/AdderServiceInterface-0.0.1-SNAPSHOT.jar</a><br/>
start <a href="file:../AdderServiceConsumer/target/AdderServiceConsumer-0.0.1-SNAPSHOT.jar"
class="external-link" rel="nofollow">file:../AdderServiceConsumer/target/AdderServiceConsumer-0.0.1-SNAPSHOT.jar</a><br/>
start <a href="file:../AdderServiceImporter/target/AdderServiceImporter-0.0.1-SNAPSHOT.jar"
class="external-link" rel="nofollow">file:../AdderServiceImporter/target/AdderServiceImporter-0.0.1-SNAPSHOT.jar</a></p>

<p>... log messages may appear, after a little while the following message appears:<br/>
Using adder service: 1 + 1 = 2</p></div>

<p>The remote adder service has now been invoked. You will see the following line on
the server side window:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Adder service invoked: 1 + 1 = 2
</pre>
</div></div>
<p>That's it !</p>

<h2><a name="apache-felix-ipojo-dosgi-Conclusion"></a>Conclusion</h2>

<p>This tutorial has illustrated how to easily create remote services and consume them
with iPOJO. Subscribe to the Felix users mailing list by sending a message to <a href="mailto:users-subscribe@felix.apache.org"
class="external-link" rel="nofollow">users-subscribe@felix.apache.org</a>; after
subscribing, email questions or feedback to <a href="mailto:users@felix.apache.org" class="external-link"
rel="nofollow">users@felix.apache.org</a>.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>

 </div>
        <img src="http://felix.apache.org/ipojo/site/footer.png" class="footer">
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-1518442-4");
pageTracker._trackPageview();
} catch(err) {}
</script>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="http://cwiki.apache.org/confluence/display/FELIX/apache-felix-ipojo-dosgi">View
Online</a>
        |
        <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=122271&revisedVersion=10&originalVersion=9">View
Changes</a>
                |
        <a href="http://cwiki.apache.org/confluence/display/FELIX/apache-felix-ipojo-dosgi?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message