Creating a Hello World JBI Binding Component
Notewarning | ||
---|---|---|
| ||
|
Tip | ||
---|---|---|
| ||
NOTE: Before beginning this tutorial, please take the time to read the FAQ entry titled Should I Create My Own JBI Components?. It is very important that you understand the reason for developing a JBI binding component and this FAQ entry will explain this. |
This tutorial describes how to create a very simple Hello World style of JBI binding component. This tutorial is as minimalistic as possible so as to focus on key concepts and not drown in details. The Hello World binding component will respond to all requests with the message:
Panel | |
---|---|
|
The following sections will walk through the creation, packaging, testing and deployment of the Hello World binding component.
Prerequisites
- Maven 2.0.4 7 or higher
- If you have never used Maven previously the Maven Getting Started Guide explains some valuable concepts surrounding Maven
- ServiceMix 3.2.1 .2 or higher
- A broadband internet connection so Maven can automatically download dependencies
...
Panel |
---|
$ mvn archetype:create \ |
...
The first three parameters to the mvn
command (-DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-binding-component -DarchetypeVersion=3.2.1.2) identify which Maven archetype to use for the archetype:create
goal, while the last two parameters (-DgroupId=org.apache.servicemix.samples.helloworld.bc -DartifactId=hello-world-bc) uniquely identify the Maven project that is being generated. The groupId
is used as the Java package and the artifactId
is used as the project name. Therefore, only alphanumeric characters are valid values for the groupId
and artifactId
parameters.
Tip |
---|
The value of the |
...
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.bc [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating Archetype: servicemix-binding-component:3.2.1.2 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: org.apache.servicemix.samples.helloworld.bc [INFO] Parameter: packageName, Value: org.apache.servicemix.samples.helloworld.bc [INFO] Parameter: basedir, Value: /Users/bsnyder/src/hello-world-smx [INFO] Parameter: package, Value: org.apache.servicemix.samples.helloworld.bc [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: artifactId, Value: hello-world-bc [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 85,column 16] : ${servicemix-version} is not a valid reference. [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 90,column 16] : ${servicemix-version} is not a valid reference. [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 115,column 18] : ${xbean-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-bc [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Tue Mar 06 18:27:08 MST 2007 [INFO] Final Memory: 4M/8M [INFO] ------------------------------------------------------------------------ |
...
src/main/java/org/apache/servicemix/samples/bc/MyBootstrap.java
- Implementsjavax.jbi.component.Boostrap
which is called by the JBI container as part of the component lifecycle (i.e.g, when the component is installed and uninstalled). This is where you place logic to set up and tear down things when the component is started and stopped. This class is no longer needed.
src/main/java/org/apache/servicemix/samples/bc/MyComponent.java
- Extends theDefaultComponent
, a convenience class that makes creating JBI components much easier and provides some additional lifecycle management for the BC when it's deployed to the JBI container. This class should be fleshed out by overriding methods in theDefaultComponent
to configure and initialize the component.
...
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: unmigrated-wiki-markup
*<?xml version="1.0" encoding="UTF-8"?><hello>Message \ [Ski Colorado!\] contains \ [13\] 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 your first JBI BC successfully.
...
Code Block |
---|
$ pwd /Users/bsnyder/src/hello-world-smx/hello-world-bc $ cd .. $ mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-service-assembly \ -DarchetypeVersion=3.2.1.2 \ -DgroupId=org.apache.servicemix.samples.helloworld \ -DartifactId=hello-world-sa |
...
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.2.1.2 [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] ------------------------------------------------------------------------ |
...
Note | ||
---|---|---|
| ||
The default implementation of the component accepts InOut MEPs (ADD OUTLINE for further work:
Classpath for SU to include manually till v3.1, see mail manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units INS When to use this JBI Component provide exact position in the SVN! maybe moving the content of overlapping existing docus to this new tut and - where appropriate - delete the old ones (only leaving a redirect). This shall already include everything stated at provide additional reading |
...