Fix issue with empty xml resulting in parse errors.
This commit is contained in:
parent
804b49b86d
commit
c1c894d64e
|
@ -1,2 +1,2 @@
|
||||||
group = biz.nellemann.hmci
|
group = biz.nellemann.hmci
|
||||||
version = 1.0.7
|
version = 1.0.8
|
||||||
|
|
|
@ -149,6 +149,11 @@ class HmcClient {
|
||||||
String responseBody = response.body.string()
|
String responseBody = response.body.string()
|
||||||
Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>()
|
Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>()
|
||||||
|
|
||||||
|
// Do not try to parse empty response
|
||||||
|
if(responseBody.empty || responseBody.size() < 1) {
|
||||||
|
return managedSystemsMap
|
||||||
|
}
|
||||||
|
|
||||||
def feed = new XmlSlurper().parseText(responseBody)
|
def feed = new XmlSlurper().parseText(responseBody)
|
||||||
feed?.entry?.each { entry ->
|
feed?.entry?.each { entry ->
|
||||||
entry.content.each { content ->
|
entry.content.each { content ->
|
||||||
|
@ -182,8 +187,13 @@ class HmcClient {
|
||||||
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id))
|
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id))
|
||||||
Response response = getResponse(url)
|
Response response = getResponse(url)
|
||||||
String responseBody = response.body.string()
|
String responseBody = response.body.string()
|
||||||
|
|
||||||
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {}
|
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {}
|
||||||
|
|
||||||
|
// Do not try to parse empty response
|
||||||
|
if(responseBody.empty || responseBody.size() < 1) {
|
||||||
|
return partitionMap
|
||||||
|
}
|
||||||
|
|
||||||
def feed = new XmlSlurper().parseText(responseBody)
|
def feed = new XmlSlurper().parseText(responseBody)
|
||||||
feed?.entry?.each { entry ->
|
feed?.entry?.each { entry ->
|
||||||
//log.debug("Entry")
|
//log.debug("Entry")
|
||||||
|
|
|
@ -21,6 +21,18 @@ class HmcClientTest extends Specification {
|
||||||
mockServer.shutdown()
|
mockServer.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void "test against empty xml"() {
|
||||||
|
setup:
|
||||||
|
def testXml = ""
|
||||||
|
mockServer.enqueue(new MockResponse().setBody(testXml));
|
||||||
|
|
||||||
|
when:
|
||||||
|
Map<String, ManagedSystem> systems = hmc.getManagedSystems()
|
||||||
|
|
||||||
|
then:
|
||||||
|
systems.size() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void "test getManagedSystems"() {
|
void "test getManagedSystems"() {
|
||||||
setup:
|
setup:
|
||||||
|
|
Loading…
Reference in a new issue