messages = persister.getLogMessageEntries(
logEntry.getId(),
getLoggingVerbosityLevel());
for(Iterator m = messages.iterator(); m.hasNext();) {
LogMessageEntry messageEntry = (LogMessageEntry) m.next();
message += (messageEntry.getMessage()) + "\n";
}
} else {
message += MAIL_MESSAGE_NO_ENTRIES;
}
// Send notification email except when the message is
// MAIL_MESSAGE_NO_ENTRIES or the pipe has aborted and
// isAbortMailEnabled()==true
if (!message.equals(MAIL_MESSAGE_NO_ENTRIES)
|| (statusCode==LogEntry.STATUS_ABORTED && isAbortMailEnabled())) {
try {
Properties props = new Properties();
props.put("mail.host", getMailHost());
Session mailConnection = Session.getInstance(props,
null);
Message msg = new MimeMessage(mailConnection);
Address sender = new InternetAddress(MAIL_SENDER + "@"
+ getMailHost(), MAIL_SENDER);
Address[] receivers = receiverAddresses(getRecipientAddress());
// Set mail content and subject
msg.setContent(message, "text/plain");
msg.setFrom(sender);
msg.setRecipients(Message.RecipientType.TO, receivers);
msg.setSubject(subject);
// Send the mail
Transport.send(msg);
} catch (MessagingException e) {
String error = "An error occurred when sending mail report from "
+ MAIL_SENDER
+ "@"
+ getMailHost()
+ " to "
+ getRecipientAddress()
+ ":\n"
+ e.getMessage();
Environment.getInstance().log(error);
logEntry.logMessage(error, this, MessageLogger.ERROR);
persister.update(logEntry);
} catch (RuntimeException ex) {
Environment.getInstance().log(
"A RuntimeException has occurred: "
+ ex.getMessage()
+ ex.getStackTrace().toString());
}
}
}
// Remove unnecessary (debug level) messages from the LogEntry if Transfer log
// verbosity level is set to DYNAMIC and the current LogEntry's status is either
// OK or ABORTED
if(getLoggingVerbosityLevel() == MessageLogger.LOG_DYNAMIC
&& (statusCode == LogEntry.STATUS_OK || statusCode == LogEntry.STATUS_ABORTED) ) {
messages = persister.getLogMessageEntries(logEntry.getId(), MessageLogger.DEBUG);
if(messages.size() > 0) {
for(Iterator m = messages.iterator(); m.hasNext();) {
LogMessageEntry messageEntry = (LogMessageEntry) m.next();
if(messageEntry.getMessageType() == MessageLogger.DEBUG) {
persister.delete(messageEntry);
}
}
}