try {
Document document = newDocumentBuilder()
.parse(new InputSource(new InputStreamReader(inputStream, "UTF-8")));
Element root = document.getDocumentElement(); // lfm element
String statusString = root.getAttribute("status");
Status status = "ok".equals(statusString) ? Status.OK : Status.FAILED;
if (status == Status.FAILED) {
if (cache != null)
cache.remove(cacheEntryName); // if request was failed remove from cache
Element error = (Element) root.getElementsByTagName("error").item(0);
int errorCode = Integer.parseInt(error.getAttribute("code"));