Skip to content

Commit

Permalink
Merge pull request #13 from OpenAS2/revert-11-graceful-file-error-han…
Browse files Browse the repository at this point in the history
…dling

Revert "#15 Provide recoverable solution to invalid file name in "toAny" folder"
  • Loading branch information
pete-gilchrist committed May 13, 2016
2 parents 6a17848 + 9c1b71c commit 1eb16b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ public void poll()
} catch (OpenAS2Exception oae)
{
oae.terminate();
forceStop(oae);
} catch (Exception e)
{
new WrappedException(e).terminate();
forceStop(e);
}
}

Expand Down Expand Up @@ -184,11 +186,6 @@ protected void updateTracking() throws OpenAS2Exception
try
{
processFile(file);
} catch (Exception e)
{
IOUtilOld.handleError(file, errorDir);
trackedFiles.remove(fileEntry.getKey());
throw new WrappedException(e);
} finally
{
trackedFiles.remove(fileEntry.getKey());
Expand Down Expand Up @@ -247,7 +244,7 @@ protected void processFile(File file) throws OpenAS2Exception
{
Header hd = headersEnum.nextElement();
headers = ";;" + hd.getName() + "::" + hd.getValue();

}

logger.trace("Message object in directory polling module. Content-Disposition: " + msg.getContentDisposition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public class DirectoryResenderModule extends BaseResenderModule {
public static final String PARAM_ERROR_DIRECTORY = "errordir";
public static final String PARAM_RESEND_DELAY = "resenddelay"; // in seconds

// TODO Resend set to 15 minutes. Implement a scaling resend time with eventual permanent failure of transmission
// TODO Resend set to 15 minutes. Implement a scaling resend time with eventual permanent failure of transmission
public static final long DEFAULT_RESEND_DELAY = 15 * 60 * 1000; // 15 minutes

private Log logger = LogFactory.getLog(DirectoryResenderModule.class.getSimpleName());


public boolean canHandle(String action, Message msg, Map<Object, Object> options) {
return action.equals(ResenderModule.DO_RESEND);
}

public void handle(String action, Message msg, Map<Object, Object> options)
throws OpenAS2Exception {
ObjectOutputStream oos = null;
try {
try {
File resendDir = IOUtilOld.getDirectoryFile(getParameter(PARAM_RESEND_DIRECTORY, true));
File resendFile = IOUtilOld.getUnique(resendDir, getFilename());
oos = new ObjectOutputStream(new FileOutputStream(resendFile));
Expand All @@ -57,7 +57,7 @@ public void handle(String action, Message msg, Map<Object, Object> options)
oos.writeObject(method);
oos.writeObject(retries);
oos.writeObject(msg);

logger.info("message put in resend queue"+msg.getLogMsgID());
if (logger.isTraceEnabled())
try
Expand All @@ -68,7 +68,7 @@ public void handle(String action, Message msg, Map<Object, Object> options)
{
Header hd = headersEnum.nextElement();
headers = ";;" + hd.getName() + "::" + hd.getValue();

}

logger.trace("Message object in resender module for storage. Content-Disposition: " + msg.getContentDisposition()
Expand All @@ -91,11 +91,11 @@ public void handle(String action, Message msg, Map<Object, Object> options)
{}
}
}

public void init(Session session, Map<String,String> options) throws OpenAS2Exception {
super.init(session, options);
getParameter(PARAM_RESEND_DIRECTORY, true);
getParameter(PARAM_ERROR_DIRECTORY, true);
getParameter(PARAM_ERROR_DIRECTORY, true);
}

public void resend() {
Expand All @@ -117,10 +117,11 @@ public void resend() {
}
} catch (OpenAS2Exception oae) {
oae.terminate();
forceStop(oae);
}
}

protected String getFilename() throws InvalidParameterException {
protected String getFilename() throws InvalidParameterException {
long resendDelay;
if (getParameter(PARAM_RESEND_DELAY, false) == null) {
resendDelay = DEFAULT_RESEND_DELAY;
Expand All @@ -133,10 +134,10 @@ protected String getFilename() throws InvalidParameterException {
}

protected boolean isTimeToSend(File currentFile) {
try {
try {
StringTokenizer fileTokens = new StringTokenizer(currentFile.getName(), ".", false);

Date timestamp = DateUtil.parseDate("MM-dd-yy-HH-mm-ss", fileTokens.nextToken());
Date timestamp = DateUtil.parseDate("MM-dd-yy-HH-mm-ss", fileTokens.nextToken());

return timestamp.before(new Date());
} catch (Exception e) {
Expand Down Expand Up @@ -168,7 +169,7 @@ protected void processFile(File file) throws OpenAS2Exception {
{
Header hd = headersEnum.nextElement();
headers = ";;" + hd.getName() + "::" + hd.getValue();

}

logger.trace("Reconstituted Message object in resender. Content-Disposition: " + msg.getContentDisposition()
Expand All @@ -181,7 +182,7 @@ protected void processFile(File file) throws OpenAS2Exception {
msg.setOption(SenderModule.SOPT_RETRIES, retries);
msg.setStatus(Message.MSG_STATUS_MSG_RESEND);
getSession().getProcessor().handle(method, msg, msg.getOptions());

if (!file.delete()) { // Delete the file, sender will re-queue if the transmission fails again
throw new OpenAS2Exception("File was successfully sent but not deleted: " +
file.getAbsolutePath());
Expand Down

0 comments on commit 1eb16b6

Please sign in to comment.