{
log.info("Executing DropOffSynchronous operation ");
Element docElement = (Element) dropOffSyncRequest.getAny();
DropOffResponse dropOffSyncResponse = new DropOffResponse();
ServiceResponseInfo sb = new ServiceResponseInfo();
String mailBoxURI = null;
String clientsideID = null;
String recordURI = null;
String messageID = null;
HashMap<String, String> attributesMap = SSAFUtil
.getMessageAttributes(docElement);
clientsideID = attributesMap.get("clientsideID");
recordURI = attributesMap.get("recordURI");
mailBoxURI = attributesMap.get("dropoffMailBoxURI");
// Throw Fault if clientside_Id is not specified
if (StringUtils.isBlank(clientsideID))
{
sb.noteError("clientside_Id attribute is not specified in incoming request document");
Drop_OffUtil .throwFault( recordURI,
null,
null,
sb, SSAFErrorTypes.REQUEST_INVALID, mailBoxURI,
docElement);
}
// check if mailBoxURI attribute is present in incoming request
if (StringUtils.isNotBlank(mailBoxURI))
{
String mailBoxesAbsolutePath = mailBoxes_root + mailBoxURI;
// check if it dropped of a file successfully
if (DropOffHelperMethods.dropOffAFile(mailBoxesAbsolutePath, docElement,
sb, clientsideID, recordURI))
{
log.info("Successfully dropped off a file to the mailbox location specified : "
+ mailBoxesAbsolutePath +SSAFUtil.fileSeparator+
"drop_off"+SSAFUtil.fileSeparator+"drop_box");
// poll for response file in both confirm_box and fail_box
// folders.
Element dropOffStatusReponseElement = Drop_OffUtil
.pollForAFile(mailBoxesAbsolutePath,
clientsideID,
recordURI,
sb, docElement,
numberOfTimesToPoll,sleepInterval);
if (dropOffStatusReponseElement != null)
{
// find out what type of response is returned either
// confirmation or Error
NodeList acceptedMessageList = dropOffStatusReponseElement
.getElementsByTagNameNS(SSAFNamespaces.drop_off
.getNamespace(), SSAFNodes.accepted_message
.getLocalName());
if (acceptedMessageList.getLength() > 0)
{
Element acceptedMessageElement = (Element) acceptedMessageList
.item(0);
messageID = acceptedMessageElement.getAttributeNS(
SSAFNamespaces.ssaf.getNamespace(),
SSAFNodes.message_id.getLocalName());
}
// all confirmation messages must have message_id attribute
// in them. If not it's a error Document.
if (StringUtils.isNotBlank(messageID))
{
log.info("message_id attribute defined in dropOffStatusReponseElement : "+messageID);
File confirmationFileToDelete = Drop_OffUtil
.lookForConfirmationFileWithMessageID(
messageID, mailBoxesAbsolutePath,
docElement, sb);
// check if file exists
if (confirmationFileToDelete != null
&& confirmationFileToDelete.exists())
{
// if it exists go ahead and delete a confirmation file
if (DropOffHelperMethods.deleteAFile(
confirmationFileToDelete, sb))
{
dropOffSyncResponse
.setAny(dropOffStatusReponseElement);
}
else
{ // file exists but could not be deleted
sb.noteError("Confirmation file exists in a file system but not " +
"able to delete a confirmation file with message_id : "
+ messageID);
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(recordURI,
clientsideID,
messageID,
sb,SSAFErrorTypes.NONLOGIC,
mailBoxURI,
dropOffStatusReponseElement);
}
}
else
{
// File is not present in file system
sb.noteError("File does not exists in a file system with specified message_id : "
+ messageID);
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(recordURI,
clientsideID,
messageID,
sb,SSAFErrorTypes.REQUEST_RECORD_ERROR,
mailBoxURI, dropOffStatusReponseElement);
}
}
else
{
// If it is in this block then it is a error document -
// delete it form file system and then return
// dropOffSyncResponse.
log.info("There is no message_id attribute defined in dropOffStatusReponseElement");
String deleteErrorFileLocation = Drop_OffUtil
.getFileName(mailBoxesAbsolutePath, "fail_box",
clientsideID, "response");
File fileToDelete = new File(deleteErrorFileLocation);
// check if error file exists
if (fileToDelete.exists())
{
if (DropOffHelperMethods.deleteAFile(fileToDelete, sb))
{
log.info("Successfully deleted the a error file with" +
" specified clientside_id :" + clientsideID);
dropOffSyncResponse.setAny(dropOffStatusReponseElement);
}
else
{ // Confirmation file exists but could not be deleted
sb.noteError("Confirmation file exists in a file system but not" +
" able to delete a error file with specified clientside_id : "