cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > DOSGi Spring-DM Demo page
Date Fri, 25 Jun 2010 09:07:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/15/_/styles/combined.css?spaceKey=CXF&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="https://cwiki.apache.org/confluence/display/CXF/DOSGi+Spring-DM+Demo+page">DOSGi
Spring-DM Demo page</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davidb@apache.org">David
Bosschaert</a>
    </h4>
        <br/>
                         <h4>Changes (1)</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" >&lt;/beans&gt; <br>{code}
<br></td></tr>
            <tr><td class="diff-changed-lines" >Like in the Greeter demo, the
client side needs to be configured to know where the remote service actually is. When using
a Discovery system this configuration is provided dynamically via <span class="diff-changed-words">Discovery<span
class="diff-added-chars"style="background-color: #dfd;">,</span> <span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">(</span>see</span>
the <span class="diff-added-words"style="background-color: #dfd;">[DOSGi</span>
Discovery <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">demo
- TODO).</span> <span class="diff-added-words"style="background-color: #dfd;">Demo
page].</span> In this demo this information is provided statically in a [{{OSGI-INF/remote-service/remote-services.xml}}|http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml]
file. <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml}&lt;endpoint-descriptions
xmlns=&quot;http://www.osgi.org/xmlns/rsa/v1.0.0&quot;&gt; <br>  &lt;endpoint-description&gt;
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>This page describes the CXF Distributed OSGi with Spring-DM demo.</p>

<p>The Spring-DM demo uses Spring-DM to create a remoted OSGi service from a Spring
Bean. The consumer side uses Spring-DM to create a consumer to a remote OSGi service. By using
Spring-DM you don't need to write code to interact with the OSGi Service Registry. That's
all handled through injection which hugely simplifies the code. Besides, you can use all the
features of Spring together with OSGi.</p>

<p>It uses the CXF/DOSGi multi bundle distribution since that provides Spring-DM as
a dependency. By installing the multi bundle distribution, you have all the prerequisites
to run this demo. See <a href="/confluence/display/CXF/DOSGi+Multi+Bundle+Setup" title="DOSGi
Multi Bundle Setup">here for instructions on installing the multi bundle distribution</a>.</p>
<h2><a name="DOSGiSpring-DMDemopage-Demodesign"></a>Demo design</h2>
<p>From a high level the demo is very similar to the greeter demo. It comprises of 3
bundles:</p>
<ul>
	<li>The demo interface bundle providing the Dinner Service interface.</li>
	<li>The Dinner Service implementation bundle.</li>
	<li>The Dinner Service consumer bundle.</li>
</ul>


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

<p>The <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/interface/src/main/java/org/apache/cxf/dosgi/samples/springdm/DinnerService.java"
class="external-link" rel="nofollow">Dinner Service interface</a> 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> DinnerService {
    List&lt;Restaurant&gt; findRestaurants(<span class="code-object">String</span>
searchQuery);
}</pre>
</div></div>

<h2><a name="DOSGiSpring-DMDemopage-TheDinnerServiceProvider"></a>The Dinner
Service Provider</h2>

<p>The service implementation provides a <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/impl/src/main/java/org/apache/cxf/dosgi/samples/springdm/impl/DinnerServiceImpl.java"
class="external-link" rel="nofollow">simplistic implementation of the DinnerService interface</a>
which is instantiated via Spring as a bean. </p>

<p>The interesting bit is in the <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/impl/src/main/resources/META-INF/spring/spring.xml"
class="external-link" rel="nofollow"><tt>META-INF/spring/spring.xml</tt></a>
file. This file creates the DinnerServiceImpl bean and registers it with the OSGi Service
Registry. It also sets the <tt>osgi.remote.interfaces</tt> property on the service
to mark is as suitable for remoting. Here are the important parts of the <tt>spring.xml</tt>
file:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;beans <span class="code-keyword">xmlns:osgi</span>=<span
class="code-quote">"..."</span>&gt;</span>
  <span class="code-tag">&lt;osgi:service interface=<span class="code-quote">"org.apache.cxf.dosgi.samples.springdm.DinnerService"</span>&gt;</span>
    <span class="code-tag">&lt;osgi:service-properties&gt;</span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"service.exported.interfaces"</span>
value=<span class="code-quote">"*"</span> /&gt;</span>
    <span class="code-tag">&lt;/osgi:service-properties&gt;</span>
    
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.cxf.dosgi.samples.springdm.impl.DinnerServiceImpl"</span>
/&gt;</span>
  <span class="code-tag">&lt;/osgi:service&gt;</span>                
    
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>
<p>Unlike in the Greeter demo <tt>osgi.remote.configuration...</tt> properties
are not set in the configuration, this means that the service is exposed on the default location
of <tt><a href="http://localhost:9000/org/apache/cxf/dosgi/samples/springdm/DinnerService"
class="external-link" rel="nofollow">http://localhost:9000/org/apache/cxf/dosgi/samples/springdm/DinnerService</a></tt>.
The default location is based on the interface name of the service being remoted.</p>

<p>In this example, the bundles are installed in Felix.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">-&gt; start http:<span class="code-comment">//repo2.maven.org/maven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-spring-dm-<span
class="code-keyword">interface</span>/1.1/cxf-dosgi-ri-samples-spring-dm-<span
class="code-keyword">interface</span>-1.1.jar
</span>-&gt; start http:<span class="code-comment">//repo2.maven.org/maven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-spring-dm-impl/1.1/cxf-dosgi-ri-samples-spring-dm-impl-1.1.jar
</span>... log messages may appear ...
-&gt; ps
START LEVEL 32
   ID   State         Level  Name
[   0] [Active     ] [    0] <span class="code-object">System</span> Bundle (1.8.0)
... bundles ...
[  35] [Active     ] [    1] CXF Distributed OSGi Spring-DM Sample Interface Bundle
[  36] [Active     ] [    1] CXF Distributed OSGi Spring-DM Sample Implementation Bundle
</pre>
</div></div>
<p>At this point the service should be available. You can check this by obtaining the
WSDL:</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/119322/spring-dm-wsdl.jpeg?version=1&amp;modificationDate=1244032159000"
style="border: 0px solid black" /></span></p>

<h2><a name="DOSGiSpring-DMDemopage-TheDinnerServiceConsumer"></a>The Dinner
Service Consumer</h2>
<p>As on the remote service provider side, the service consumer is also created using
spring. Spring creates a <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/client/src/main/java/org/apache/cxf/dosgi/samples/springdm/client/DinnerServiceConsumer.java"
class="external-link" rel="nofollow">DinnerServiceConsumer</a> bean which is injected
with the a proxy to the remote DinnerService. The injection is all done by Spring, which makes
the code extremely simple. When Spring is done injecting, it calls the <tt>start()</tt>
method where the remote service is used. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class DinnerServiceConsumer
{
    DinnerService dinnerService;
    
    <span class="code-keyword">public</span> void setDinnerService(DinnerService
ds) {
        dinnerService = ds;
    }
    
    <span class="code-keyword">public</span> void start() {
        <span class="code-object">System</span>.out.println(<span class="code-quote">"Found
the following restaurants:"</span>);
        <span class="code-keyword">for</span> (Restaurant r : dinnerService.findRestaurants(<span
class="code-quote">"nice and not too expensive!"</span>)) {
            <span class="code-object">System</span>.out.format(<span class="code-quote">"
 %s (%s) Rating: %d\n"</span>, r.getName(), r.getAddress(), r.getRating());
        }
    }
}
</pre>
</div></div>

<p>The client side <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/client/src/main/resources/META-INF/spring/client-spring.xml"
class="external-link" rel="nofollow"><tt>META-INF/spring/spring.xml</tt></a>
file is also really simple. It simply declares a dependency on the OSGi DinnerService, which
is injected into the DinnerServiceConsumer bean. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;beans&gt;</span>
  <span class="code-tag">&lt;osgi:reference id=<span class="code-quote">"dinnerServiceRef"</span>
interface=<span class="code-quote">"org.apache.cxf.dosgi.samples.springdm.DinnerService"</span>/&gt;</span>
  
  &lt;bean class=<span class="code-quote">"org.apache.cxf.dosgi.samples.springdm.client.DinnerServiceConsumer"</span>
        init-method=<span class="code-quote">"start"</span>&gt;
    <span class="code-tag">&lt;property name=<span class="code-quote">"dinnerService"</span>
ref=<span class="code-quote">"dinnerServiceRef"</span>/&gt;</span>
  <span class="code-tag">&lt;/bean&gt;</span>
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>
<p>Like in the Greeter demo, the client side needs to be configured to know where the
remote service actually is. When using a Discovery system this configuration is provided dynamically
via Discovery, see the <a href="/confluence/display/CXF/DOSGi+Discovery+Demo+page" title="DOSGi
Discovery Demo page">DOSGi Discovery Demo page</a>. In this demo this information
is provided statically in a <a href="http://svn.apache.org/repos/asf/cxf/dosgi/trunk/samples/spring_dm/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml"
class="external-link" rel="nofollow"><tt>OSGI-INF/remote-service/remote-services.xml</tt></a>
file. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;endpoint-descriptions xmlns=<span
class="code-quote">"http://www.osgi.org/xmlns/rsa/v1.0.0"</span>&gt;</span>
  <span class="code-tag">&lt;endpoint-description&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"objectClass"</span>&gt;</span>
      <span class="code-tag">&lt;array&gt;</span>
        <span class="code-tag">&lt;value&gt;</span>org.apache.cxf.dosgi.samples.springdm.DinnerService<span
class="code-tag">&lt;/value&gt;</span>
      <span class="code-tag">&lt;/array&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"endpoint.id"</span>&gt;</span>http://localhost:9000/org/apache/cxf/dosgi/samples/springdm/DinnerService<span
class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;property name=<span class="code-quote">"service.imported.configs"</span>&gt;</span>org.apache.cxf.ws<span
class="code-tag">&lt;/property&gt;</span>
  <span class="code-tag">&lt;/endpoint-description&gt;</span>
<span class="code-tag">&lt;/endpoint-descriptions&gt;</span></pre>
</div></div>
<p>Install and run the consumer side of the demo in a separate Felix instance:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">-&gt; start http:<span class="code-comment">//repo2.maven.org/maven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-spring-dm-<span
class="code-keyword">interface</span>/1.1/cxf-dosgi-ri-samples-spring-dm-<span
class="code-keyword">interface</span>-1.1.jar
</span>-&gt; start http:<span class="code-comment">//repo2.maven.org/maven2/org/apache/cxf/dosgi/samples/cxf-dosgi-ri-samples-spring-dm-client/1.1/cxf-dosgi-ri-samples-spring-dm-client-1.1.jar
</span>... log messages may appear, at some point the consumer will make an invocation
on the remote service, you will see:
Found the following restaurants:
  Jojo's (1 food way) Rating: 3
  Boohaa's (95 forage ave) Rating: 1
  MicMac (Plastic Plaza) Rating: 1</pre>
</div></div>
<p>And on the service provider side, you can see that it has been invoked as the following
message appears: </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">-&gt; Hey! Someone's using the Dinner Service! Query: nice
and not too expensive!</pre>
</div></div>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF/DOSGi+Spring-DM+Demo+page">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=119322&revisedVersion=11&originalVersion=10">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF/DOSGi+Spring-DM+Demo+page?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message