| @@ -208,7 +208,6 @@ public class Postback | |||
| HttpPost httpPost = new HttpPost(postBackURL); | |||
| StringEntity requestEntity; | |||
| CloseableHttpResponse response = null; | |||
| byte[] xmlBytes = null; | |||
| try | |||
| { | |||
| requestEntity = (new StringEntity(xml.toString())); | |||
| @@ -218,11 +217,13 @@ public class Postback | |||
| incrementPostedTransactions(reportList.size()); | |||
| StatusLine statusLine = response.getStatusLine(); | |||
| int statusCode = statusLine.getStatusCode(); | |||
| response.close(); | |||
| if (statusCode != 200) | |||
| { | |||
| CommonLogger.alarm.error("Got error status code " + statusCode + " while posting status to broadcast requester"); | |||
| return PostbackStatus.HTTP_STATUS_ERROR; | |||
| } | |||
| return PostbackStatus.SUCCESS; | |||
| } | |||
| catch (UnsupportedEncodingException e) | |||
| { | |||
| @@ -233,70 +234,8 @@ public class Postback | |||
| { | |||
| CommonLogger.alarm.error("While posting back to broadcast requester: " + e); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| String xmlStr; | |||
| try | |||
| { | |||
| xmlBytes = EntityUtils.toByteArray(response.getEntity()); | |||
| xmlStr = new String(xmlBytes); | |||
| myLogger.debug("Received resposne: " + xmlStr); | |||
| } | |||
| catch (IOException e) | |||
| { | |||
| CommonLogger.alarm.error("While getting response from posting to broadcast requester: " + e); | |||
| return PostbackStatus.SERVER_IO_ERROR; | |||
| } | |||
| Document xmlDoc = null; | |||
| try | |||
| { | |||
| DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |||
| DocumentBuilder builder = factory.newDocumentBuilder(); | |||
| xmlDoc = builder.parse(new ByteArrayInputStream(xmlBytes)); | |||
| } | |||
| catch (Exception e) | |||
| { | |||
| CommonLogger.alarm.warn("xml parse problem on received response from " + postBackURL + ": " + xmlStr); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| if (!xmlDoc.getDocumentElement().getNodeName().startsWith(xmlTopElement)) | |||
| { | |||
| CommonLogger.alarm.warn("xml response from " + postBackURL + " not a <" + xmlTopElement + "> response: " + xmlStr); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| XPath xpathEngine = XPathFactory.newInstance().newXPath(); | |||
| String xpath = null; | |||
| try | |||
| { | |||
| xpath = "@error"; | |||
| Node errorNode = (Node)xpathEngine.evaluate(xpath, xmlDoc.getDocumentElement(), XPathConstants.NODE); | |||
| if (errorNode != null) | |||
| { | |||
| String errorCode = errorNode.getNodeValue(); | |||
| xpath = "error_text"; | |||
| String errorText = (String)xpathEngine.evaluate(xpath, | |||
| xmlDoc.getDocumentElement(), XPathConstants.STRING); | |||
| CommonLogger.alarm.warn("Error response to <" + xmlTopElement + "> post back to " | |||
| + postBackURL + " -- error code=\"" + errorCode + "\", error text = \"" | |||
| + errorText + "\""); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| } | |||
| catch (XPathExpressionException e) | |||
| { | |||
| CommonLogger.alarm.warn("Bad xpath: " + xpath); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| catch (Exception e) | |||
| { | |||
| CommonLogger.alarm.warn("While decoding post back response from server: " + e); | |||
| return PostbackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| return PostbackStatus.SUCCESS; | |||
| } | |||
| } | |||
| } | |||
| /** | |||