HTTP GET - Trouble parsing text/html

I am having problems with a simple HTTP GET command parsing of the return. I usually use HubAction to send the command, but need an explicit response before continuing to the next step in the method. Obviously I am missing something, but I am at a loss.

Below are two elements:

  • method newSendCmd which calls the post and response (I added some elements to document the return data in log.
  • log of the response (shows problem in two errors on XmlSlurper and XmlParser).

Method newSendCmd:

private newSendCmd(command){
	def host = "http://192.168.0.127:55001"
	httpGet("${host}${command}") { response ->
		log.info "status: ${response.getStatus()}"
		log.info "contentType: ${response.getContentType()}"
		log.info "data: ${response.getData()}"
		log.info "context: ${response.getContext()}"
		log.info "entity: ${response.getEntity()}"
		log.info "locale: ${response.getLocale()}"
		log.info "tatusLine: ${response.getStatusLine()}"
		def data = response.data
		log.debug data
		def cmdResp = "DID NOT WORK"
		try { cmdResp = new XmlParser().parseText(data) }
		catch (error) { log.error "XmlParser: ${error}" }
		try { cmdResp = new XmlSlurper().parseText(data) }
		catch (error) { log.error "XmlSlurper: ${error}" }
		log.debug cmdResp
	}
}

Log Data:

dev:27572019-04-29 12:32:04.669 pm debugDID NOT WORK

dev:27572019-04-29 12:32:04.665 pm errorXmlSlurper: groovy.lang.MissingMethodException: No signature of method: groovy.util.XmlSlurper.parseText() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: [MuteStatus1.0192.168.0.127publicoff] Possible solutions: parseText(java.lang.String), parse(java.io.File), parse(java.io.InputStream), parse(java.io.Reader), parse(java.lang.String), parse(org.xml.sax.InputSource)

dev:27572019-04-29 12:32:04.657 pm errorXmlParser: groovy.lang.MissingMethodException: No signature of method: groovy.util.XmlParser.parseText() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: [MuteStatus1.0192.168.0.127publicoff] Possible solutions: parseText(java.lang.String), parse(java.io.File), parse(java.io.InputStream), parse(java.io.Reader), parse(java.lang.String), parse(org.xml.sax.InputSource)

dev:27572019-04-29 12:32:04.645 pm debugMuteStatus1.0192.168.0.127publicoff

dev:27572019-04-29 12:32:04.641 pm infotatusLine: HTTP/1.1 200 OK

dev:27572019-04-29 12:32:04.639 pm infolocale: en_US

dev:27572019-04-29 12:32:04.638 pm infoentity: ResponseEntityProxy{[Content-Type: text/html,Content-Length: 224,Chunked: false]}

dev:27572019-04-29 12:32:04.637 pm infocontext: groovyx.net.http.HttpContextDecorator@187f8318

dev:27572019-04-29 12:32:04.635 pm infodata: MuteStatus1.0192.168.0.127publicoff

dev:27572019-04-29 12:32:04.634 pm infocontentType: text/html

dev:27572019-04-29 12:32:04.632 pm infostatus: 200

Any help is appreciated!!!!!

The error looks like you're trying to parse something that's already xml.

In the following post the XML was automatically parsed - did you try using response.data as an XML object directly?

2 Likes

Thanks. I had tried that in the base command. problem was the ContentType not being there. By doing that, I am able to get the data I need. Now it is all better!