Versions Compared

Key

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

...

The focus of this section is on the creation of a JBI component. For this task, a Maven archetype will be used to create a Maven project skeleton to house the component. Maven archetypes are templates for Maven projects that jumpstart project creation via the automation of repetitive tasks by following standard conventions. The result of using an archetype to create a Maven project is a directory structure, a Maven POM file and, depending on the archetype being used, sometimes Java objects and JUnit tests.

Note

As this text describes how to create a Hello World service engine and pack it into a SU and SA, the project name is hello-world-se and each piece of the SA puzzle are named using a similar pattern. For a given project, the IDs and names shall be altered such that they describe the purpose or function of the given piece of the SA.

1) Create a directory named hello-world-smx and switch to that directory:

...

Again, Maven creates a directory using the artifactId provided (printed in green in the command and output) as the directory name. Inside this directory resides the pom.xml and the src directory.

...

The implementation of this method was provided by the servicemix-service-engine Maven archetype and is shown in the code snippet above. Because the archetype can be used to create a consumer or a provider service engine, this method is very generic and contains a conditional block for handling either a consumer or a provider role. But this method will still require us to make the decision of which style of Message Exchange Pattern (MEP) to handle as well. In the case of the Hello World SE, we know that it is a provider so it will need to send a return message. Therefore it will need to handle an In-Out MEP.

Image Removed

Instead So instead of having MyEndpoint extend the very basic Endpoint class, we're going to extend a different class that is specifically for provider endpoints named
ProviderEndpoint.

Image Added

Notice the diagram above showing the class hierarchy of Endpoint. The ProviderEndpoint supplies some additional conveniences for provider components and will make the job of implementing MyEndpoint as a provider much easier. So change the definition of MyEndpoint from this:

...

Because the ProviderEndpoint.process() method already handles an In-Out MEP, MyEndpoint will simply need to override the ProviderEndpoint.processInOut() method. Below is the content for implementing this method:

Code Block
protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
	SourceTransformer sourceTransformer = new SourceTransformer();
	String inMessage = sourceTransformer.toString(in.getContent()); 
	out.setContent(new StringSource("<hello>Hello World! Message [" + inMessage + "] contains [" + inMessage.getBytes().length + "] bytes</hello>."));
}

...

This method is the logic for the Hello World SE

...

. We're not doing anything complex here at all in order to keep this tutorial very simple. Now it's time to test the component.

Testing the Hello World SE

Thanks to the archetypeThanks to the archetype, testing the component is very easy because it already created a test. All that is necessary The only change we'll make is to change the string being sent by the client code. In the src/test/java directory is the org.apache.servicemix.samples.helloworld.se.MySpringComponentTest test. Simple Simply open this test and change line #36 from this:

...

Panel

Wiki Markup
\[INFO\] Scanning for projects...
\[INFO\] ----------------------------------------------------------------------------
\[INFO\] Building Hello World Service Engine
\[INFO\]    task-segment: \[install\]
\[INFO\] ----------------------------------------------------------------------------
\[INFO\] \[xbean:mapping \{execution: default\}\]
Checking: org.apache.servicemix.samples.helloworld.se.MyComponent
Checking: org.apache.servicemix.samples.helloworld.se.MyEndpoint
\[INFO\] Generating META-INF properties file: /Users/bsnyder/src/hello-world-smx/hello-world-se/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-se/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-se/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-se/target/xbean/hello-world-se.xsd.html for namespace: http://org.apache.servicemix.samples.helloworld/1.0
\[INFO\] Generating XSD file: /Users/bsnyder/src/hello-world-smx/hello-world-se/target/xbean/hello-world-se.xsd for namespace: http://org.apache.servicemix.samples.helloworld/1.0
\[INFO\] Generating WIKI documentation file: /Users/bsnyder/src/hello-world-smx/hello-world-se/target/xbean/hello-world-se.xsd.wiki for namespace: http://org.apache.servicemix.samples.helloworld/1.0
Warning, could not load class: org.apache.servicemix.samples.helloworld.se.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\]
\[INFO\] Nothing to compile - all classes are up to date
\[INFO\] \[resources:testResources\]
\[INFO\] Using default encoding to copy filtered resources.
\[INFO\] \[compiler:testCompile\]
\[INFO\] Nothing to compile - all classes are up to date
\[INFO\] \[surefire:test\]
\[INFO\] Surefire report directory: /Users/bsnyder/src/hello-world-smx/hello-world-se/target/surefire-reports

Wiki Markup
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.apache.servicemix.samples.helloworld.se.MySpringComponentTest
*<hello>Hello World! Message \[<hello>Ski Colorado!</hello>\] contains \[28\] bytes.</hello>*
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.009 sec

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

Wiki Markup
\[INFO\] \[jar:jar\]
\[INFO\] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-se/target/hello-world-se-1.0-SNAPSHOT.jar
\[INFO\] \[jbi:jbi-component\]
\[INFO\] Generating installer /Users/bsnyder/src/hello-world-smx/hello-world-se/target/hello-world-se-1.0-SNAPSHOT-installer.zip
\[INFO\] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-se/target/hello-world-se-1.0-SNAPSHOT-installer.zip
\[INFO\] \[install:install\]
\[INFO\] Installing /Users/bsnyder/src/hello-world-smx/hello-world-se/target/hello-world-se-1.0-SNAPSHOT.jar to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-se/1.0-SNAPSHOT/hello-world-se-1.0-SNAPSHOT.jar
\[INFO\] Installing /Users/bsnyder/src/hello-world-smx/hello-world-se/target/xbean/hello-world-se.xsd to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-se/1.0-SNAPSHOT/hello-world-se-1.0-SNAPSHOT.xsd
\[INFO\] Installing /Users/bsnyder/src/hello-world-smx/hello-world-se/target/xbean/hello-world-se.xsd.html to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-se/1.0-SNAPSHOT/hello-world-se-1.0-SNAPSHOT-schema.html
\[INFO\] Installing /Users/bsnyder/src/hello-world-smx/hello-world-se/target/hello-world-se-1.0-SNAPSHOT-installer.zip to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-se/1.0-SNAPSHOT/hello-world-se-1.0-SNAPSHOT-installer.zip
\[INFO\] ------------------------------------------------------------------------
\[INFO\] BUILD SUCCESSFUL
\[INFO\] ------------------------------------------------------------------------
\[INFO\] Total time: 15 seconds
\[INFO\] Finished at: Thu Jan 04 15:21:00 MST 2007
\[INFO\] Final Memory: 13M/24M
\[INFO\] ------------------------------------------------------------------------

unmigrated-wiki-markup
Notice that not only do we see that the build was successful, but
notice
 also note the bold text of the message that was printed (*<hello>Hello World! Message \[<hello>Ski Colorado!</hello>\] contains \[28\] bytes.</hello>*). This is the message we were expecting to be output. If you see this, you just wrote
your
 a JBI service engine component and tested it successfully.  

...

Creating the Maven Subprojects For the Service Unit and Service Assembly

...