Versions Compared

Key

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

...

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

Testing the Hello World SE

Thanks to the archetype, testing the component is very easy because it already created a test. All that is necessary 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 open this test and change line #36 from this:

Code Block

me.getInMessage().setContent(new StringSource("<hello>world</hello>"));

to something more meaningful, like this:

Code Block

me.getInMessage().setContent(new StringSource("<hello>Ski Colorado!</hello>"));

To execute the test, simply run the Maven install goal from within the hello-world-se directory like so:

Code Block

$ mvn install 

Below is the output that will print to the console:

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\] ------------------------------------------------------------------------

Notice that not only do we see that the build was successful, but notice the bold text of the message that was printed. If you see this, you just wrote your a JBI component and tested it successfully.

...

Creating the Maven Subprojects For the Service Unit and Service Assembly

...