Versions Compared

Key

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

...

Wiki Markup
Notice that not only do we see that the build was successful, but also note the text in the output above that was printed by the test (*<hello>Hello World! Message \[<hello>Ski Colorado!</hello>\] contains \[28\] bytes.</hello>*). This is the message we were expecting to be output from the test. So if you see this, you just wrote a JBI component and tested it successfully. Now this SU needs to be wrapped in a SA so it can be deployed to the JBI container. 

Wrapping the Service Unit in a Service Assembly

The component we created above and packaged as a SU cannot be directly deployed to a JBI container until it's wrapped in a SA. This can be done by creating a SA project with a dependency on the SU. From within the hello-world-smx directory, execute the following commands to create the Maven project for the SA:

Code Block

$ pwd
/Users/bsnyder/src/hello-world-smx/hello-world-se
$ cd .. 
$ mvn archetype:create \
    -DarchetypeGroupId=org.apache.servicemix.tooling \
    -DarchetypeArtifactId=servicemix-service-assembly \
    -DarchetypeVersion=3.1-incubating \
    -DgroupId=org.apache.servicemix.samples.helloworld \
    -DartifactId=hello-world-sa \ 
    -DremoteRepositories=http://people.apache.org/repo/m2-incubating-repository

Upon successful execution of the archetype:create goals, look for the BUILD SUCCESSFUL output as displayed below:

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] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] ************************************************************** 
[INFO] Starting Jakarta Velocity v1.4
[INFO] RuntimeInstance initializing.
[INFO] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
[INFO] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[INFO] Resource Loader Instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[INFO] ClasspathResourceLoader : initialization starting.
[INFO] ClasspathResourceLoader : initialization complete.
[INFO] ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[INFO] Default ResourceManager initialization complete.
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[INFO] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[INFO] Created: 20 parsers.
[INFO] Velocimacro : initialization starting.
[INFO] Velocimacro : adding VMs from VM library template : VM_global_library.vm
[ERROR] ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
[INFO] Velocimacro : error using  VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: 
Unable to find resource 'VM_global_library.vm'
[INFO] Velocimacro :  VM library template macro registration complete.
[INFO] Velocimacro : allowInline = true : VMs can be defined inline in templates
[INFO] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
[INFO] Velocimacro : allowInlineLocal = false : VMs defined inline will be  global in scope if allowed.
[INFO] Velocimacro : initialization complete.
[INFO] Velocity successfully started.
[INFO] [archetype:create]
[INFO] Defaulting package to group ID: org.apache.servicemix.samples.helloworld
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating Archetype: servicemix-service-assembly:3.1-incubating
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.servicemix.samples.helloworld
[INFO] Parameter: packageName, Value: org.apache.servicemix.samples.helloworld
[INFO] Parameter: basedir, Value: /Users/bsnyder/src/hello-world-smx
[INFO] Parameter: package, Value: org.apache.servicemix.samples.helloworld
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: hello-world-sa
[WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 71,column 18] : 
${servicemix-version} is not a valid reference.
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] Archetype created in dir: /Users/bsnyder/src/hello-world-smx/hello-world-sa
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Fri Jan 05 23:40:32 MST 2007
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------

The hello-world-smx directory should now contain the following two directories:

Code Block

$ ls 
hello-world-sa hello-world-se

If you see the above directories, proceed to the next step below. If instead you see the BUILD FAILED output, you'll need to analyze the rest of the output to troubleshoot the issue. Assistance with any issue you might experience is available from the ServiceMix community via the ServiceMix mailing lists archive.

Now that we have a project for the SA, we need to edit the POM so that the project depends upon the JBI component we created above. This can be done by editing the POM for the SA to add a dependency upon the hello-world-se as listed below:

Code Block

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

Upon adding this dependency to the POM, build the project using the command below:

Code Block

$ cd hello-world-sa
$ mvn install 

...

Deploying the Component

Now it's time to deploy this component to the JBI container. Because the component was just built above, you should now see a filed named hello-world-se-1.0-SNAPSHOT-installer.zip in the target directory of the project. This is the component all packaged up and ready to be deployed. To deploy the component, simply copy the ZIP file to the ServiceMix install directory. You can do this before starting ServiceMix or while ServiceMix is running.

As long as the component deploys properly, you're now ready to create a deploy a configuration for the component.

Deploying a Service Unit That Depends Upon the Component

In order to actually make use of the component, you will need to deploy a configuration for the component. Once JBI components are deployed to the JBI container, they're just hanging out there waiting for a configuration to be deployed to them. This is why JBI is often referred to as a container of containers. The JBI container accepts deployment of JBI components and JBI components accept deployment of service units (SUs) that configure them. This is very similar to the way RAR files work in JavaEE-land. RAR files are generic components that are deployed to the JavaEE container that accept the deployment of a configuration file to tell it how to run. This is exactly how JBI components work. To achieve this, you need to create a JBI SU that depends on the JBI component in it's pom.xml file and to deploy the SU to the JBI container as well.

In the case of the Hello World SE, we're lucky that there are no configuration options really, so all we need to do is create SU that depends on the Hello World SE and deploy that. To do this, use the command below:

Panel

$ mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-service-unit \
-DarchetypeVersion=3.1-incubating \
-DgroupId=org.apache.servicemix.samples.helloworld.se \
-DartifactId=hello-world-su \
-DremoteRepositories=http://people.apache.org/repo/m2-incubating-repositoryImage Added

This create a directory named hello-world-su. Now edit the pom.xml file to add the following dependency on the Hello World SE:

Panel

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

This tells Maven that the hello-world-su project depends upon the hello-world-se project. After compiling the hello-world-su, copy the JAR file to the ServiceMix deploy directory. As long as it starts up without error, you're ready to begin sending messages to it.

This is a work in progress

Incorporating the Projects Into a Top Level POM

...

Now when the projects are built you will no longer see a project named A custom project. Instead you'll now see Hello World SE Service Unit and Hello World Service Assembly. Rebuild the projects again using the mvn clean install command on the command-line to see the change.

Deploying the Component

Now that the SA is built, we're ready to deploy it to the JBI container.

...