How to consume a webservice Rest on BonitaSoft 7.4

1
0
-1

Hi people!

I'm trying to consume a webservice that I'd produces with an object like:{"tipo":null,"servidor":null,"cname":null,"nome":"example.com","ip":"x.x.x.x","ip_servidor":null}

I've added the connector Rest and I'm configuring it. I can already do the GET and get the string. But how to extract the information and insert into the variables?

Thanks

Felipe Medeiros

1 answer

1
0
-1

Hi,

Using the GET REST Connector, you should be able to manipulate the response as an object on the Output operations screen of the connector configuration. The output is called bodyAsObject. You can either store that object in a variable or write a Groovy script to modify it before storing it in a variable.

Cheers

Comments

Submitted by felipe_22 on Fri, 03/17/2017 - 14:12

Hi Lionel Palacin,

Thanks for you answer! It´s exactly I'm trying to do!

In fact I need to know more about Groovy script as you just sayed. Could you help me with this?

For example, I want to get the properties nome and ip. So I tryed something like that:

myString = bodyAsObject.nome
myString = bodyAsObject.ip

or I have to use a JsonSluper?

Thanks again!

Submitted by felipe_22 on Tue, 03/21/2017 - 21:37

I tryed this script to get the object:

import groovy.json.JsonSlurper

def Dns = new JsonSlurper().parseText(bodyAsObject)

class Dns {
String nome
String ip
String ip_servidor
String cname
String tipo
String servidor
}

but I get this exception:

No signature of method: groovy.json.JsonSlurper.parseText() is applicable for argument types: (java.util.HashMap) values: [[servidor:null, tipo:null, ip_servidor:null, ip:x.x.x.x, ...]]
Possible solutions: parseText(java.lang.String), parse([B), parse([C), parse(java.io.File), parse(java.io.InputStream), parse(java.io.Reader)

Notifications