Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

This component has been deprecated in favor to servicemix-scripting component.

...

Before we go into detail of how you can work with JBI and Groovy in ServiceMix, lets show a simple hello world kinda example.

...

...

As you can see the component is configured with a piece of Groovy to execute when the service is invoked. (BTW if you wanna see this script in action try the test case and XML config file.

...

Its often handy to keep track of state across requests. There is a variable called 'bindings' which you can use to maintain state...

...

...

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.

...

or use an intermediate object if you've lots of properties to set

...

...

or just use the native property syntax

...

...

Generating output

Groovy provides various mechanism for generating the output (whether it is the result of a service or a transformation). Which mechanism you use depends on your use case and personal preference.

...

You can use Groovy string templates to output XML, which is a nice, simple way to generate blocks of XML with dynamic content

...

...

Notice the user above of the input messages's 'name' property, which is equivalent to the expression

...

...

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.

...

...

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.

...

...