servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache ServiceMix 4.0 > Creating an OSGi bundle for deploying JBI endpoints
Date Wed, 23 Mar 2011 11:53:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/3/_/styles/combined.css?spaceKey=SMX4&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/SMX4/Creating+an+OSGi+bundle+for+deploying+JBI+endpoints">Creating
an OSGi bundle for deploying JBI endpoints</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~gertvanthienen">Gert
Vanthienen</a>
    </h4>
        <br/>
                         <h4>Changes (4)</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" >h3. Creating the Maven project <br>First,
create and empty directory and add the following pom.xml file.  We add the bundle plugin and
configure it to import the servicemix-file and servicemix-bean packages as well as the *{{org.apache.servicemix.common.osgi}}*
package <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>{info:title=Components version} <br>When you&#39;re running this example,
make sure to configure the correct component version in your pom.xml file\\ <br>e.g.
for ServiceMix 4.3.0, choose the 2011.01 version <br>{info} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml} <br>&lt;project
xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;groupId&gt;org.apache.servicemix&lt;/groupId&gt;
<br>      &lt;artifactId&gt;servicemix-bean&lt;/artifactId&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;version&gt;2009.01&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;2011.01&lt;/version&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;/dependency&gt; <br>
 &lt;/dependencies&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
<br>        &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;version&gt;2.0.0&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;2.3.4&lt;/version&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;extensions&gt;true&lt;/extensions&gt;
<br>        &lt;configuration&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
<br>        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
       &lt;version&gt;2.3.2&lt;/version&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;configuration&gt;
<br>          &lt;source&gt;1.5&lt;/source&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>This page explains how you can create an OSGi bundle that contains both Java
code and a Spring XML file with the endpoints definition.  The example shows a file poller
endpoint with a servicemix-bean POJO</p>

<h3><a name="CreatinganOSGibundlefordeployingJBIendpoints-CreatingtheMavenproject"></a>Creating
the Maven project</h3>
<p>First, create and empty directory and add the following pom.xml file.  We add the
bundle plugin and configure it to import the servicemix-file and servicemix-bean packages
as well as the <b><tt>org.apache.servicemix.common.osgi</tt></b> package</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Components
version</b><br />When you're running this example, make sure to configure the
correct component version in your pom.xml file<br class="atl-forced-newline" />
e.g. for ServiceMix 4.3.0, choose the 2011.01 version</td></tr></table></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;project xmlns=<span class="code-quote">"http://maven.apache.org/POM/4.0.0"</span>
<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
  xsi:schemaLocation=<span class="code-quote">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"</span>&gt;
  <span class="code-tag">&lt;modelVersion&gt;</span>4.0.0<span class="code-tag">&lt;/modelVersion&gt;</span>
  <span class="code-tag">&lt;groupId&gt;</span>org.apache.servicemix<span
class="code-tag">&lt;/groupId&gt;</span>
  <span class="code-tag">&lt;artifactId&gt;</span>osgi-sample<span
class="code-tag">&lt;/artifactId&gt;</span>
  <span class="code-tag">&lt;packaging&gt;</span>bundle<span class="code-tag">&lt;/packaging&gt;</span>
  <span class="code-tag">&lt;version&gt;</span>1.0-SNAPSHOT<span class="code-tag">&lt;/version&gt;</span>
  <span class="code-tag">&lt;dependencies&gt;</span>
    <span class="code-tag">&lt;dependency&gt;</span>
      <span class="code-tag">&lt;groupId&gt;</span>org.apache.servicemix<span
class="code-tag">&lt;/groupId&gt;</span>
      <span class="code-tag">&lt;artifactId&gt;</span>servicemix-bean<span
class="code-tag">&lt;/artifactId&gt;</span>
      <span class="code-tag">&lt;version&gt;</span>2011.01<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag">&lt;/dependency&gt;</span>
  <span class="code-tag">&lt;/dependencies&gt;</span>
  <span class="code-tag">&lt;build&gt;</span>
    <span class="code-tag">&lt;plugins&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- configure
the bundle plugin with some additional imports --&gt;</span></span>
      <span class="code-tag">&lt;plugin&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span
class="code-tag">&lt;/groupId&gt;</span>
        <span class="code-tag">&lt;artifactId&gt;</span>maven-bundle-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
        <span class="code-tag">&lt;version&gt;</span>2.3.4<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;extensions&gt;</span>true<span class="code-tag">&lt;/extensions&gt;</span>
        <span class="code-tag">&lt;configuration&gt;</span>
          <span class="code-tag">&lt;instructions&gt;</span>
            <span class="code-tag">&lt;Import-Package&gt;</span>
               org.apache.servicemix.file,org.apache.servicemix.bean,org.apache.servicemix.common.osgi,*
            <span class="code-tag">&lt;/Import-Package&gt;</span>
          <span class="code-tag">&lt;/instructions&gt;</span>
        <span class="code-tag">&lt;/configuration&gt;</span>
      <span class="code-tag">&lt;/plugin&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- let's use
Java 5 --&gt;</span></span>
      <span class="code-tag">&lt;plugin&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>org.apache.maven.plugins<span
class="code-tag">&lt;/groupId&gt;</span>
        <span class="code-tag">&lt;artifactId&gt;</span>maven-compiler-plugin<span
class="code-tag">&lt;/artifactId&gt;</span>
        <span class="code-tag">&lt;version&gt;</span>2.3.2<span class="code-tag">&lt;/version&gt;</span>
        <span class="code-tag">&lt;configuration&gt;</span>
          <span class="code-tag">&lt;source&gt;</span>1.5<span class="code-tag">&lt;/source&gt;</span>
          <span class="code-tag">&lt;target&gt;</span>1.5<span class="code-tag">&lt;/target&gt;</span>
        <span class="code-tag">&lt;/configuration&gt;</span>
      <span class="code-tag">&lt;/plugin&gt;</span>
    <span class="code-tag">&lt;/plugins&gt;</span>
  <span class="code-tag">&lt;/build&gt;</span>
<span class="code-tag">&lt;/project&gt;</span>
</pre>
</div></div>

<h3><a name="CreatinganOSGibundlefordeployingJBIendpoints-AddingtheJavasourcefilesin%7B%7Bsrc%2Fmain%2Fjava%7D%7D"></a>Adding
the Java source files in <b><tt>src/main/java</tt></b></h3>
<p>We create the Java source files under the <b><tt>src/main/java</tt></b>
folder as usual:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> org.apache.servicemix.pojo;

<span class="code-keyword">import</span> org.apache.commons.logging.Log;
<span class="code-keyword">import</span> org.apache.commons.logging.LogFactory;
<span class="code-keyword">import</span> org.apache.servicemix.bean.Property;

<span class="code-keyword">public</span> class Pojo {
    
    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> Log LOG = LogFactory.getLog(Pojo.class);
    
    <span class="code-keyword">public</span> void handleFile(@Property(name=<span
class="code-quote">"org.apache.servicemix.file.name"</span>) <span class="code-object">String</span>
name) {
        LOG.info(<span class="code-quote">"Handling file "</span> + name);
    }
    
}
</pre>
</div></div>

<h3><a name="CreatinganOSGibundlefordeployingJBIendpoints-AddingtheSpringXMLfileto%7B%7BMETAINF%2Fspring%7D%7Din%7B%7Bsrc%2Fmain%2Fresources%7D%7D"></a>Adding
the Spring XML file to <b><tt>META-INF/spring</tt></b> in <b><tt>src/main/resources</tt></b></h3>
<p>Any Spring XML file in the <b><tt>META-INF/spring</tt></b>
folder will be automatically loaded and started upon deployment.  We add a Spring XML file
with our endpoint definitions to this folder.  Make sure it includes the <b><tt>org.apache.servicemix.common.osgi.EndpointExporter</tt></b>
that registers the endpoints with the NMR.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"utf-8"</span>?&gt;</span>
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:file</span>=<span class="code-quote">"http://servicemix.apache.org/file/1.0"</span>
       <span class="code-keyword">xmlns:bean</span>=<span class="code-quote">"http://servicemix.apache.org/bean/1.0"</span>
       <span class="code-keyword">xmlns:ns</span>=<span class="code-quote">"urn:test:example"</span>
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://servicemix.apache.org/file/1.0
         http://servicemix.apache.org/file/1.0/servicemix-file.xsd
         http://servicemix.apache.org/bean/1.0
         http://servicemix.apache.org/bean/1.0/servicemix-bean.xsd" &gt;
         
    &lt;file:poller service=<span class="code-quote">"ns:poller"</span> endpoint=<span
class="code-quote">"endpoint"</span>
                 targetService=<span class="code-quote">"ns:bean"</span> targetEndpoint=<span
class="code-quote">"endpoint"</span>
                 file=<span class="code-quote">"/home/gert/test/poller"</span>/&gt;
    
    &lt;bean:endpoint service=<span class="code-quote">"ns:bean"</span> endpoint=<span
class="code-quote">"endpoint"</span>
                   beanClassName=<span class="code-quote">"org.apache.servicemix.pojo.Pojo"</span>/&gt;
                   
    <span class="code-tag"><span class="code-comment">&lt;!-- use this special
class to register the endpoints with the NMR --&gt;</span></span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.servicemix.common.osgi.EndpointExporter"</span>
/&gt;</span>
    
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h3><a name="CreatinganOSGibundlefordeployingJBIendpoints-Buildandtest"></a>Build
and test</h3>
<p>Now, run a <b><tt>mvn clean install</tt></b> from your project
directory to start the Maven build. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
[INFO] Scanning <span class="code-keyword">for</span> projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building test
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /home/gert/Projects/test/target
[INFO] [resources:resources]
[INFO] Using <span class="code-keyword">default</span> encoding to copy filtered
resources.
Downloading: http:<span class="code-comment">//repo1.maven.org/maven2/org/apache/ws/security/wss4j/1.5.2/wss4j-1.5.2.pom
</span>[INFO] [compiler:compile]
[INFO] Compiling 1 source file to /home/gert/Projects/test/target/classes
...
[INFO] [bundle:bundle]
[INFO] [install:install]
[INFO] Installing /home/gert/Projects/test/target/test-1.0-SNAPSHOT.jar to /home/gert/.m2/repository/org/apache/servicemix/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar
[INFO] [bundle:install]
[INFO] Parsing file:/home/gert/.m2/repository/repository.xml
[INFO] Installing org/apache/servicemix/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Mon Jun 01 09:05:29 CEST 2009
[INFO] Final Memory: 32M/192M
[INFO] ------------------------------------------------------------------------
</pre>
</div></div>

<p>After the build has finished succesfully, just copy the JAR file you find in the
target directory into the ServiceMix 4 <b><tt>deploy</tt></b> directory.
 Afterwards, verify that the bundle has been started by typing the <b><tt>osgi/list</tt></b>
command in the ServiceMix 4 console.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smx@root:/&gt; osgi/list
START LEVEL 100
   ID   State         Spring     Level  Name
... 
[ 158] [Active     ] [Started] [   60] test (1.0.0.SNAPSHOT)
</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/SMX4/Creating+an+OSGi+bundle+for+deploying+JBI+endpoints">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=119050&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SMX4/Creating+an+OSGi+bundle+for+deploying+JBI+endpoints?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message