Search in sources :

Example 1 with RequestTimeoutException

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

the class CFMLEngineImpl method _service.

private void _service(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, short type) throws ServletException, IOException {
    CFMLFactoryImpl factory = (CFMLFactoryImpl) getCFMLFactory(servlet.getServletConfig(), req);
    // is Lucee dialect enabled?
    if (type == Request.TYPE_LUCEE) {
        if (!((ConfigImpl) factory.getConfig()).allowLuceeDialect()) {
            try {
                PageContextImpl.notSupported();
            } catch (ApplicationException e) {
                throw new PageServletException(e);
            }
        }
    }
    boolean exeReqAsync = exeRequestAsync();
    PageContextImpl pc = factory.getPageContextImpl(servlet, req, rsp, null, false, -1, false, !exeReqAsync, false, -1, true, false, false);
    try {
        Request r = new Request(pc, type);
        if (exeReqAsync) {
            r.start();
            long ended = -1;
            do {
                SystemUtil.wait(Thread.currentThread(), 1000);
                // done?
                if (r.isDone()) {
                    // print.e("mas-done:"+System.currentTimeMillis());
                    break;
                } else // reach request timeout
                if (ended == -1 && (pc.getStartTime() + pc.getRequestTimeout()) < System.currentTimeMillis()) {
                    // print.e("req-time:"+System.currentTimeMillis());
                    CFMLFactoryImpl.terminate(pc, false);
                    ended = System.currentTimeMillis();
                // break; we do not break here, we give the thread itself the chance to end we need the exception output
                } else // the thread itself seem blocked, so we release this thread
                if (ended > -1 && ended + 10000 <= System.currentTimeMillis()) {
                    // print.e("give-up:"+System.currentTimeMillis());
                    break;
                }
            } while (true);
        } else // run in thread coming from servlet engine
        {
            try {
                Request.exe(pc, type, true, false);
            } catch (RequestTimeoutException rte) {
                if (rte.getThreadDeath() != null)
                    throw rte.getThreadDeath();
            } catch (NativeException ne) {
                if (ne.getCause() instanceof ThreadDeath)
                    throw (ThreadDeath) ne.getCause();
            } catch (ThreadDeath td) {
                throw td;
            } catch (Throwable t) {
            }
        }
    } finally {
        factory.releaseLuceePageContext(pc, !exeReqAsync);
    }
}
Also used : RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) PageServletException(lucee.runtime.exp.PageServletException) PageContextImpl(lucee.runtime.PageContextImpl) NativeException(lucee.runtime.exp.NativeException)

Example 2 with RequestTimeoutException

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

the class PageContextImpl method execute.

private final void execute(PageSource ps, boolean throwExcpetion, boolean onlyTopLevel) throws PageException {
    ApplicationListener listener = getRequestDialect() == CFMLEngine.DIALECT_CFML ? (gatewayContext ? config.getApplicationListener() : ((MappingImpl) ps.getMapping()).getApplicationListener()) : ModernAppListener.getInstance();
    Throwable _t = null;
    try {
        initallog();
        listener.onRequest(this, ps, null);
        if (ormSession != null) {
            releaseORM();
            removeLastPageSource(true);
        }
        log(false);
    } catch (Throwable t) {
        PageException pe;
        if (t instanceof ThreadDeath && getTimeoutStackTrace() != null) {
            t = pe = new RequestTimeoutException(this, (ThreadDeath) t);
        } else
            pe = Caster.toPageException(t, false);
        _t = t;
        if (!Abort.isSilentAbort(pe)) {
            this.pe = pe;
            log(true);
            if (fdEnabled) {
                FDSignal.signal(pe, false);
            }
            listener.onError(this, pe);
        } else
            log(false);
        if (throwExcpetion) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw pe;
        }
    } finally {
        if (enablecfoutputonly > 0) {
            setCFOutputOnly((short) 0);
        }
        if (!gatewayContext && getConfig().debug()) {
            try {
                listener.onDebug(this);
            } catch (Exception e) {
                pe = Caster.toPageException(e);
                if (!Abort.isSilentAbort(pe))
                    listener.onError(this, pe);
                ExceptionUtil.rethrowIfNecessary(e);
            }
        }
        ps = null;
        if (_t != null)
            ExceptionUtil.rethrowIfNecessary(_t);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationListener(lucee.runtime.listener.ApplicationListener) PageException(lucee.runtime.exp.PageException) CasterException(lucee.runtime.exp.CasterException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) DatabaseException(lucee.runtime.exp.DatabaseException) ServletException(javax.servlet.ServletException) ModernAppListenerException(lucee.runtime.listener.ModernAppListenerException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 3 with RequestTimeoutException

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

the class PageContextImpl method handlePageException.

public void handlePageException(PageException pe, boolean setHeader) {
    if (!Abort.isSilentAbort(pe)) {
        // if(requestTimeoutException!=null)
        // pe=Caster.toPageException(requestTimeoutException);
        int statusCode = getStatusCode(pe);
        // prepare response
        if (rsp != null) {
            // content-type
            Charset cs = ReqRspUtil.getCharacterEncoding(this, rsp);
            if (cs == null)
                ReqRspUtil.setContentType(rsp, "text/html");
            else
                ReqRspUtil.setContentType(rsp, "text/html; charset=" + cs.name());
            // expose error message in header
            if (rsp != null && pe.getExposeMessage())
                rsp.setHeader("exception-message", StringUtil.emptyIfNull(pe.getMessage()).replace('\n', ' '));
            // status code
            if (getConfig().getErrorStatusCode())
                rsp.setStatus(statusCode);
        }
        ErrorPage ep = errorPagePool.getErrorPage(pe, ErrorPageImpl.TYPE_EXCEPTION);
        // ExceptionHandler.printStackTrace(this,pe);
        ExceptionHandler.log(getConfig(), pe);
        // error page exception
        if (ep != null) {
            try {
                Struct sct = pe.getErrorBlock(this, ep);
                variablesScope().setEL(KeyConstants._error, sct);
                variablesScope().setEL(KeyConstants._cferror, sct);
                doInclude(new PageSource[] { ep.getTemplate() }, false);
                return;
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                if (Abort.isSilentAbort(t))
                    return;
                pe = Caster.toPageException(t);
            }
        }
        // error page request
        ep = errorPagePool.getErrorPage(pe, ErrorPageImpl.TYPE_REQUEST);
        if (ep != null) {
            PageSource ps = ep.getTemplate();
            if (ps.physcalExists()) {
                Resource res = ps.getResource();
                try {
                    String content = IOUtil.toString(res, getConfig().getTemplateCharset());
                    Struct sct = pe.getErrorBlock(this, ep);
                    java.util.Iterator<Entry<Key, Object>> it = sct.entryIterator();
                    Entry<Key, Object> e;
                    String v;
                    while (it.hasNext()) {
                        e = it.next();
                        v = Caster.toString(e.getValue(), null);
                        if (v != null)
                            content = repl(content, e.getKey().getString(), v);
                    }
                    write(content);
                    return;
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    pe = Caster.toPageException(t);
                }
            } else
                pe = new ApplicationException("The error page template for type request only works if the actual source file also exists. If the exception file is in an " + Constants.NAME + " archive (.lar), you need to use type exception instead.");
        }
        try {
            String template = getConfig().getErrorTemplate(statusCode);
            if (!StringUtil.isEmpty(template)) {
                try {
                    Struct catchBlock = pe.getCatchBlock(getConfig());
                    variablesScope().setEL(KeyConstants._cfcatch, catchBlock);
                    variablesScope().setEL(KeyConstants._catch, catchBlock);
                    doInclude(template, false);
                    return;
                } catch (PageException e) {
                    pe = e;
                }
            }
            if (!Abort.isSilentAbort(pe))
                forceWrite(getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH).toString(this, pe.toDumpData(this, 9999, DumpUtil.toDumpProperties()), true));
        } catch (Exception e) {
        }
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ErrorPage(lucee.runtime.err.ErrorPage) Resource(lucee.commons.io.res.Resource) Charset(java.nio.charset.Charset) PageException(lucee.runtime.exp.PageException) CasterException(lucee.runtime.exp.CasterException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) DatabaseException(lucee.runtime.exp.DatabaseException) ServletException(javax.servlet.ServletException) ModernAppListenerException(lucee.runtime.listener.ModernAppListenerException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) ApplicationException(lucee.runtime.exp.ApplicationException) Key(lucee.runtime.type.Collection.Key)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)3 RequestTimeoutException (lucee.runtime.exp.RequestTimeoutException)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 JspException (javax.servlet.jsp.JspException)2 CacheException (lucee.commons.io.cache.exp.CacheException)2 CasterException (lucee.runtime.exp.CasterException)2 DatabaseException (lucee.runtime.exp.DatabaseException)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 MissingIncludeException (lucee.runtime.exp.MissingIncludeException)2 PageException (lucee.runtime.exp.PageException)2 ModernAppListenerException (lucee.runtime.listener.ModernAppListenerException)2 Charset (java.nio.charset.Charset)1 Entry (java.util.Map.Entry)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Resource (lucee.commons.io.res.Resource)1 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)1 PageContextImpl (lucee.runtime.PageContextImpl)1 ErrorPage (lucee.runtime.err.ErrorPage)1