Search in sources :

Example 86 with PageException

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;
}
Also used : PrintStream(java.io.PrintStream) PageException(lucee.runtime.exp.PageException)

Example 87 with PageException

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;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.rest.Mapping) XMLConfigAdmin(lucee.runtime.config.XMLConfigAdmin) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Password(lucee.runtime.config.Password)

Example 88 with PageException

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);
    }
}
Also used : XMLConfigAdmin(lucee.runtime.config.XMLConfigAdmin) PageException(lucee.runtime.exp.PageException)

Example 89 with PageException

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;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) PageException(lucee.runtime.exp.PageException) DumpData(lucee.runtime.dump.DumpData)

Example 90 with PageException

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;
}
Also used : TaskAppender(lucee.commons.io.log.log4j.appender.TaskAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(lucee.commons.io.log.log4j.appender.ConsoleAppender) DatasourceAppender(lucee.commons.io.log.log4j.appender.DatasourceAppender) RollingResourceAppender(lucee.commons.io.log.log4j.appender.RollingResourceAppender) ConsoleAppender(lucee.commons.io.log.log4j.appender.ConsoleAppender) PageException(lucee.runtime.exp.PageException) AppenderSkeleton(org.apache.log4j.AppenderSkeleton) HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) Charset(java.nio.charset.Charset) IOException(java.io.IOException) DatasourceAppender(lucee.commons.io.log.log4j.appender.DatasourceAppender) RollingResourceAppender(lucee.commons.io.log.log4j.appender.RollingResourceAppender) Entry(java.util.Map.Entry) Level(org.apache.log4j.Level) PrintWriter(java.io.PrintWriter)

Aggregations

PageException (lucee.runtime.exp.PageException)200 ApplicationException (lucee.runtime.exp.ApplicationException)56 IOException (java.io.IOException)54 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)37 ExpressionException (lucee.runtime.exp.ExpressionException)32 Resource (lucee.commons.io.res.Resource)30 SecurityException (lucee.runtime.exp.SecurityException)26 BundleException (org.osgi.framework.BundleException)26 MalformedURLException (java.net.MalformedURLException)25 Array (lucee.runtime.type.Array)21 Key (lucee.runtime.type.Collection.Key)17 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)15 SAXException (org.xml.sax.SAXException)15 Entry (java.util.Map.Entry)14 ClassException (lucee.commons.lang.ClassException)14 DeprecatedException (lucee.runtime.exp.DeprecatedException)14 SMTPException (lucee.runtime.net.mail.SMTPException)13 ArrayImpl (lucee.runtime.type.ArrayImpl)13 Query (lucee.runtime.type.Query)13