cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > Developing a Distributed OSGi Application in Eclipse
Date Mon, 18 Jan 2010 10:02:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/11/_/styles/combined.css?spaceKey=CXF&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CXF/Developing+a+Distributed+OSGi+Application+in+Eclipse">Developing
a Distributed OSGi Application in Eclipse</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davidb@apache.org">David
Bosschaert</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <p>This is really easy and assumes that you've already set up your Eclipse
workspace as <a href="/confluence/display/CXF/Setting+up+Eclipse+for+Running+and+Debugging+Distributed+OSGi"
title="Setting up Eclipse for Running and Debugging Distributed OSGi">described here</a>.</p>

<h3><a name="DevelopingaDistributedOSGiApplicationinEclipse-CreatingaDistributedOSGiService"></a>Creating
a Distributed OSGi Service</h3>

<p>1. Create a new Plugin Project for a 'standard' OSGi Framework.<br/>
<img src="/confluence/download/attachments/105948/new_project.jpg" align="absmiddle" border="0"
/></p>

<p>2. Create an OSGi service and and register it with the OSGi Service Registry. I'm
creating a service that implements my <tt>test.distributed.service.TemperatureService</tt>.
</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">package</span> test.distributed.service;
<span class="code-keyword">import</span> java.util.Date;

<span class="code-keyword">public</span> <span class="code-keyword">interface</span>
TemperatureService {
    <span class="code-object">int</span> getTemperature(Date date, <span class="code-object">String</span>
city, <span class="code-object">boolean</span> celcius);
}
</pre>
</div></div>
<p>The service is registered with the OSGi Service Registry in the Activator. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">package</span> test.distributed.service;
<span class="code-keyword">import</span> java.util.*;
<span class="code-keyword">import</span> org.osgi.framework.*;

<span class="code-keyword">public</span> class Activator <span class="code-keyword">implements</span>
BundleActivator {
    <span class="code-keyword">private</span> ServiceRegistration registration;

    <span class="code-keyword">public</span> void start(BundleContext bc) <span
class="code-keyword">throws</span> Exception {
    Dictionary props = <span class="code-keyword">new</span> Hashtable();
    props.put(<span class="code-quote">"osgi.remote.interfaces"</span>, <span
class="code-quote">"*"</span>);

    registration = bc.registerService(TemperatureService.class.getName(), 
                                      <span class="code-keyword">new</span> TemperatureServiceImpl(),
props);	}

    <span class="code-keyword">public</span> void stop(BundleContext context)
<span class="code-keyword">throws</span> Exception {
        registration.unregister();
    }
}
</pre>
</div></div>
<p>The only thing you need to do to expose a service remotely is setting the <tt>osgi.remote.interfaces</tt>
property to the (comma separated) list of interfaces of the service that need to be exposed.
Specifying <tt>*</tt> simply takes all the interfaces that were passed in to the
<tt>registerService()</tt> call.<br/>
By default the service will be made available on <tt>http://{machine}:9000/fully/qualified/ClassName</tt>
(so in this case <tt><a href="http://localhost:9000/test/distributed/service/TemperatureService"
rel="nofollow">http://localhost:9000/test/distributed/service/TemperatureService</a></tt>).
You can change this by adding the  <tt>osgi.remote.configuration.type</tt> and
<tt>osgi.remote.configuration.pojo.address</tt> properties on the service, e.g.:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">props.put(<span class="code-quote">"osgi.remote.interfaces"</span>,
<span class="code-quote">"*"</span>);
props.put(<span class="code-quote">"org.apache.cxf.ws.address"</span>, <span
class="code-quote">"http:<span class="code-comment">//localhost:8888/temp"</span>);</span></pre>
</div></div>

<h3><a name="DevelopingaDistributedOSGiApplicationinEclipse-TheConsumerSide"></a>The
Consumer Side</h3>
<p>Developing the consumer side bundles requires no different setup than the server
side bundles. </p>

<p>If you are using a <tt>OSGI-INF/remote-service/remote-services.xml</tt>
file to statically configure the client side with the remote service, you will need to include
this in your <tt>build.properties</tt> file to ensure that Eclipse puts it in
your bundle. If you are using Discovery, this change to the <tt>build.properties</tt>
is not needed.</p>

<p>See the samples/greeter demo for a full example.</p>
     </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/CXF/Developing+a+Distributed+OSGi+Application+in+Eclipse">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=105948&revisedVersion=3&originalVersion=2">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CXF/Developing+a+Distributed+OSGi+Application+in+Eclipse?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message