use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class SystemOutput method call.
public static boolean call(PageContext pc, Object obj, boolean addNewLine, boolean doErrorStream) throws PageException {
String string;
if (Decision.isSimpleValue(obj))
string = Caster.toString(obj);
else {
try {
string = Serialize.call(pc, obj);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
string = obj.toString();
}
}
PrintStream stream = System.out;
// string+=":"+Thread.currentThread().getId();
if (doErrorStream)
stream = System.err;
if (string != null) {
if (StringUtil.indexOfIgnoreCase(string, "<print-stack-trace>") != -1) {
String st = ExceptionUtil.getStacktrace(new Exception("Stack trace"), false);
string = StringUtil.replace(string, "<print-stack-trace>", "\n" + st + "\n", true).trim();
}
if (StringUtil.indexOfIgnoreCase(string, "<hash-code>") != -1) {
String st = obj.hashCode() + "";
string = StringUtil.replace(string, "<hash-code>", st, true).trim();
}
}
if (addNewLine)
stream.println(string);
else
stream.print(string);
return true;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class RestDeleteApplication method call.
public static String call(PageContext pc, String dirPath, String strWebAdminPassword) throws PageException {
Password webAdminPassword = CacheUtil.getPassword(pc, strWebAdminPassword, false);
Resource dir = RestDeleteApplication.toResource(pc, dirPath);
ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
try {
XMLConfigAdmin admin = XMLConfigAdmin.newInstance((ConfigWebImpl) pc.getConfig(), webAdminPassword);
Mapping[] mappings = config.getRestMappings();
Mapping mapping;
for (int i = 0; i < mappings.length; i++) {
mapping = mappings[i];
if (RestUtil.isMatch(pc, mapping, dir)) {
admin.removeRestMapping(mapping.getVirtual());
admin.storeAndReload();
}
}
} catch (Exception e) {
throw Caster.toPageException(e);
}
return null;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class RestInitApplication method update.
private static void update(PageContext pc, Resource dir, String virtual, Password webAdminPassword, boolean defaultMapping) throws PageException {
try {
XMLConfigAdmin admin = XMLConfigAdmin.newInstance((ConfigWebImpl) pc.getConfig(), webAdminPassword);
admin.updateRestMapping(virtual, dir.getAbsolutePath(), defaultMapping);
admin.storeAndReload();
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Image method toDumpData.
@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
DumpData dd = _info().toDumpData(pageContext, maxlevel, dp);
if (dd instanceof DumpTable) {
DumpTable dt = ((DumpTable) dd);
dt.setTitle("Struct (Image)");
try {
dt.setComment("<img style=\"margin:5px\" src=\"data:image/png;base64," + getBase64String("png") + "\">");
} catch (PageException e) {
}
}
return dd;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Log4jUtil method getAppender.
public static final Appender getAppender(Config config, Layout layout, String name, ClassDefinition cd, Map<String, String> appenderArgs) {
if (appenderArgs == null)
appenderArgs = new HashMap<String, String>();
// Appender
Appender appender = null;
if (cd != null && cd.hasClass()) {
// Console Appender
if (ConsoleAppender.class.getName().equalsIgnoreCase(cd.getClassName())) {
// stream-type
boolean doError = false;
String st = Caster.toString(appenderArgs.get("streamtype"), null);
if (!StringUtil.isEmpty(st, true)) {
st = st.trim().toLowerCase();
if (st.equals("err") || st.equals("error"))
doError = true;
}
appenderArgs.put("streamtype", doError ? "error" : "output");
// get print writer
PrintWriter pw;
if (doError) {
if (config.getErrWriter() == null)
pw = new PrintWriter(System.err);
else
pw = config.getErrWriter();
} else {
if (config.getOutWriter() == null)
pw = new PrintWriter(System.out);
else
pw = config.getOutWriter();
}
appender = new ConsoleAppender(pw, layout);
} else if (DatasourceAppender.class.getName().equalsIgnoreCase(cd.getClassName())) {
// datasource
String dsn = Caster.toString(appenderArgs.get("datasource"), null);
if (StringUtil.isEmpty(dsn, true))
dsn = Caster.toString(appenderArgs.get("datasourceName"), null);
if (!StringUtil.isEmpty(dsn, true))
dsn = dsn.trim();
appenderArgs.put("datasource", dsn);
// username
String user = Caster.toString(appenderArgs.get("username"), null);
if (StringUtil.isEmpty(user, true))
user = Caster.toString(appenderArgs.get("user"), null);
if (!StringUtil.isEmpty(user, true))
user = user.trim();
else
user = null;
appenderArgs.put("username", user);
// password
String pass = Caster.toString(appenderArgs.get("password"), null);
if (StringUtil.isEmpty(pass, true))
pass = Caster.toString(appenderArgs.get("pass"), null);
if (!StringUtil.isEmpty(pass, true))
pass = pass.trim();
else
pass = null;
appenderArgs.put("password", pass);
try {
appender = new DatasourceAppender(config, layout, dsn, user, pass);
} catch (PageException e) {
SystemOut.printDate(e);
appender = null;
}
} else if (RollingResourceAppender.class.getName().equalsIgnoreCase(cd.getClassName())) {
// path
Resource res = null;
String path = Caster.toString(appenderArgs.get("path"), null);
if (!StringUtil.isEmpty(path, true)) {
path = path.trim();
path = ConfigWebUtil.translateOldPath(path);
res = ConfigWebUtil.getFile(config, config.getConfigDir(), path, ResourceUtil.TYPE_FILE);
if (res.isDirectory()) {
res = res.getRealResource(name + ".log");
}
}
if (res == null) {
res = ConfigWebUtil.getFile(config, config.getConfigDir(), "logs/" + name + ".log", ResourceUtil.TYPE_FILE);
}
// charset
Charset charset = CharsetUtil.toCharset(Caster.toString(appenderArgs.get("charset"), null), null);
if (charset == null) {
charset = config.getResourceCharset();
appenderArgs.put("charset", charset.name());
}
// maxfiles
int maxfiles = Caster.toIntValue(appenderArgs.get("maxfiles"), 10);
appenderArgs.put("maxfiles", Caster.toString(maxfiles));
// maxfileSize
long maxfilesize = Caster.toLongValue(appenderArgs.get("maxfilesize"), 1024 * 1024 * 10);
appenderArgs.put("maxfilesize", Caster.toString(maxfilesize));
// timeout
// timeout in seconds
int timeout = Caster.toIntValue(appenderArgs.get("timeout"), 60);
appenderArgs.put("timeout", Caster.toString(timeout));
try {
appender = new RollingResourceAppender(layout, res, charset, true, maxfilesize, maxfiles, timeout, null);
} catch (IOException e) {
SystemOut.printDate(e);
}
} else // class defintion
{
Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
if (obj instanceof Appender) {
appender = (Appender) obj;
AppenderSkeleton as = obj instanceof AppenderSkeleton ? (AppenderSkeleton) obj : null;
Iterator<Entry<String, String>> it = appenderArgs.entrySet().iterator();
Entry<String, String> e;
String n;
while (it.hasNext()) {
e = it.next();
n = e.getKey();
if (as != null) {
if ("threshold".equalsIgnoreCase(n)) {
Level level = Level.toLevel(e.getValue(), null);
if (level != null) {
as.setThreshold(level);
continue;
}
}
}
try {
Reflector.callSetter(obj, e.getKey(), e.getValue());
} catch (PageException e1) {
// TODO log
SystemOut.printDate(e1);
}
}
}
}
}
if (appender instanceof AppenderSkeleton) {
((AppenderSkeleton) appender).activateOptions();
} else if (appender == null) {
PrintWriter pw;
if (config.getOutWriter() == null)
pw = new PrintWriter(System.out);
else
pw = config.getOutWriter();
appender = new ConsoleAppender(pw, layout);
}
return appender;
}
Aggregations