| @@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.LinkedList; | |||
| import java.util.List; | |||
| import java.util.Queue; | |||
| @@ -94,7 +93,7 @@ public class PostBack | |||
| System.out.println(getName() + " terminating"); | |||
| return; | |||
| } | |||
| myLogger.debug("Looking for reports"); | |||
| List<String> reportList = null; | |||
| synchronized(postQueue) | |||
| { | |||
| @@ -110,6 +109,7 @@ public class PostBack | |||
| } | |||
| if (reportList.size() > 0) | |||
| { | |||
| myLogger.debug(String.format("Extracted %d reports, reducing postQueue size: %d", reportList.size(), postQueue.size())); | |||
| postQueue.notify(); | |||
| break; // break out to do the work. | |||
| } | |||
| @@ -122,10 +122,10 @@ public class PostBack | |||
| } | |||
| catch (InterruptedException e) | |||
| { | |||
| CommonLogger.alarm.info(getName() + ": Postback queue interrupted while waiting: " + e); | |||
| CommonLogger.alarm.info("Postback queue interrupted while waiting: " + e); | |||
| break; | |||
| } | |||
| CommonLogger.health.info(getName() + " surfacing from wait"); | |||
| CommonLogger.health.info("Surfacing from wait"); | |||
| System.out.println(getName() + " surfacing from wait"); | |||
| continue; | |||
| } | |||
| @@ -146,14 +146,14 @@ public class PostBack | |||
| queueReport(rpt); | |||
| } | |||
| // Sleep for a while before retrying this PostBack server. | |||
| CommonLogger.alarm.warn(getName() + ": Caught server IO error. sleep for " + POSTBACK_SERVER_WAIT_TIME + " seconds"); | |||
| CommonLogger.alarm.warn("Caught server IO error. sleep for " + POSTBACK_SERVER_WAIT_TIME + " seconds"); | |||
| try | |||
| { | |||
| Thread.sleep(POSTBACK_SERVER_WAIT_TIME * 1000); | |||
| } | |||
| catch (InterruptedException e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": Caught while PostBack thread sleeps: " + e); | |||
| CommonLogger.alarm.warn("Caught while PostBack thread sleeps: " + e); | |||
| } | |||
| default: | |||
| } | |||
| @@ -187,7 +187,7 @@ public class PostBack | |||
| } | |||
| catch (UnsupportedEncodingException e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": While adding this application/xml content to PostBack: " + xml + " -- " + e); | |||
| CommonLogger.alarm.warn("While adding this application/xml content to PostBack: " + xml + " -- " + e); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| post.setRequestEntity(requestEntity); | |||
| @@ -208,11 +208,11 @@ public class PostBack | |||
| post.setURI(new HttpURL(url)); | |||
| if (redirectCount == 0) | |||
| { | |||
| CommonLogger.activity.info(getName() + ": posting " + xml.toString() + " to " + url); | |||
| CommonLogger.activity.info("posting " + xml.toString() + " to " + url); | |||
| } | |||
| else | |||
| { | |||
| CommonLogger.activity.info(getName() + ": redirected to " + url); | |||
| CommonLogger.activity.info("redirected to " + url); | |||
| } | |||
| int statusCode = client.executeMethod(post); | |||
| @@ -227,40 +227,40 @@ public class PostBack | |||
| } | |||
| else | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": When posting to \"" + url + "\": " + " received status 302 but without location header"); | |||
| CommonLogger.alarm.warn("When posting to \"" + url + "\": " + " received status 302 but without location header"); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| } | |||
| else if (statusCode != 200) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": Received problem status code " + statusCode + " from posting to \"" + url + "\": " + xml); | |||
| CommonLogger.alarm.warn("Received problem status code " + statusCode + " from posting to \"" + url + "\": " + xml); | |||
| return PostBackStatus.HTTP_STATUS_ERROR; | |||
| } | |||
| responseBody = post.getResponseBodyAsString().trim(); | |||
| post.releaseConnection(); | |||
| CommonLogger.activity.info(getName() + ": Received response: " + (responseBody.length() == 0? "[empty]" : responseBody)); | |||
| CommonLogger.activity.info("Received response: " + (responseBody.length() == 0? "[empty]" : responseBody)); | |||
| if (responseBody.trim().length() == 0) return PostBackStatus.SUCCESS; | |||
| break; | |||
| } | |||
| catch (ConnectTimeoutException e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": IO problem while posting to \"" + url + "\": " + xml + " -- " + e.getMessage()); | |||
| CommonLogger.alarm.warn("IO problem while posting to \"" + url + "\": " + xml + " -- " + e.getMessage()); | |||
| return PostBackStatus.SERVER_IO_ERROR; | |||
| } | |||
| catch (IOException e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": IO problem while posting to \"" + url + "\": " + xml + " -- " + e.getMessage()); | |||
| CommonLogger.alarm.warn("IO problem while posting to \"" + url + "\": " + xml + " -- " + e.getMessage()); | |||
| return PostBackStatus.SERVER_IO_ERROR; | |||
| } | |||
| catch (IllegalArgumentException e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": When posting to \"" + url + "\": " + e.getMessage()); | |||
| CommonLogger.alarm.warn("When posting to \"" + url + "\": " + e.getMessage()); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| } | |||
| if (responseBody == null) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": When posting to \"" + url + "\": " + " Exhausted allowable redirects"); | |||
| CommonLogger.alarm.warn("When posting to \"" + url + "\": " + " Exhausted allowable redirects"); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| // parse into xml doc | |||
| @@ -273,12 +273,12 @@ public class PostBack | |||
| } | |||
| catch (Exception e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": xml parse problem on received response from " + postBackURL + ": " + responseBody); | |||
| CommonLogger.alarm.warn("xml parse problem on received response from " + postBackURL + ": " + responseBody); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| if (!xmlDoc.getDocumentElement().getNodeName().startsWith(xmlTopElement)) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": xml response from " + postBackURL + " not a <" + xmlTopElement + "> response: " + responseBody); | |||
| CommonLogger.alarm.warn("xml response from " + postBackURL + " not a <" + xmlTopElement + "> response: " + responseBody); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| XPath xpathEngine = XPathFactory.newInstance().newXPath(); | |||
| @@ -293,7 +293,7 @@ public class PostBack | |||
| xpath = "error_text"; | |||
| String errorText = (String)xpathEngine.evaluate(xpath, | |||
| xmlDoc.getDocumentElement(), XPathConstants.STRING); | |||
| CommonLogger.alarm.warn(getName() + ": Error response to <" + xmlTopElement + "> post back to " | |||
| CommonLogger.alarm.warn("Error response to <" + xmlTopElement + "> post back to " | |||
| + postBackURL + " -- error code=\"" + errorCode + "\", error text = \"" | |||
| + errorText + "\""); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| @@ -306,9 +306,10 @@ public class PostBack | |||
| } | |||
| catch (Exception e) | |||
| { | |||
| CommonLogger.alarm.warn(getName() + ": While decoding post back response from server: " + e); | |||
| CommonLogger.alarm.warn("While decoding post back response from server: " + e); | |||
| return PostBackStatus.IRRECOVERABLE_ERROR; | |||
| } | |||
| myLogger.debug("returned from posting"); | |||
| return PostBackStatus.SUCCESS; | |||
| } | |||
| @@ -373,21 +374,22 @@ public class PostBack | |||
| */ | |||
| public boolean queueReport(String report) | |||
| { | |||
| // Log for recovery in case of problem in posting report. | |||
| CommonLogger.activity.info(myName + " queing report: " + report); | |||
| myLogger.debug(myName + ": postQueue size: " + postQueue.size()); | |||
| synchronized(postQueue) | |||
| { | |||
| if (postQueue.size() < maxQueueSize) | |||
| { | |||
| CommonLogger.activity.info("queing report: " + report); | |||
| postQueue.add(report); | |||
| myLogger.debug("postQueue size: " + postQueue.size()); | |||
| postQueue.notify(); | |||
| return true; | |||
| } | |||
| else | |||
| { | |||
| CommonLogger.alarm.warn("Queue full - did not queue report: " + report + " -- postQueue size: " + postQueue.size()); | |||
| return false; | |||
| } | |||
| } | |||
| CommonLogger.alarm.warn(myName + ".queueReport failed to send report: " + report); | |||
| return false; | |||
| } | |||
| /** | |||