// get the rootNode
Element rootNode = doc.getRootElement();
if (!"rest-client".equals(rootNode.getQualifiedName())) {
throw new XMLException("Root node is not <rest-client>");
}
// checking correct rest version
checkIfVersionValid(rootNode.getAttributeValue("version"));
// assign rootnode to current node and also finding 'response' node
Element tNode = null;
Element responseNode = null;
// if more than two request element is present then throw the exception
if (rootNode.getChildElements().size() != 1) {
throw new XMLException("There can be only one child node for root node: <response>");
}
// minimum one response element is present in xml
if (rootNode.getFirstChildElement("response") == null) {
throw new XMLException("The child node of <rest-client> should be <response>");
}
responseNode = rootNode.getFirstChildElement("response");
for (int i = 0; i < responseNode.getChildElements().size(); i++) {
tNode = responseNode.getChildElements().get(i);
String nodeName = tNode.getQualifiedName();
if ("execution-time".equals(nodeName)) {
responseBean.setExecutionTime(Long.parseLong(tNode.getValue()));
} else if ("status".equals(nodeName)) {
responseBean.setStatusLine(tNode.getValue());
responseBean.setStatusCode(Integer.parseInt(tNode.getAttributeValue("code")));
} else if ("headers".equals(nodeName)) {
Map<String, String> m = getHeadersFromHeaderNode(tNode);
for (String key : m.keySet()) {
responseBean.addHeader(key, m.get(key));
}
} else if ("body".equals(nodeName)) {
final String base64body = tNode.getValue();
responseBean.setResponseBody(Util.base64decodeByteArray(base64body));
} else if ("test-result".equals(nodeName)) {
TestResultBean testResultBean = new TestResultBean();
for (int j = 0; j < tNode.getChildCount(); j++) {
String nn = tNode.getQualifiedName();
if ("run-count".equals(nn)) {
throw new XMLException("<headers> element should contain only <header> elements");
} else if ("failure-count".equals(nn)) {
throw new XMLException("<headers> element should contain only <header> elements");
} else if ("error-count".equals(nn)) {
throw new XMLException("<headers> element should contain only <header> elements");
} else if ("failures".equals(nn)) {
throw new XMLException("<headers> element should contain only <header> elements");
} else if ("errors".equals(nn)) {
throw new XMLException("<headers> element should contain only <header> elements");
}
}
responseBean.setTestResult(testResultBean);
} else {
throw new XMLException("Unrecognized element found: <" + nodeName + ">");
}
}
return responseBean;
}