Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: further edits (style, code etc)

...

This tutorial describes how to create a very simple "Hello world" JBI service engine (SE) component, pack it into a Service Unit (SU) which will be packed to a Service Assambly (SA), and finally how to run the SE inside ServiceMix. The SE will answer your received messages with "Hello, I received xyz bytes!", so you we literally see that it works. As it has the same structure as real, useful SE, the given hints help you to use it the presented code as a blueprint to create your own SE-SA-SUSUs. Still, the example is as minimalistic as possible, so are readers shall not getting get lost in too many details and you but get an idea of the big picture.

This tutorial shows you the desired/best practices or "clean" way to create a SE-SA-SU using Maven archetypes, so how the workflow shall be (- of course, other possibilities exist and may be better suited for certain situations). Furthermore, it will explain the reasons for critical choices and how to required information can be retrieved. Where appropriate, additional reading will be suggested. To make it as easy as possible to follow the descriptions, they contain only the relevant code snippets, while the full code is available in the SVN repository for reference. Please note that the code snippets are fetched directly from the full code in the SVN repository, thus the wiki and the code share always at the same, up to date state. 

Tip
titleHandy Hints

This tutorial is especially useful for ServiceMix beginners.

The Maven Getting Started Guide is a recommended , and short reading. It explains most of the Maven related things you will needneeded.

Warning
titleTODO

 
INS When to use this JBI Component
INS Using the component that you created

http://www.servicemix.org/site/notes-on-creating-jbi-component-using-maven2.htmlImage Removed
is already fully incorporated, so delete content and point from there to here

provide exact position in the SVN! 
/samples/hello-world-SE-SU-SA/
integrate from SVN source like it is done at Configuration  at http://www.servicemix.org/site/visualisation.htmlImage Removed

maybe moving the content of overlapping existing docus to this new tut and - where appropriate - delete the old ones (only leaving a redirect).
http://www.servicemix.org/site/notes-on-creating-jbi-component-using-maven2.html http://www.servicemix.org/site/creating-a-standard-jbi-component.htmlImage Added
is already fully incorporated, so delete content and point from there to here

provide additional reading

Maybe add testing 

Prerequisites

You needThe following is required

  • Around 15 minutes of time
  • A running copy of ServiceMix 3.0 and Maven 2.0.4 or higher
  • A connection to the Internet to download dependencies
  • A text editor to alter XML files
  • An editor or IDE for Java files

Overview SE-SU-SA

JBI components are can be tought of as the "smallest applications" you can access in an ESB. They have a very specific purpose, thus a narrow scope and set of functionallity. Components come in two flavours: Service Engine (SE) and Binding Components (BC).

...

Several SUs are packed into a Service Assambly (SA). An SA is a complete "application" consisting of multiple components (reminder: the "smallest appliactions") interacting with each other and thus making up the big "application". 

Further reading: JSR 208 

Creating the SE

Creating the stub of the SE 

First, a JBI component has to be created. Here, we use archetypes, just like shown at Creating a Standard JBI Component and Notes on Creating JBI Component using maven2 and Creating a protocol bridge. The Maven 2 archetypes are a kind of pattern, generic model, blueprint or template, or as Merriam-Webster defines "the original pattern or model of which all things of the same type are representations or copies". Using archetypes, Maven creates the basis for components, settings and so on, thus they archetypes spare developers repetetive work and avoid errors like typos etc.

Note: As this text describes how to create a "Hello World" Service Engine and pack it into an SU and SA, the project name is hello-world-SE-SU-SA and the single pieces are named analogous. For a custom project, the IDs and names shall be altered such that they describe the purpose or function of any the given piece of the SA.

Create First, we create a directory hello-world-SE-SU-SA and open a command line in this folder. Now we execute the following command (it has to be one line but was split to be readable):

No Format
mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SE
Code Block

color test mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SE

The first three parameters identify the maven 2 archetype to use, while the last two parameters define the generated maven 2 project. The version information "3.0-incubating" may have to be changed; just a look at any of ServiceMix' pom.xml for reveals the version you are usingto use. Maven uses the group ID (printed in pink) as default Java package (see Defaulting package to group ID: in output below as well), thus invalid characters like minus, percent etc. must be avoided or a custom package name has to be given as parameter. The output looks like this (watch for the informations in bold lettersonly relevant information preserved):

No Format
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ----------------------------------------------------------------------------
...
[INFO] Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE
...
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] Archetype created in dir: C:\0hello-world-SE-SU-SA\hello-world-SE
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

...

No Format
\hello-world-SE-SU-SA\hello-world-SE\
      pom.xml
      src\main\
            java\
                  org\apache\servicemix\
                        samples\helloWorldSE\
                              MyBootstrap.java
                              MyComponent.java
                              MyDeployer.java
                              MyEndpoint.java
                              MyLifeCycle.java
                              MySpringComponent.java
      test\
            java\
                  org\apache\servicemix\
                        samples\helloWorldSE\
                              MySpringComponentTest.java
            resources\
                  spring.xml

Now you You might be wondering why all the classes have the word "My" prefixed to them. Don't worry these are This prefix is just driven from the template, you ; you just need to rename them it to whatever you want to. Just , as long as you make sure you change the corresponding resource files , change "My" to whatever prefix that you used for the classes.(all tests and the pom.xml) as well.

Compiling the code 

From now on, you can build the code by executing

No Format

cd hello-world-SE

mvn compile

which shall present you as one of the last lines of output

No Format

[INFO] BUILD SUCCESSFUL

In case this success information is not appearing, the output shall give further information on the reasons.

Testing the code 

Doing automated testing of the code is possible as well. As ServiceMix' root POM disables testing, it has to be activated for the subprojects that shall be tested. To do so, the <build> entity of our pom.xml has to be enriched by

No Format

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>false</skip><!-- this overrides ServiceMix' root POM and forces to execute the tests -->
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

 where <skip>false</skip> is the relevant line of code. Now, tests will be done when executing

No Format

mvn test

The output shall look like the followingINFO Scanning for projects...
INFO ----------------------------------------------------------------------------
INFO Building A custom project
INFO task-segment: test
INFO ----------------------------------------------------------------------------
...
INFO test
INFO Setting reports dir: c:\java\tmp\servicemix-xslt\target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
surefire Running org.apache.servicemix.helloWorldSE.MySpringComponentTest
...
surefire Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1,422 sec
INFO ------------------------------------------------------------------------
INFO BUILD SUCCESSFUL
INFO ------------------------------------------------------------------------
INFO Total time: 42 seconds
INFO Finished at: Thu May 11 22:50:58 CEST 2006
INFO Final Memory: 8M/18M
INFO ------------------------------------------------------------------------ 
Adding

The default implementation of the component accepts InOut MEPs and return the input content as the out message.

3) Using an IDE to add meat to the component. You can either use IDEA or Eclipse, I tried it with Eclipse so I guess I am going to stick it for now. <TODO>

Now you can build and test the code by executing

...

...


cd hello-world-SE

mvn test

This shall already include everything stated at
http://www.servicemix.org/site/maven-jbi-plugin.html#MavenJBIplugin-GettingStartedImage Removed
and
http://www.servicemix.org/site/working-with-components.htmlImage Removed
 

Note
titleBe Careful

The body of the note here..

...

use the SU archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.htmlImage Removed  

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+UnitsImage Removed  

Packing into the SA 

...

use the SA archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.htmlImage Removed
mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeVersion=3.0-incubating-SNAPSHOT -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SA

manually editing http://www.servicemix.org/site/working-with-service-assemblies.htmlImage Removed