Spin: How to transform from Java Object into XML in Groovy

739 views
Skip to first unread message

Bernd Rücker (camunda)

unread,
Jan 6, 2015, 8:40:33 AM1/6/15
to camunda-...@googlegroups.com

Hey guys.

 

Another Spin question I could not quickly figure out via the docs or examples.

 

I want to use Groovy to:

-          create a new process variable

-          use xPath to get

-          but have a Java Object as process variable it is derived from

 

That works perfectly as expression:

 

$XML(application).xPath('/creditorApplication/bankIdentifierCode').element().textContent();        

 

But XML() is not usable in Groovy – I can only use S – but then the Java Object is used and not transformed into XML. But

 

S(application).xPath('/creditorApplication/bankIdentifierCode').element().textContent();        

 

gives:

 

Caused by: java.lang.IllegalArgumentException: SPIN-01001 Unsupported input of type 'com.camunda.demo.webinar.dataconnect.CreditorApplication'

     at org.camunda.spin.impl.logging.SpinCoreLogger.unsupportedInputParameter(SpinCoreLogger.java:39)

     at org.camunda.spin.impl.SpinFactoryImpl.createSpin(SpinFactoryImpl.java:56)

     at org.camunda.spin.Spin.S(Spin.java:64)

 

How can I achieve this?

 

Thanks

Bernd

Christian Lipphardt

unread,
Jan 6, 2015, 8:53:26 AM1/6/15
to
Hi Bernd,

Did you try using S(application, DataFormats.xml()) ?
It should be exactly the same as XML(application). See Spin documentation[1].

Otherwise you could use the powerful XML features of Groovy directly [2|.

[1]: http://docs.camunda.org/latest/api-references/spin/#handling-xml-reading-xml
[2]: http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper
signature.asc

Sebastian Menski

unread,
Jan 6, 2015, 9:36:30 AM1/6/15
to camunda-...@googlegroups.com
Hi Bernd,

Christians answer is correct just some more explanation why S fails and XML is not available. If you use S it tries to detect the dataformat, which is
unknown for your own class. But you can always specify the format explicit as second parameter. Depending on the format you specify it may be possible
to map a java object to this format and allow Spin to work with it. This is the case for our XML and JSON formats. We decided to remove the XML and JSON
binding from the script languages because Javascript already has an JSON object defined. So we wanted to be consistent for all formats and script languages
and only added the S binding to the scripting environments knowing there is always the possibility to explicitly specify the data format for the S function. 

Cheers,
Sebastian

Bernd Rücker (camunda)

unread,
Jan 6, 2015, 10:32:13 AM1/6/15
to camunda-...@googlegroups.com

Hi Christian.

 

I did try

S(application, xml())

 

as indicated in the docs – but xml() is not available in Groovy as well. Daniel gave me the hint to use “application/xml” as String – and this works:

 

S(application, 'application/xml').xPath(…

 

Maybe that should be added as hint in the docs accordingly?

 

Thanks and cheers

Bernd

 

Von: camunda-...@googlegroups.com [mailto:camunda-...@googlegroups.com] Im Auftrag von Christian Lipphardt
Gesendet: Dienstag, 6. Januar 2015 14:53
An: camunda-...@googlegroups.com
Betreff: Re: [camunda-bpm-users] Spin: How to transform from Java Object into XML in Groovy

 

Hi Bernd,

Did you try using S(application, xml()) ?


It should be exactly the same as XML(application). See Spin documentation[1].

Otherwise you could use the powerful XML features of Groovy directly [2|.

[1]: http://docs.camunda.org/latest/api-references/spin/#handling-xml-reading-xml
[2]: http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper

On 06.01.15 14:38, Bernd Rücker (camunda) wrote:

--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/e3445f13.000014c0.00000044%40ca-ruecker.
For more options, visit https://groups.google.com/d/optout.

 

--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/54ABE8D4.70800%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Menski

unread,
Jan 6, 2015, 10:35:19 AM1/6/15
to camunda-...@googlegroups.com
Hi Bernd,

you have to add 

import static org.camunda.spin.DataFormats.*;

to your groovy script to use xml() and json() as shown in this example:

Cheers,
Sebastian
Reply all
Reply to author
Forward
0 new messages