Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>org.apache.servicemix.samples<samples.helloworld</groupId>
  <artifactId>hello-world-se<smx</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Hello World JBI Sample<Component</name>

  <modules>
    <module>hello-world-sa</module>
    <module>hello-world-su</module>
  </modules>

  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix.samples.helloworld</groupId>
      <artifactId>hello-world-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

</project>

This POM will allow the example to be easily folded in to the ServiceMix samples. The <modules> element denotes the subprojects other projects that were created using the Maven archetypes and the <dependencies> element tells Maven to include the SU into the SA when it is constructed.

Give Each of the Maven Subprojects a Name

When sitting in the . Once the pom.xml file from above is saved into the hello-world-smx directory, you should now see the following:

No Formatcode

$ ls 
hello-world-sa
hello-world-se
 hello-world-su
 pom.xml

Now we need to give each component's pom.xml an appropriate name. This name will allow Maven's output to denote a component's name in its output making our development work a bit easier. To name each project, simply edit each pom.xml and replace <name>A custom project</name> with an appropriate name. Below are the instructions for naming each component's project:

  • Edit hello-world-sa/pom.xml and replace <name>a custom project</name> with <name>Hello World Service Assembly</name>
  • Edit hello-world-se/pom.xml and replace <name>a custom project</name> with <name>Hello World Service Engine</name>
  • Edit hello-world-su/pom.xml and replace <name>a custom project</name> with <name>Hello World Service Unit</name>

A Quick Look at the Directory Hierarchy

After executing the Maven archetypes above, you should now be able to see the following directory hierarchy:

No Format

./hello-world-sa
./hello-world-sa/pom.xml
./hello-world-se
./hello-world-se/pom.xml
./hello-world-se/src
./hello-world-se/src/main
./hello-world-se/src/main/java
./hello-world-se/src/main/java/org
./hello-world-se/src/main/java/org/apache
./hello-world-se/src/main/java/org/apache/servicemix
./hello-world-se/src/main/java/org/apache/servicemix/samples
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyBootstrap.java
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyComponent.java
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyEndpoint.java
./hello-world-se/src/test
./hello-world-se/src/test/java
./hello-world-se/src/test/java/org
./hello-world-se/src/test/java/org/apache
./hello-world-se/src/test/java/org/apache/servicemix
./hello-world-se/src/test/java/org/apache/servicemix/samples
./hello-world-se/src/test/java/org/apache/servicemix/samples/helloworld
./hello-world-se/src/test/java/org/apache/servicemix/samples/helloworld/MySpringComponentTest.java
./hello-world-se/src/test/resources
./hello-world-se/src/test/resources/log4j.properties
./hello-world-se/src/test/resources/spring.xml
./hello-world-su
./hello-world-su/pom.xml
./hello-world-su/src
./hello-world-su/src/main
./hello-world-su/src/main/resources
Tip
titleUnix

To show the entire directory hierarchy, simply execute find . from the command line

Tip
titleWindows

To show the entire directory hierarchy, simply execute find from the command line

According to the archetype rules, all Java objects generated from the archetype:create goal are prefixed with the word My. The Java objects can be renamed to whatever you prefer, making sure to also change the names in the corresponding resource files and all tests and {{pom.xml}}s) as well.

Note

The content of the <version> element is arbitrary and is used to describe not the version of ServiceMix but of the version of projects that were just created. We just have to use consistently the same version when we reference this project.

How to Build and Package the Components

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

Compiling the Components

In order to, among other things, build and package the components, execute the following command from within hello-world-smx directory:

Code Block

mvn install 

All projects can now be built using the following command on the command-line:

Code Block

$ mvn clean install 

The command above should display the output below:

No Format

[INFO] Scanning for projects...
[INFO] Reactor build order: 
[INFO]   A custom project
[INFO]   A custom project
[INFO]   Hello World JBI Component
[INFO] ----------------------------------------------------------------------------
[INFO] Building A custom project
[INFO]    task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target/classes
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target/test-classes
[INFO] [xbean:mapping {execution: default}]
Checking: org.apache.servicemix.samples.helloworld.MyComponent
Checking: org.apache.servicemix.samples.helloworld.MyEndpoint
[INFO] Generating META-INF properties file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/services/org/apache/xbean/spring/http/
org.apache.servicemix.samples.helloworld/1.0 for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating Spring 2.0 handler mapping: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/spring.handlers 
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating Spring 2.0 schema mapping: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/spring.schemas 
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating HTML documentation file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.html 
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating XSD file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd 
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating WIKI documentation file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.wiki 
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
Warning, could not load class: org.apache.servicemix.samples.helloworld.MyEndpoint
[INFO] ...done.
Downloading: http://repo.mergere.com/maven2/xml-security/xmlsec/1.3.0/xmlsec-1.3.0.pom
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
Downloading: http://repo.mergere.com/maven2/wss4j/wss4j/1.5.0/wss4j-1.5.0.pom
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
[INFO] [jbi:generate-jbi-component-descriptor]
[INFO] Generating jbi.xml
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 3 source files to /Users/bsnyder/src/hello-world-smx/hello-world-su/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /Users/bsnyder/src/hello-world-smx/hello-world-su/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/surefire-reports

-------------------------------------------------------
 T E S T S
-----------------------------------
No Format

...
[INFO] --------------------
Running org.apache.servicemix.samples.helloworld.MySpringComponentTest
<hello>Hello World! Message [<hello>Ski Colorado!</hello>] contains [28] bytes</hello>.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.47 sec

Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT.jar
[INFO] [jbi:jbi-component]
[INFO] Generating installer /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT-installer.zip
[INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-----------------------------su-1.0-SNAPSHOT-installer.zip
[INFO] Reactor Summary:[install:install]
[INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT.jar to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT.jar
[INFO] Installing /Users/bsnyder/src/hello---------------------------------------------------------
[INFO] Hello World Service Assembly .......................... SUCCESS [11.583s]
[INFO] Hello World Service Unit .............................. SUCCESS [0.656s]
[INFO] Hello World JBI Sample ................................ SUCCESS [1.517s]
[INFO] world-smx/hello-world-su/target/xbean/hello-world-su.xsd to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT.xsd
[INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.html to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT-schema.html
[INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT-installer.zip to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT-installer.zip
[INFO] ----------------------------------------------------------------------------
[INFO] Building A custom project
[INFO]    task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-sa/target
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/classes
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world--------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14 seconds
[INFO] Finished at: Fri Dec 01 00:35:06 MST 2006
[INFO] Final Memory: 13M/25M
[INFO] ------------------------------------------------------------------------

Upon successful execution of the install goal, look for the BUILD SUCCESSFUL output as shown above. In addition, because each pom.xml has been given a name, each project can be easily identified. If instead you see the BUILD FAILED output, you'll need to look at the rest of the output to troubleshoot the issue. In case this success information does not appear, the output will provide some information about what might have gone awry. Assistance with any issue you might experience is available from the ServiceMix community via the ServiceMix mailing lists archive.

Testing the Components

Performing automated testing of the components is possible via Maven as well. Because the ServiceMix root POM prevents tests from being executed at the top level, this functionality must be activated so that the coponents can be tested. To do so, the <build> element of the hello-world-se/pom.xml must be augmented using the following content:

Code Block

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>false</skip><!-- this overrides the ServiceMix root POM's setting for test execution -->
        </configuration>
      </plugin>
   </plugins>
</pluginManagement>

By adding the configuation above, the install goal will now including test execution in addition to building and packaging the components. To run the tests, execute the test goal this time and you should see the following output:

Code Block

$ mvn test
No Format

[INFO] Scanning for projects...
[INFO] ---sa/target/test-classes
[WARNING] 
        Artifact junit:junit:jar:3.8.1:test retains local scope 'test' overriding broader scope 'compile'
        given by a dependency. If this is not intended, modify or remove the local scope.

[INFO] [jbi:generate-jbi-service-assembly-descriptor]
[INFO] Generating jbi.xml
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] No sources to compile
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jbi:jbi-service-assembly]
[INFO] [jar:jar]
[INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/hello-world-sa-1.0-SNAPSHOT.jar
[INFO] [install:install]
[INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/hello-world-sa-1.0-SNAPSHOT.jar to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-sa/1.0-SNAPSHOT/hello-world-sa-1.0-SNAPSHOT.zip
[INFO] ----------------------------------------------------------------------------
[INFO] Building Hello World JBI Component
[INFO]    task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target/classes
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target/test-classes
[INFO] [site:attach-descriptor]
[INFO] [install:install]
[INFO] Installing /Users/bsnyder/src/hello-world-smx/pom.xml to 
/Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-smx/1.0-SNAPSHOT/hello-world-smx-1.0-SNAPSHOT.pom
[INFO] 
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] -------------------------------------------------------------------------
[INFO] BuildingA custom project ...................................... SUCCESS [30.738s]
[INFO] A custom project
[INFO]    task-segment: [test ...................................... SUCCESS [3.080s]
[INFO] Hello World JBI Component ............................. SUCCESS [1.547s]
[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] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36 seconds
[INFO] Finished at: Sat Jan 06 16:59:57 MST 2007
[INFO] BUILD SUCCESSFULFinal Memory: 15M/28M
[INFO] ------------------------------------------------------------------------
...
Note
titleTODO

Maybe add further testing at the end of the tutarial ("how to continue when having the working example")

Generation and Deployment of the SA

The execution of the install goal above packages not only each component individually, it also packages the components together into a single SA. Of course, the code does not yet do anything, but we can already deploy the SA ServiceMix by switching to the hello-world-se/hello-world-sa directory and executing the jbi:projectDeploy goal like so:

Code Block

$ mvn jbi:projectDeploy

This tells the Maven JBI plugin to deploy the components to ServiceMix. When the deployment is complete, ServiceMix will output the following:

No Format

INFO  - ServiceAssemblyLifeCycle       - Starting service assembly: hello-world-sa

As long as you see the BUILD SUCCESSFUL message in the output continue to the next section to give each project a unique name.

Give Each of the Maven Subprojects a Name

Notice in the output above that there are a two projects named A custom project. This is because the archetypes create projects with this generic name. Let's give each project a unique name via each component's pom.xml file. This name will allow Maven's output to denote a component's name in its output making our development work a bit easier. To name each project, simply edit each pom.xml and replace <name>A custom project</name> with an appropriate name. Below are the instructions for naming each component's project:

  • Edit hello-world-sa/pom.xml and replace <name>A custom project</name> with <name>Hello World Service Assembly</name>
  • Edit hello-world-su/pom.xml and replace <name>A custom project</name> with <name>Hello World Service Unit</name>

Now when the projects are built you will no longer see a project named A custom project. Instead you'll now see Hello World Service Unit and Hello World Service Assembly. Rebuild the projects again using the mvn clean install command on the command-line to see the changeThis output tells us that the SA was successfully deployed to ServiceMix.

...

Note
titleDeploying Component Dependencies

When working with the jbi:projectDeploy you may want to disable dependency deployment. When deploying to a server which has other components sharing these dependencies, they can cause problems during deployment. To stop the Maven JBI plugin from undeploying and redeploying dependencies each time, alter its configuration by disabling the deployment of dependencies using the following:

Code Block
<build>
<plugins>
  <plugin>
    <artifactId>jbi-maven-plugin</artifactId>
    <configuration>
      <deployDependencies>false</deployDependencies>
    </configuration>
  </plugin>
</plugins>
</build>

The configuration above introduces the deployDependencies element to the Maven JBI plugin and sets it to false.

For a few more configurable options on the Maven JBI plugin, see also Ability to configure jbi:projectDeploy goal to exclude updating dependencies.

Adding Functionality to the Component

We're now ready to add a bit of functionality to the component. Using an IDE like IntelliJ IDEA or Eclipse make this task much easier. The steps described here apply to Eclipse.

Tip
titleGenerate Eclipse Project Files

In order to import the SE into Eclipse, tell Maven to generate the necessary project and classpath files, switch to the hello-world-se directory and execute the following Maven goal:

Code Block

$ mvn eclipse:eclipse

This will allow the SE to be imported into Eclipse for adding functionality.

Note
titleTODO

The default implementation of the component accepts InOut MEPs (ADD
LINK TO FURTHER READING CONCERNING MEPs) and return the input content
as the out message. This is already nearly what we want.

OUTLINE for further work:

  • Get Messages
  • read Messages
  • Wiki Markup
    count the bytes
    Maybe easiest by XSLT endpoint (can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.) see \[ servicemix-saxon\|servicemix-saxon\]
  • send a message back
  • Configure SA so that the example receives messages
    create & populate
    C:\hello-world-SE-SU-SA\hello-world-SU\src\main\resources\servicemix.xml
  • as MyDeployer extends AbstractXBeanDeployer create xbean.xml for SU
  • make something send messages (eg quartz timer, HTTP POST,...) and dump the answer (eg TraceComponent, FireWriter, EIP,...)
  • add a chapter what user may do now / "how to continue when having the working example"

Classpath for SU to include manually till v3.1, see mail

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

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

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.html

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 version14
http://www.servicemix.org/site/creating-a-standard-jbi-component.html version26
are already fully incorporated in the mentioned versions, so delete content and point from there to here (and delete note at the very top)

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

provide additional reading
Creating a protocol bridge.for a "bigger" example
The examples page lists examples providing more information, showing further possibilities and components.

...