Author: chirino
Date: Sun Nov 5 13:30:22 2006
New Revision: 471536
URL: http://svn.apache.org/viewvc?view=rev&rev=471536
Log:
Latest export from confluence
Modified:
incubator/servicemix/site/main/groovy.html
Modified: incubator/servicemix/site/main/groovy.html
URL:
http://svn.apache.org/viewvc/incubator/servicemix/site/main/groovy.html?view=diff&rev=471536&r1=471535&r2=471536
==============================================================================
--- incubator/servicemix/site/main/groovy.html (original)
+++ incubator/servicemix/site/main/groovy.html Sun Nov 5 13:30:22 2006
@@ -36,7 +36,7 @@
<TR>
<TD align="left" valign="middle" nowrap="">
<DIV id="site-breadcrumbs">
-<A href="home.html" title="ServiceMix">ServiceMix</A> > <A
href="home.html" title="Home">Home</A> > <A
href="documentation.html"
title="Documentation">Documentation</A> > <A
href="components.html" title="Components">Components</A> > <A
href="lightweight-components.html" title="Lightweight components">Lightweight
components</A> > <A href="" title="Groovy">Groovy</A>
+<A href="home.html" title="ServiceMix">ServiceMix</A> > <A
href="home.html" title="Home">Home</A> > <A
href="documentation.html"
title="Documentation">Documentation</A> > <A
href="components-list.html" title="Components list">Components
list</A> > <A href="lightweight-components.html"
title="Lightweight components">Lightweight components</A> > <A
href="" title="Groovy">Groovy</A>
</DIV>
</TD>
<TD align="right" valign="middle" nowrap="">
@@ -113,25 +113,69 @@
<!--
<div class="pagetitle">Groovy</div>
-->
- <DIV class="wiki-content">
-<P>ServiceMix supports <SPAN class="nobr"><A
href="http://groovy.codehaus.org/" title="Visit page outside Confluence"
rel="nofollow">Groovy<SUP><IMG class="rendericon"
src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0"
width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> which allows
Groovy scripts to be used as endpoints, transformers or services. This allows
you to combine the power of the Groovy scripting language with the ServiceMix
JBI container and any off the shelf JBI components to create a very flexible
and agile integration solution.</P>
+ <DIV class="wiki-content"><P>ServiceMix supports <SPAN
class="nobr"><A href="http://groovy.codehaus.org/" title="Visit page outside
Confluence" rel="nofollow">Groovy<SUP><IMG class="rendericon"
src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0"
width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> which allows
Groovy scripts to be used as endpoints, transformers or services. This allows
you to combine the power of the Groovy scripting language with the ServiceMix
JBI container and any off the shelf JBI components to create a very flexible
and agile integration solution.</P>
<P><IMG src="http://groovy.codehaus.org/images/groovy-logo.png"
align="absmiddle" border="0"></P>
-<P>The <SPAN class="nobr"><A
href="http://servicemix.codehaus.org/maven/apidocs/org/servicemix/components/groovy/GroovyComponent.html"
title="Visit page outside Confluence" rel="nofollow">GroovyComponent<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> is
an extension of the <A href="scripting.html" title="Scripting">Scripting</A>
support and supports the same variable bindings.</P>
+<P>The <SPAN class="nobr"><A
href="http://incubator.apache.org/servicemix/dist/servicemix-3.0-incubating/site/servicemix-components/apidocs/org/apache/servicemix/components/groovy/GroovyComponent.html"
title="Visit page outside Confluence" rel="nofollow">GroovyComponent<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> is
an extension of the <A href="scripting.html" title="Scripting">Scripting</A>
support and supports the same variable bindings.</P>
<H2><A name="Groovy-Example"></A>Example</H2>
<P>Before we go into detail of how you can work with JBI and Groovy in
ServiceMix, lets show a simple hello world kinda example.</P>
-
-<P>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 <SPAN class="nobr"><A
href="http://servicemix.codehaus.org/maven/xref-test/org/servicemix/client/ServiceMixClientTest.html"
title="Visit page outside Confluence" rel="nofollow">test case<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> and
<SPAN class="nobr"><A
href="http://svn.servicemix.codehaus.org/*checkout*/branches/servicemix-1.1/base/src/test/resources/org/servicemix/client/example.xml"
title="Visit page outside Confluence" rel="nofollow">XML config file<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN>.</P>
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-xml"><sm:activationSpec componentName=<SPAN
class="code-quote">"myServiceUsingXMLText"</SPAN>
+ service=<SPAN
class="code-quote">"foo:myServiceUsingXMLText"</SPAN>>
+ <SPAN class="code-tag"><sm:component></SPAN>
+ <SPAN class="code-tag"><bean class=<SPAN
class="code-quote">"org.apache.servicemix.components.groovy.GroovyComponent"</SPAN>></SPAN>
+ <SPAN class="code-tag"><property name=<SPAN
class="code-quote">"scriptText"</SPAN>></SPAN>
+ <SPAN class="code-tag"><value></SPAN>
+ <![CDATA[
+
+// lets output some message properties
+outMessage.properties = [foo:<SPAN
class="code-quote">"hello"</SPAN>, someList:[1, 2, 3]]
+
+// lets output some non-xml body
+outMessage.bodyText = """
+<SPAN class="code-tag"><hello></SPAN>
+ <SPAN class="code-tag"><world person=<SPAN
class="code-quote">"$inMessage.properties.name"</SPAN> location=<SPAN
class="code-quote">"London"</SPAN>/></SPAN>
+<SPAN class="code-tag"></hello></SPAN>
+"""
+ ]]>
+ <SPAN class="code-tag"></value></SPAN>
+ <SPAN class="code-tag"></property></SPAN>
+ <SPAN class="code-tag"></bean></SPAN>
+ <SPAN class="code-tag"></sm:component></SPAN>
+ <SPAN class="code-tag"></sm:activationSpec></SPAN></PRE>
+</DIV></DIV>
+<P>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 <SPAN class="nobr"><A
href="http://incubator.apache.org/servicemix/dist/servicemix-3.0-incubating/site/servicemix-core/xref-test/org/apache/servicemix/client/ServiceMixClientTest.html"
title="Visit page outside Confluence" rel="nofollow">test case<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> and
<SPAN class="nobr"><A
href="http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml?revision=HEAD"
title="Visit page outside Confluence" rel="nofollow">XML config file<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN>
.</P>
<P>Now we'll go through the various options which are available when
working with JBI and Groovy in ServiceMix</P>
<H2><A name="Groovy-Maintainingstateacrossrequests"></A>Maintaining state
across requests</H2>
<P>Its often handy to keep track of state across requests. There is a variable
called 'bindings' which you can use to maintain state...</P>
-
+<DIV class="code"><DIV class="codeContent">
+<PRE class="code-xml"><SPAN class="code-tag"><activationSpec
componentName=<SPAN class="code-quote">"myServiceImpl"</SPAN>
service=<SPAN class="code-quote">"foo:myServiceImpl"</SPAN>></SPAN>
+ <SPAN class="code-tag"><component></SPAN>
+ <SPAN class="code-tag"><bean xmlns=<SPAN
class="code-quote">""
class="</SPAN>org.apache.servicemix.components.groovy.GroovyComponent"></SPAN>
+ <SPAN class="code-tag"><property name=<SPAN
class="code-quote">"scriptText"</SPAN>></SPAN>
+ <SPAN class="code-tag"><value></SPAN>
+ <![CDATA[
+if (bindings.counter == null) {
+ bindings.counter = 1
+}
+else {
+ ++bindings.counter
+}
+
+def date = new Date()
+
+outMessage.bodyText = <SPAN class="code-quote">"<SPAN
class="code-tag"><response counter='$bindings.counter'
date='$date'></SPAN><SPAN
class="code-tag"></response></SPAN>"</SPAN>
+ ]]>
+ <SPAN class="code-tag"></value></SPAN>
+ <SPAN class="code-tag"></property></SPAN>
+ <SPAN class="code-tag"></bean></SPAN><SPAN
class="code-tag"></component></SPAN><SPAN
class="code-tag"></activationSpec></SPAN></PRE>
+</DIV></DIV>
<H2><A name="Groovy-WorkingwithJBIproperties"></A>Working with JBI
properties</H2>
@@ -154,7 +198,7 @@
<H2><A name="Groovy-Generatingoutput"></A>Generating output</H2>
-<P>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.</P>
+<P>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.</P>
<H3><A name="Groovy-Stringtemplates"></A>String templates</H3>
@@ -173,7 +217,7 @@
<H3><A name="Groovy-POJOreturnvalues"></A>POJO return values</H3>
-<P>You can return a POJO as the body of a message - which other components can
either transform or the default <SPAN class="nobr"><A
href="http://servicemix.codehaus.org/maven/apidocs/org/servicemix/client/Marshaler.html"
title="Visit page outside Confluence" rel="nofollow">Marshaler<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> will
figure out the right thing to do.</P>
+<P>You can return a POJO as the body of a message - which other components can
either transform or the default <SPAN class="nobr"><A
href="http://incubator.apache.org/servicemix/dist/servicemix-3.0-incubating/site/servicemix-core/apidocs/org/apache/servicemix/jbi/messaging/PojoMarshaler.html"
title="Visit page outside Confluence" rel="nofollow">Marshaler<SUP><IMG
class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif"
height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> will
figure out the right thing to do.</P>
<DIV class="code"><DIV class="codeContent">
<PRE class="code-java"><SPAN class="code-comment">// lets output the body as a
POJO
</SPAN>outMessage.body = [3, 2, 1]</PRE>
@@ -197,8 +241,8 @@
</DIV>
<DIV id="site-footer">
Added by <A
href="http://goopen.org/confluence/users/viewuserprofile.action?username=jstrachan">James
Strachan</A>,
- last edited by <A
href="http://goopen.org/confluence/users/viewuserprofile.action?username=gnodet">Guillaume
Nodet</A> on May 11, 2006
- (<A
href="http://goopen.org/confluence/pages/diffpages.action?pageId=2007&originalId=5186">view
change</A>)
+ last edited by <A
href="http://goopen.org/confluence/users/viewuserprofile.action?username=gnodet">Guillaume
Nodet</A> on Nov 08, 2006
+ (<A
href="http://goopen.org/confluence/pages/diffpages.action?pageId=2007&originalId=14797">view
change</A>)
(<A
href="http://goopen.org/confluence/pages/editpage.action?pageId=2007">edit
page</A>)
</DIV>