* @return a message of success or failure
*/
public static String resendDeletedMessage(String filename)
{
StringBuffer retString = new StringBuffer();
TAManager taManager = null;
Trace.info("Resending message from " + filename);
/*
* Reading and parsing the deleted message
*/
try
{
Document messageDom = XMLHelper.parseXML(readFile(getDirectory()
+ Constants.FILE_SEPERATOR + filename), null, null);
XBUSSystem source = new XBUSSystem(messageDom.getFirstChild()
.getNodeName());
NodeList addresses = messageDom.getElementsByTagName("Address");
Node address = null;
String attrName = null;
String addressValue = null;
for (int i = 0; i < addresses.getLength(); i++)
{
address = addresses.item(i);
if ((attrName = XMLHelper.getAttribute(address, "name")) == null)
{
throw new XException(Constants.LOCATION_INTERN,
Constants.LAYER_BASE,
Constants.PACKAGE_BASE_DELETEDMESSAGESTORE, "1");
}
if ((addressValue = XMLHelper.getNodeText(address)) == null)
{
throw new XException(Constants.LOCATION_INTERN,
Constants.LAYER_BASE,
Constants.PACKAGE_BASE_DELETEDMESSAGESTORE, "2");
}
source.setAddress(attrName, addressValue);
}
NodeList data = messageDom.getElementsByTagName("Data");
String request = null;
if (data.getLength() > 0)
{
Node messageNode = messageDom.getElementsByTagName("Data")
.item(0);
Node dataNode = null;
if ((dataNode = messageNode.getFirstChild()) != null)
{
request = dataNode.getNodeValue();
}
}
if (request == null)
{
throw new XException(Constants.LOCATION_INTERN,
Constants.LAYER_BASE,
Constants.PACKAGE_BASE_DELETEDMESSAGESTORE, "3");
}
/*
* Resending the message
*/
taManager = TAManager.getInstance();
taManager.clearManager();
taManager.begin();
Adapter adapter = new Adapter();
adapter.callApplication(source, request, Constants.TYPE_TEXT);
Object responseObject = adapter.getResponse();
if (Constants.RC_OK.equals(adapter.getReturncode()))
{
taManager.commit();
PostProcessor.start(source, responseObject,
Constants.POSTPROCESSING_PERSYSTEM);
Trace.info("End resending " + source.getCompleteName());
Trace.info("-----------------------------");
retString.append("Message from ").append(
source.getCompleteName()).append(
" successfully resent!");
File messageFile = new File(getDirectory()
+ Constants.FILE_SEPERATOR + filename);
if (messageFile.delete())
{
retString.append("<br>");
retString.append("File ").append(filename).append(
" has been deleted.");
}
else
{
retString.append("<br />");
retString.append("File ").append(filename).append(
" cannot be deleted.");
}
}
else
{
taManager.rollback();
Trace.info("Error while resending " + source.getCompleteName());
Trace.info("-----------------------------");
retString.append("Error while resending ").append(
source.getCompleteName()).append("<br>").append(
"Reason: ").append(adapter.getErrormessage()).append(
"<br>").append("File ").append(filename).append(
" has not been deleted.");
}
}
catch (Exception t)
{
Trace.info("Error while resending " + filename);
Trace.info("-----------------------------");
retString.append("Error while resending ").append(filename).append(
"<br>").append("Reason: ").append(t.getMessage()).append(
"<br>").append("File ").append(filename).append(
" has not been deleted.");
}
finally
{
if (taManager != null)
{
taManager.close();
}
}
return retString.toString();