// Write the new bits for the application
moveTempFileToDeployLocation(tempFile, appFile, isExploded);
// The file has been written successfully to the deploy dir. Now try to actually deploy it.
MainDeployer mainDeployer = getParentResourceComponent().getMainDeployer();
try {
mainDeployer.redeploy(appFile);
// Deploy was successful, delete the backup
try {
FileUtils.purge(backupOfOriginalFile, true);
} catch (Exception e) {
log.warn("Failed to delete backup of original file: " + backupOfOriginalFile);
}
} catch (Exception e) {
// Deploy failed - rollback to the original app file...
String errorMessage = ThrowableUtil.getAllMessages(e);
try {
FileUtils.purge(appFile, true);
backupOfOriginalFile.renameTo(appFile);
// Need to redeploy the original file - this generally should succeed.
mainDeployer.redeploy(appFile);
errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****";
} catch (Exception e1) {
errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: "
+ ThrowableUtil.getAllMessages(e1);
}