TutorialTutorial: Creation of a "Hello World - SE"
...
This tutorial shows 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 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. 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 | ||
---|---|---|
| ||
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 needed. |
Warning | ||||
---|---|---|---|---|
| ||||
INS When to use this JBI Component Maybe add testing testing |
Prerequisites
The 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
...
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 making up the big "application".
Further reading: JSR 208
Creating the SE
Creating the stub of the SE 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 archetypes spare developers repetetive work and avoid errors like typos etc.
...
Panel | ||
---|---|---|
|
...
All the classes have the word "My" prefixed to them due to the template. We can just rename the prefix to whatever we want to, as long as we make sure we change the corresponding resource files (all tests and the pom.xml) as well.
Compiling the code code
From now on, we can build the code by executing
...
In case this success information is not appearing, the output shall give further information on the reasons. In case it's not helpful, further Further information can be found in the ServiceMix mailing lists archive and the Maven website.
Testing the code code
Doing automated testing of the code is possible as well. As ServiceMix' root POM disables testing, we have to be activate it 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 where <skip>false</skip> is the relevant line of code. Now, when executing
...
Adding functionality to the stub of the SE SE
The default implementation of the component accepts InOut MEPs and return the input content as the out message.
...
This shall already include everything stated at
http://www.servicemix.org/site/maven-jbi-plugin.html#MavenJBIplugin-GettingStarted
and
http://www.servicemix.org/site/working-with-components.html
Note | ||
---|---|---|
| ||
The body of the note here.. |
...
use the SU archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.html
manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units
Packing into the SA SA
As mentioned above\, the archetypes for SUs and SAs mainly help with tasks related to Maven.
...