Search in sources :

Example 16 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class ChildThreadImpl method execute.

public PageException execute(Config config) {
    PageContext oldPc = ThreadLocalPageContext.get();
    Page p = page;
    PageContextImpl pc = null;
    try {
        // deamon
        if (this.pc != null) {
            pc = this.pc;
            ThreadLocalPageContext.register(pc);
        } else // task
        {
            ConfigWebImpl cwi;
            try {
                cwi = (ConfigWebImpl) config;
                DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
                pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
                pc.setRequestTimeout(requestTimeout);
                p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
            // p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
            } catch (PageException e) {
                return e;
            }
            pc.addPageSource(p.getPageSource(), true);
        }
        threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
        pc.setCurrentThreadScope(new ThreadsImpl(this));
        pc.setThread(Thread.currentThread());
        // String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
        Undefined undefined = pc.us();
        Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
        LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
        // Key[] keys = attrs.keys();
        Iterator<Entry<Key, Object>> it = attrs.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            newArgs.setEL(e.getKey(), e.getValue());
        }
        newLocal.setEL(KEY_ATTRIBUTES, newArgs);
        Argument oldArgs = pc.argumentsScope();
        Local oldLocal = pc.localScope();
        int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
        pc.setFunctionScopes(newLocal, newArgs);
        try {
            p.threadCall(pc, threadIndex);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!Abort.isSilentAbort(t)) {
                ConfigWeb c = pc.getConfig();
                if (c instanceof ConfigImpl) {
                    ConfigImpl ci = (ConfigImpl) c;
                    Log log = ci.getLog("thread");
                    if (log != null)
                        LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
                }
                PageException pe = Caster.toPageException(t);
                if (!serializable)
                    catchBlock = pe.getCatchBlock(pc.getConfig());
                return pe;
            }
        } finally {
            completed = true;
            pc.setFunctionScopes(oldLocal, oldArgs);
            undefined.setMode(oldMode);
            // pc.getScopeFactory().recycle(newArgs);
            pc.getScopeFactory().recycle(pc, newLocal);
            if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
                HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
                pc.flush();
                contentType = rsp.getContentType();
                Pair<String, Object>[] _headers = rsp.getHeaders();
                if (_headers != null)
                    for (int i = 0; i < _headers.length; i++) {
                        if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
                            contentEncoding = Caster.toString(_headers[i].getValue(), null);
                    }
            }
        }
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        pc = null;
        if (oldPc != null)
            ThreadLocalPageContext.register(oldPc);
    }
    return null;
}
Also used : Argument(lucee.runtime.type.scope.Argument) Page(lucee.runtime.Page) Entry(java.util.Map.Entry) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) LocalImpl(lucee.runtime.type.scope.LocalImpl) Pair(lucee.commons.lang.Pair) PageException(lucee.runtime.exp.PageException) Undefined(lucee.runtime.type.scope.Undefined) Log(lucee.commons.io.log.Log) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) ArgumentThreadImpl(lucee.runtime.type.scope.ArgumentThreadImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) Key(lucee.runtime.type.Collection.Key) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 17 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class ORMUtil method getDataSourceName.

public static String getDataSourceName(PageContext pc, Component cfc, String defaultValue) {
    pc = ThreadLocalPageContext.get(pc);
    // datasource defined with cfc
    Struct meta = null;
    try {
        meta = cfc.getMetaData(pc);
        String datasourceName = Caster.toString(meta.get(KeyConstants._datasource, null), null);
        if (!StringUtil.isEmpty(datasourceName, true)) {
            return datasourceName.trim();
        }
    } catch (PageException e) {
    }
    DataSource ds = getDefaultDataSource(pc, null);
    if (ds != null)
        return ds.getName();
    return defaultValue;
}
Also used : PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct) DataSource(lucee.runtime.db.DataSource)

Example 18 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class OSGiUtil method toVersion.

public static Version toVersion(String version, Version defaultValue) {
    if (StringUtil.isEmpty(version))
        return defaultValue;
    // String[] arr = ListUtil.listToStringArray(version, '.');
    String[] arr;
    try {
        arr = ListUtil.toStringArrayTrim(ListUtil.listToArray(version.trim(), '.'));
    } catch (PageException e) {
        // should not happen
        return defaultValue;
    }
    Integer major, minor, micro;
    String qualifier;
    if (arr.length == 1) {
        major = Caster.toInteger(arr[0], null);
        minor = 0;
        micro = 0;
        qualifier = null;
    } else if (arr.length == 2) {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = 0;
        qualifier = null;
    } else if (arr.length == 3) {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = Caster.toInteger(arr[2], null);
        qualifier = null;
    } else {
        major = Caster.toInteger(arr[0], null);
        minor = Caster.toInteger(arr[1], null);
        micro = Caster.toInteger(arr[2], null);
        qualifier = arr[3];
    }
    if (major == null || minor == null || micro == null)
        return defaultValue;
    if (qualifier == null)
        return new Version(major, minor, micro);
    return new Version(major, minor, micro, qualifier);
}
Also used : PageException(lucee.runtime.exp.PageException) Version(org.osgi.framework.Version)

Example 19 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class Reflector method getConstructorInstance.

public static ConstructorInstance getConstructorInstance(Class clazz, Object[] args, ConstructorInstance defaultValue) {
    args = cleanArgs(args);
    // getConstructors(clazz);
    Constructor[] constructors = cStorage.getConstructors(clazz, args.length);
    if (constructors != null) {
        Class[] clazzArgs = getClasses(args);
        // exact comparsion
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                Class[] parameterTypes = constructors[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
                        continue outer;
                }
                return new ConstructorInstance(constructors[i], args);
            }
        }
        // like comparsion
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                Class[] parameterTypes = constructors[i].getParameterTypes();
                for (int y = 0; y < parameterTypes.length; y++) {
                    if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
                        continue outer;
                }
                return new ConstructorInstance(constructors[i], args);
            }
        }
        // convert comparsion
        ConstructorInstance ci = null;
        int _rating = 0;
        outer: for (int i = 0; i < constructors.length; i++) {
            if (constructors[i] != null) {
                RefInteger rating = (constructors.length > 1) ? new RefIntegerImpl(0) : null;
                Class[] parameterTypes = constructors[i].getParameterTypes();
                Object[] newArgs = new Object[args.length];
                for (int y = 0; y < parameterTypes.length; y++) {
                    try {
                        newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
                    } catch (PageException e) {
                        continue outer;
                    }
                }
                if (ci == null || rating.toInt() > _rating) {
                    if (rating != null)
                        _rating = rating.toInt();
                    ci = new ConstructorInstance(constructors[i], newArgs);
                }
            // return new ConstructorInstance(constructors[i],newArgs);
            }
        }
        return ci;
    }
    return defaultValue;
// throw new NoSuchMethodException("No matching Constructor for "+clazz.getName()+"("+getDspMethods(getClasses(args))+") found");
}
Also used : PageException(lucee.runtime.exp.PageException) Constructor(java.lang.reflect.Constructor) RefInteger(lucee.commons.lang.types.RefInteger) ConstructorInstance(lucee.runtime.reflection.pairs.ConstructorInstance) RefIntegerImpl(lucee.commons.lang.types.RefIntegerImpl)

Example 20 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class RPCServer method doGet.

/**
 * Process GET requests. This includes handoff of pseudo-SOAP requests
 *
 * @param request request in
 * @param response request out
 * @throws ServletException
 */
public void doGet(HttpServletRequest request, HttpServletResponse response, Component component) throws ServletException {
    PrintWriter writer = new FilterPrintWriter(response);
    try {
        if (!doGet(request, response, writer, component)) {
            ReqRspUtil.setContentType(response, "text/html; charset=utf-8");
            writer.println("<html><h1>" + lucee.runtime.config.Constants.NAME + " Webservice</h1>");
            writer.println(Messages.getMessage("reachedServlet00"));
            writer.println("<p>" + Messages.getMessage("transportName00", "<b>http</b>"));
            writer.println("</html>");
        }
    } catch (Throwable e) {
        ExceptionUtil.rethrowIfNecessary(e);
        if (e instanceof InvocationTargetException)
            e = ((InvocationTargetException) e).getTargetException();
        if (e instanceof PageException)
            throw new PageServletException((PageException) e);
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) PageServletException(lucee.runtime.exp.PageServletException) PageException(lucee.runtime.exp.PageException) FilterPrintWriter(org.apache.axis.transport.http.FilterPrintWriter) PageServletException(lucee.runtime.exp.PageServletException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter) FilterPrintWriter(org.apache.axis.transport.http.FilterPrintWriter)

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