use of lucee.commons.security.Credentials in project Lucee by lucee.
the class Schedule method doUpdate.
/**
* @throws PageException
*/
private void doUpdate() throws PageException {
String message = "missing attribute for tag schedule with action update";
String detail = "required attributes are [startDate, startTime, URL, interval, operation]";
Resource file = null;
// if(publish) {
if (!StringUtil.isEmpty(strFile) && !StringUtil.isEmpty(strPath)) {
file = ResourceUtil.toResourceNotExisting(pageContext, strPath);
file = file.getRealResource(strFile);
} else if (!StringUtil.isEmpty(strFile)) {
file = ResourceUtil.toResourceNotExisting(pageContext, strFile);
} else if (!StringUtil.isEmpty(strPath)) {
file = ResourceUtil.toResourceNotExisting(pageContext, strPath);
}
if (file != null)
pageContext.getConfig().getSecurityManager().checkFileLocation(pageContext.getConfig(), file, serverPassword);
// missing attributes
if (startdate == null || starttime == null || url == null || interval == null)
throw new ApplicationException(message, detail);
// timeout
if (requesttimeout < 0)
requesttimeout = pageContext.getRequestTimeout();
// username/password
Credentials cr = null;
if (username != null)
cr = CredentialsImpl.toCredentials(username, password);
try {
ScheduleTask st = new ScheduleTaskImpl(task, file, startdate, starttime, enddate, endtime, url, port, interval, requesttimeout, cr, ProxyDataImpl.getInstance(proxyserver, proxyport, proxyuser, proxypassword), resolveurl, publish, hidden, readonly, paused, autoDelete);
scheduler.addScheduleTask(st, true);
} catch (Exception e) {
throw Caster.toPageException(e);
}
//
}
use of lucee.commons.security.Credentials in project Lucee by lucee.
the class ExecutionThread method execute.
public static void execute(Config config, ScheduleTask task, String charset) {
Log log = getLog(config);
boolean hasError = false;
String logName = "schedule task:" + task.getTask();
// init
// HttpClient client = new HttpClient();
// client.setStrictMode(false);
// HttpState state = client.getState();
String url;
if (task.getUrl().getQuery() == null)
url = task.getUrl().toExternalForm() + "?RequestTimeout=" + (task.getTimeout() / 1000);
else if (StringUtil.isEmpty(task.getUrl().getQuery()))
url = task.getUrl().toExternalForm() + "RequestTimeout=" + (task.getTimeout() / 1000);
else {
if (StringUtil.indexOfIgnoreCase(task.getUrl().getQuery() + "", "RequestTimeout") != -1)
url = task.getUrl().toExternalForm();
else
url = task.getUrl().toExternalForm() + "&RequestTimeout=" + (task.getTimeout() / 1000);
}
// HttpMethod method = new GetMethod(url);
// HostConfiguration hostConfiguration = client.getHostConfiguration();
Header[] headers = new Header[] { HTTPEngine.header("User-Agent", "CFSCHEDULE") };
// method.setRequestHeader("User-Agent","CFSCHEDULE");
// Userame / Password
Credentials credentials = task.getCredentials();
String user = null, pass = null;
if (credentials != null) {
user = credentials.getUsername();
pass = credentials.getPassword();
// get.addRequestHeader("Authorization","Basic admin:spwwn1p");
}
// Proxy
ProxyData proxy = task.getProxyData();
if (!ProxyDataImpl.isValid(proxy) && config.isProxyEnableFor(task.getUrl().getHost())) {
proxy = config.getProxyData();
}
HTTPResponse rsp = null;
// execute
try {
rsp = HTTPEngine.get(new URL(url), user, pass, task.getTimeout(), true, charset, null, proxy, headers);
} catch (Exception e) {
LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
hasError = true;
}
// write file
Resource file = task.getResource();
if (!hasError && file != null && task.isPublish()) {
String n = file.getName();
if (n.indexOf("{id}") != -1) {
n = StringUtil.replace(n, "{id}", CreateUUID.invoke(), false);
file = file.getParentResource().getRealResource(n);
}
if (isText(rsp) && task.isResolveURL()) {
String str;
try {
InputStream stream = rsp.getContentAsStream();
str = stream == null ? "" : IOUtil.toString(stream, (Charset) null);
if (str == null)
str = "";
} catch (IOException e) {
str = e.getMessage();
}
try {
str = new URLResolver().transform(str, task.getUrl(), false);
} catch (PageException e) {
LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
hasError = true;
}
try {
IOUtil.write(file, str, charset, false);
} catch (IOException e) {
LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
hasError = true;
}
} else {
try {
IOUtil.copy(rsp.getContentAsStream(), file, true);
} catch (IOException e) {
LogUtil.log(log, Log.LEVEL_ERROR, logName, e);
hasError = true;
}
}
HTTPEngine.closeEL(rsp);
}
if (!hasError)
log.log(Log.LEVEL_INFO, logName, "executed");
}
Aggregations