| By Robert Davies, James Strachan | Article Rating: |
|
| August 10, 2005 10:00 AM EDT | Reads: |
49,717 |
Working with JBI Properties
In ServiceMix you can access the JBI message properties as a Map and work natively with it in Groovy using various mechanisms. e.g.
// lets output some message properties
outMessage.properties.foo = "hello"
outMessage.properties.someList = [1, 2, 3]
or use an intermediate object if you've lots of properties to set
def props = outMessage.properties
props.foo = "hello"
props.someList = [1, 2, 3]
or just use the native Map/property syntax
outMessage.properties = [foo:"hello", someList:[1, 2, 3]]
Generating Output
Groovy provides various mechanism for generating the output (whether it is the result of a service or a transformation). Which mechnism you use depends on your use case and personal preference.
String Templates
You can use Groovy string templates to output XML, which is a nice, simple way to generate blocks of XML with dynamic content:
outMessage.bodyText = """
<hello>
<world person="$inMessage.properties.name"/>
</hello>
"""
Notice the user above of the input messages's 'name' property, which is equivalent to the expression
inMessage.getProperty("name")
POJO Return Values
You can return a POJO as the body of a message - which other components can either transform or the default Marshaler will figure out the right thing to do.
// lets output the body as a POJO
outMessage.body = [3, 2, 1]
Using Groovy Markup
Groovy supports a simple and concise markup mechanism which can be used to programatically generate some XML markup (either DOM, SAX or any other XML model) while retaining the full power of Groovy within the control flow of the markup.
// lets output some XML using GroovyMarkup
outMessage.body = builder.hello(version:1.2) {
world(person:inMessage.properties.name, location:'London')
}
Conclusion
If you are interested in SOA, EDA and integration please take a look at the ServiceMix project and see if it can help you. We welcome contributions!
Resource ServiceMix: http://servicemix.org/
Published August 10, 2005 Reads 49,717
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Robert Davies
Rob Davies, director of open source development at IONA, has more than 20 years of experience developing high-performance distributed enterprise systems and products for telecom and finance corporations. He is responsible for leading the development of IONA's FUSE family of open source products, which are based on leading projects at the Apache Software Foundation. Rob is a founder of the Apache ActiveMQ, Apache ServiceMix and Apache Camel projects. Prior to joining IONA, Rob served as the founder and vice president of product development at LogicBlaze, which was acquired by IONA in 2007. Previously, Rob served as founder and CTO of integration software developer SpiritSoft.
More Stories By James Strachan
James Strachan, technical director at IONA, is responsible for helping the Company provide open source offerings for organizations requiring secure, high-performance distributed systems and integration solutions. He is heavily involved in the open source community, and has co-founded several Apache projects, including ActiveMQ, Camel, Geronimo and ServiceMix. He also created the "Groovy" scripting language and additional open source projects such as dom4j, jaxen and Jelly. Prior to joining IONA, James spent more than 20 years in enterprise software development. Previously, James co-founded LogicBlaze, Inc., an enterprise open source company acquired by IONA. Prior to that, he founded SpiritSoft, Inc., a company providing enterprise Java middleware services.
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?





































