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 : "
+ clientsideID);
log.error(sb.getMergedMessages());
Drop_OffUtil .throwFault( recordURI,
clientsideID,
messageID,
sb,SSAFErrorTypes.NONLOGIC,
mailBoxURI,
dropOffStatusReponseElement);
}
}
else
{
// Error file is not present in file system
sb.noteError("Error file does not exists in file system with specified" +
" clientside_id : "+ clientsideID);
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(recordURI,
clientsideID,
messageID,
sb,SSAFErrorTypes.REQUEST_RECORD_ERROR,
mailBoxURI, dropOffStatusReponseElement);
}
}
}
// this is else part for pollForAFile if statement.
else
{
// throw FatalFault if you are not able to find file with
// specified clientside_id in file system.
sb.noteError("Not able to find a response for this request, SSAF component " +
"is taking sometime to process a request. Try to invoke asynchronous " +
"CheckDropOffStatus web service method with clientside_id :" +clientsideID+" to check for response");
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.NONLOGIC,
mailBoxesAbsolutePath, docElement);
}
}
// this is else part for dropOffAFile() if statement
else
{
// throw FatalFault if it could not drop-off a file
sb.noteError("Could not dropOff a file at :"
+ mailBoxesAbsolutePath +SSAFUtil.fileSeparator+
"drop_off"+SSAFUtil.fileSeparator+"drop_box");
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.NONLOGIC,
mailBoxURI, docElement);
}
}
else
{
// Throw Fault if MailBoxURI is not specified
sb.noteMessage("mailbox_nominal_uri attribute in incoming request document" +
" is not specified properly");
log.error(sb.getMergedMessages());
Drop_OffUtil .throwFault( recordURI,
null,
null,
sb, SSAFErrorTypes.REQUEST_RECORD_ERROR,
mailBoxURI, docElement);