Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: restructured

...

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 stub of the SE, SU, SA and main POM

Creating the stub of the SE

...

Panel

Wiki Markup
\[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\] <span style="color: #ff00ff">Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE</span>
...
\[INFO\] \************\**\**\**\**\* End of debug info from resources from generated POM \**\**\******************\*
\[INFO\] <span style="color: #009900">Archetype created in dir: C:\hello-world-SE-SU-SA\hello-world-SE</span>
\[INFO\] \-----------------------------------------------------------------------\-
\[INFO\] BUILD SUCCESSFUL
\[INFO\] \-----------------------------------------------------------------------\-

Maven creates a new folder having the same name as the artifact ID provided (printed in green in the command and output). Inside this folder, a file called pom.xml is created. This contains the Project Object Model providing Maven with all needed information for building (see Introduction to the POM at the Maven website). Moreover, Java source files and tests were created. The full structure of files created by Maven looks like this (some directories are grouped together for better readability):

...

Creating the stub of the SU and SA 

The archetypes for SUs and SAs do not contain much code, but rather help with tasks related to Maven. Later, we will only need to adapt the POMs to our project - just little work.

In the directory hello-

...

world-SE-SU-SA

...

we execute the following commands (they have to be one line but were split to be readable) for the SU

No Format

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-unit
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SU

and the SU

No Format

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SA

By now, the full structure of files is created by Maven and looks like this:

No Format

C:\hello-world-SE-SU-SA\hello-world-SA
C:\hello-world-SE-SU-SA\hello-world-SA\pom.xml


C:\hello-world-SE-SU-SA\hello-world-SE
C:\hello-world-SE-SU-SA\hello-world-SE\pom.xml

C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MyBootstrap.java
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MyComponent.java
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MyDeployer.java
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MyEndpoint.java
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MyLifeCycle.java
C:\hello-world-SE-SU-SA\hello-world-SE\src\main\java\org\apache\servicemix\samples\helloWorldSE\MySpringComponent.java

C:\hello-world-SE-SU-SA\hello-world-SE\src\test\java\org\apache\servicemix\samples\helloWorldSE
C:\hello-world-SE-SU-SA\hello-world-SE\src\test\java\org\apache\servicemix\samples\helloWorldSE\MySpringComponentTest.java

C:\hello-world-SE-SU-SA\hello-world-SE\src\test\resources
C:\hello-world-SE-SU-SA\hello-world-SE\src\test\resources\spring.xml


C:\hello-world-SE-SU-SA\hello-world-SU
C:\hello-world-SE-SU-SA\hello-world-SU\pom.xml
C:\hello-world-SE-SU-SA\hello-world-SU\src\main\resources

According to the template rules, all the classes have the word "My" prefixed to them. We can 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.

Incorporating the SU and SA into the main POM

Now that we have created the SU and SA structure, we incorporate them into the main POM. We create a file called pom.xml in the hello-world-SE-SU-SA directory and instert the following content:

No Format

<project>
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.apache.servicemix.samples</groupId>
	<artifactId>helloWorldSE</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>pom</packaging>
	<modules>
		<module>hello-world-SA</module>
		<module>hello-world-SU</module>
	</modules>
	<dependencies>
		<dependency>
			<groupId>org.apache.servicemix.samples.helloWorldSE</groupId>
			<artifactId>hello-world-SU</artifactId>
			<version>1.0-SNAPSHOT</version>
		</dependency>
	</dependencies>
</project>

The <modules> entity defines which child projects belong to the main project. The <dependencies> entity causes Maven to include the SU into the SA.

Note: The content of <version> describes not the version of ServiceMix but the project we create, thus we may choose any desired version (e.g. 3.0-final). Then you have to change it below as well.

Maven commands 

By now, it is already possible to call Maven with the relevant goals.

Compiling the SE's code

We can build the code by executing

No Format

mvn compile

in the hello-world-SE-SU-SA/hello-world-SE directory and Maven shall present 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 information on the reasons. Further information can be found in the ServiceMix mailing lists archive and the Maven website.

Testing the SE's 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 hello-world-SE-SU-SA/hello-world-SE/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, when executing

No Format

mvn test

tests will be done and Maven outputs the following (truncated to the relevant information):

No Format

[INFO] Scanning for projects...
[INFO] 

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

From now on, we can build the code by executing

No Format

cd hello-world-SE

mvn compile

which shall present us 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. Further information can be found in the ServiceMix mailing lists archive and the Maven website.

Testing the 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 <skip>false</skip> is the relevant line of code. Now, when executing

No Format

mvn test

tests will be done and Maven outputs the following (truncated to the relevant information):

No Format

[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building A custom project
[INFO]    task-segment: [test]
[INFO] ----------------------------------------------------------------------------
...
[INFO] [compiler:compile]
...
[INFO] [surefire:test]
[INFO] Setting reports dir: c:\java\tmp\servicemix-helloWorldSE\target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
[surefire] Running org.apache.servicemix.samples.helloWorldSE.MySpringComponentTest
...
[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1,422 sec
[INFO] -------------------------------------------------------------------------------
[INFO] BUILD SUCCESSFULBuilding A custom project
[INFO]    task-segment: [test]
[INFO] ----------------------------------------------------------------------------
...

Adding functionality to the stub of the SE

Note
titleTODO

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

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>

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

Creating the SU and SA and incorporating them into the main POM

The archetypes for SUs and SAs do not contain much code, but rather help with tasks related to Maven. We will only need to adapt the POMs to our project - just little work, but requiring some guidiance.

Creating the SU and SA 

In the directory hello-world-SE-SU-SA we execute the following commands (they have to be one line but were split to be readable) for the SU

No Format

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-unit 
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SU 

and the SU

No Format

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SA  

Incorporating the SU and SA into the main POM


[INFO] [compiler:compile]
...
[INFO] [surefire:test]
[INFO] Setting reports dir: c:\java\tmp\servicemix-helloWorldSE\target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
[surefire] Running org.apache.servicemix.samples.helloWorldSE.MySpringComponentTest
...
[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1,422 sec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

Generation and deployment of the SA

By running

No Format

mvn install

from Now that we have created the SU and SA structure, we incorporate them into the main pom.xml. We create a file called pom.xml in the hello-world-SE-SU-SA directory and instert the following content:

No Format

<project>
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.apache.servicemix.samples</groupId>
	<artifactId>helloWorldSE</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>pom</packaging>
	<modules>
		<module>hello-world-SA</module>
		<module>hello-world-SU</module>
	</modules>
	<dependencies>
		<dependency>
			<groupId>org.apache.servicemix.samples.helloWorldSE</groupId>
			<artifactId>hello-world-SU</artifactId>
			<version>1.0-SNAPSHOT</version>
		</dependency>
	</dependencies>
</project>

The <modules> entity defines which child projects belong to the main project. The <dependencies> entity causes Maven to include the SU into the SA.

Note: The content of <version> describes not the version of ServiceMix but the project we create, thus we may choose any desired version (e.g. 3.0-final). Then you have to change it below as well.

Now, we should be able to launch Maven and have the SA generated in the hello-world-SE-SU-SA/hello-world-SA/target/ directory by running the following command from the hello-world-SE-SU-SA directory:mvn install
Of course, it won't work if you deploy it and we now need to fill the holes.

Then, deploy the SA and needed components to a started ServiceMix container:

cd hello-world-SE-SU-SA/hello-world-SA/
mvn jbi:projectDeploy

Then you can send an request to ...

Configuring the Service Assembly 

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units
manually editing http://www.servicemix.org/site/working-with-service-assemblies.html

...

, the SA is generated in the hello-world-SE-SU-SA/hello-world-SA/target/ directory. Of course, it does not yet do anything, but we can already deploy the SA and needed components to a running ServiceMix container by switching to the hello-world-SE-SU-SA/hello-world-SA/ directory and calling

No Format

mvn jbi:projectDeploy

it and we now need to fill the holes.

Then you can send an request to ...

Configuring the Service Assembly 

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units
manually editing http://www.servicemix.org/site/working-with-service-assemblies.html

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

Adding functionality to the stub of the SE

Note
titleTODO

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

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>

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

...