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);
}
}
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);
}
}
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) {
}
}
}
Aggregations