You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by tomdog <to...@bergstein-soraic.de> on 2006/05/27 22:49:14 UTC

Groovy example

Does anybody have a nice Groovy example that shows how to retieve XML content
from the incomming message payload and put the retrieved values into the out
message?
--
View this message in context: http://www.nabble.com/Groovy+example-t1692744.html#a4593935
Sent from the ServiceMix - User forum at Nabble.com.


Re: Groovy example

Posted by tomdog <to...@bergstein-soraic.de>.
The example helps somehow. I used XmlSlurper() to retrieve specific tags from
the inMessage.bodyText (see below), but I'm not sure if this is a good
practice.


<sm:activationSpec componentName="transformThisResp"
service="test:transformThisResp" endpoint="endpoint">
	<sm:component>
		<bean class="org.apache.servicemix.components.groovy.GroovyComponent">
			<property name="scriptText">
				<value><![CDATA[
				
def node = new XmlSlurper().parseText(inMessage.bodyText)
println "identity: " + node.endpointReference.filter.identity

// Create output message with variable from input
outMessage.bodyText = """
<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
     <soapenv:Body>
         <submitThisResponse xmlns=\"http://www.my.com/xsd/\">
             <return>$node.endpointReference.filter.identity</return>
         </submitThisResponse>
     </soapenv:Body>
</soapenv:Envelope>
"""
                ]]></value>
			</property>
		</bean>
	</sm:component>
</sm:activationSpec>
--
View this message in context: http://www.nabble.com/Groovy-example-t1692744.html#a4695318
Sent from the ServiceMix - User forum at Nabble.com.


Re: Groovy example

Posted by dajevu <jd...@hireright.com>.
I found several examples in the tests that come with the full source of 3.0
incubator. For example:

<sm:activationSpec componentName="receiver" service="foo:receiver">
	<sm:component>
		<bean class="org.apache.servicemix.components.groovy.GroovyComponent">
			<property name="scriptText">
				<value><![CDATA[

println "Called with inbound message $inMessage"

// lets output some message properties
def me1 = deliveryChannel.createExchangeFactoryForService(new
javax.xml.namespace.QName("http://servicemix.org/cheese/",
"service1")).createInOutExchange()
def in1 = me1.createMessage()
in1.bodyText = inMessage.bodyText
me1.setMessage(in1, "in")
deliveryChannel.sendSync(me1)
println "Received: " + me1.getMessage("out").bodyText

// lets output some message properties
def me2 = deliveryChannel.createExchangeFactoryForService(new
javax.xml.namespace.QName("http://servicemix.org/cheese/",
"service2")).createInOutExchange()
def in2 = me2.createMessage()
in2.bodyText = me1.getMessage("out").bodyText
me2.setMessage(in2, "in")
deliveryChannel.sendSync(me2)
println "Received: " + me2.getMessage("out").bodyText

// lets output some non-xml body
outMessage.bodyText = me2.getMessage("out").bodyText

            		]]>
				</value>
			</property>
		</bean>
	</sm:component>
</sm:activationSpec>

Hope that helps,

jeff
--
View this message in context: http://www.nabble.com/Groovy+example-t1692744.html#a4606156
Sent from the ServiceMix - User forum at Nabble.com.