use of lucee.commons.lang.SerializableObject in project Lucee by lucee.
the class SMTPClient method _send.
public void _send(lucee.runtime.config.ConfigWeb config, Server[] servers) throws MailException {
long start = System.nanoTime();
long _timeout = getTimeout(config);
try {
Proxy.start(proxyData);
Log log = ((ConfigImpl) config).getLog("mail");
// Server[] servers = config.getMailServers();
if (host != null) {
int prt;
String usr, pwd;
ServerImpl[] nServers = new ServerImpl[host.length];
for (int i = 0; i < host.length; i++) {
usr = null;
pwd = null;
prt = Server.DEFAULT_PORT;
if (port > 0)
prt = port;
if (!StringUtil.isEmpty(username)) {
usr = username;
pwd = password;
}
nServers[i] = toServerImpl(host[i], prt, usr, pwd, lifeTimespan, idleTimespan);
if (ssl == SSL_YES)
nServers[i].setSSL(true);
if (tls == TLS_YES)
nServers[i].setTLS(true);
}
servers = nServers;
}
if (servers.length == 0) {
// return;
throw new MailException("no SMTP Server defined");
}
boolean _ssl, _tls;
for (int i = 0; i < servers.length; i++) {
Server server = servers[i];
String _username = null, _password = "";
if (server.hasAuthentication()) {
_username = server.getUsername();
_password = server.getPassword();
}
// tls
if (tls != TLS_NONE)
_tls = tls == TLS_YES;
else
_tls = ((ServerImpl) server).isTLS();
// ssl
if (ssl != SSL_NONE)
_ssl = ssl == SSL_YES;
else
_ssl = ((ServerImpl) server).isSSL();
MimeMessageAndSession msgSess;
boolean recyleConnection = ((ServerImpl) server).reuseConnections();
{
// synchronized(LOCK) {
try {
msgSess = createMimeMessage(config, server.getHostName(), server.getPort(), _username, _password, ((ServerImpl) server).getLifeTimeSpan(), ((ServerImpl) server).getIdleTimeSpan(), _tls, _ssl, ((ConfigImpl) config).isMailSendPartial(), !recyleConnection, ((ConfigImpl) config).isUserset());
} catch (MessagingException e) {
// listener
listener(config, server, log, e, System.nanoTime() - start);
MailException me = new MailException(e.getMessage());
me.setStackTrace(e.getStackTrace());
throw me;
}
try {
SerializableObject lock = new SerializableObject();
SMTPSender sender = new SMTPSender(lock, msgSess, server.getHostName(), server.getPort(), _username, _password, recyleConnection);
sender.start();
SystemUtil.wait(lock, _timeout);
if (!sender.isSent()) {
Throwable t = sender.getThrowable();
if (t != null)
throw Caster.toPageException(t);
// stop when still running
try {
if (sender.isAlive())
sender.stop();
} catch (Throwable t2) {
ExceptionUtil.rethrowIfNecessary(t2);
}
// after thread is stopped check sent flag again
if (!sender.isSent()) {
throw new MessagingException("timeout occurred after " + (_timeout / 1000) + " seconds while sending mail message");
}
}
// could have an exception but was send anyway
if (sender.getThrowable() != null) {
Throwable t = sender.getThrowable();
if (log != null)
LogUtil.log(log, Log.LEVEL_ERROR, "send mail", t);
}
clean(config, attachmentz);
listener(config, server, log, null, System.nanoTime() - start);
break;
} catch (Exception e) {
SystemOut.printDate(e);
if (i + 1 == servers.length) {
listener(config, server, log, e, System.nanoTime() - start);
MailException me = new MailException(server.getHostName() + " " + ExceptionUtil.getStacktrace(e, true) + ":" + i);
me.setStackTrace(e.getStackTrace());
throw me;
}
}
}
}
} finally {
Proxy.end();
}
}
use of lucee.commons.lang.SerializableObject in project Lucee by lucee.
the class Execute method _execute.
private void _execute() throws Exception {
Object monitor = new SerializableObject();
String command = "";
if (name == null) {
if (StringUtil.isEmpty(body)) {
required("execute", "name", name);
required("execute", "arguments", arguments);
} else
command = body;
} else {
if (arguments == null)
command = name;
else
command = name + arguments;
}
_Execute execute = new _Execute(pageContext, monitor, command, outputfile, variable, errorFile, errorVariable);
// if(timeout<=0)execute._run();
// else {
execute.start();
if (timeout > 0) {
try {
synchronized (monitor) {
monitor.wait(timeout);
}
} finally {
execute.abort(terminateOnTimeout);
}
if (execute.hasException()) {
throw execute.getException();
}
if (!execute.hasFinished())
throw new ApplicationException("timeout [" + (timeout) + " ms] expired while executing [" + command + "]");
// }
}
}
Aggregations