Calling "httpGet" from local Groovy

Hey guys,

I’m writing a device type that needs to poke a very complicated XML api and I’d like to debug and code it locally (in Eclipse or else).

Now, I understand that the httpGet is ST supplied wrapper around the Java/Groovy Http class… Is there a way to debug this locally? i.e. making “httpGet” calls on my machine, inside Eclipse or else.

I don’t need to have the call emulated, I just need to figure out which type is returned… I tried it out and I can just supply a closure using “[item].each”… what’s the underlying structure? I can supply the XML in a String : I just want to figure out my algorithm to traverse the nodes in the XML file.


I think the returned response type is variable depending upon the content, but if it’s XML it’s probably a GPathResult object, resulting from parsing the XML.

You could try this:

httpGet(params) {resp->
    log.debug " a GPathResult? ${ instanceof groovy.util.slurpersupport.GPathResult}"
1 Like

Thanks Jim the the pointer in the right direction.

You are correct, the “data” property does contain a GPathResult. I created a mock object that mimick the functionnality of the httpGet method using the Url object and convert the inputstream response into a GPathResult using XmlSlurper.

It works A1.


Looks like I’m hitting a wall while trying to use my web service.

The API returns an XML with a “!DOCTYPE” tag and an external dtd file…

On my local groovy code, I need to configure the XmlSlurper instance like this :

def parser = new XmlSlurper()
parser.setFeature("", false)
parser.setFeature("", false)

If I don’t I get the following errors :

[Fatal Error] :2:10: DOCTYPE is disallowed when the feature “” set to true.
Caught: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 10; DOCTYPE is disallowed when the feature “” set to true.

On SmartThings, I get an XmlSlurper object directly from the response’s data property… but it seems it crashes because I can’t set those properties… am I missing something of I cannot set those properties?

This is what I get : OK @ line 115