private void handleError(Req req, Throwable e) { req.revert(); req.async(); HttpIO.INSTANCE.error(req, e, LogLevel.ERROR); // the Req object will do the rendering req.done(); }
@Override public Object execute(final Req req, final Resp resp) { ProxyMapping mapping = findMapping(req); if (mapping == null) return null; // not found! req.async(); process(req, resp, mapping, 1, U.time()); return req; }
HttpStatus errorAndDone(final Req req, final Throwable error, final LogLevel logLevel) { req.revert(); req.async(); Runnable errorHandler = () -> { error(req, error, logLevel); // the Req object will do the rendering req.done(); }; Ctx ctx = Ctxs.get(); if (ctx == null) { With.exchange(req).run(errorHandler); } else { Jobs.execute(errorHandler); } return HttpStatus.ASYNC; }
@SuppressWarnings("unchecked") public Object postProcessResult(Req req, Object result) { if (result instanceof HttpStatus) { return result; } else if (result instanceof Req) { U.must(req == result, "Unknown request instance was received as result!"); return reqToStatus(req, result); } else if (result instanceof Resp) { U.must(req != null && req.response() == result, "Unknown response instance was received as result!"); return reqToStatus(req, result); } else if (result == null || result instanceof NotFound) { // not found return HttpStatus.NOT_FOUND; } else if ((result instanceof Future<?>) || (result instanceof org.rapidoid.concurrent.Future<?>)) { // async if (req != null) { req.async(); } return HttpStatus.ASYNC; } else if (result instanceof Results) { return ((Results) result).all(); // fetch while still inside tx (potentially) } else { return result; } }
private void handleError(Req req, Throwable e) { req.revert(); req.async(); HttpIO.INSTANCE.error(req, e, LogLevel.ERROR); // the Req object will do the rendering req.done(); }
@Override public Object execute(final Req req, final Resp resp) throws Exception { ProxyMapping mapping = findMapping(req); if (mapping == null) return null; // not found! req.async(); process(req, resp, mapping, 1, U.time()); return req; }
HttpStatus errorAndDone(final Req req, final Throwable error, final LogLevel logLevel) { req.revert(); req.async(); Runnable errorHandler = new Runnable() { @Override public void run() { error(req, error, logLevel); // the Req object will do the rendering req.done(); } }; Ctx ctx = Ctxs.get(); if (ctx == null) { With.exchange(req).run(errorHandler); } else { Jobs.execute(errorHandler); } return HttpStatus.ASYNC; }
@SuppressWarnings("unchecked") public Object postProcessResult(Req req, Object result) { if (result instanceof HttpStatus) { return result; } else if (result instanceof Req) { U.must(req == result, "Unknown request instance was received as result!"); return reqToStatus(req, result); } else if (result instanceof Resp) { U.must(req != null && req.response() == result, "Unknown response instance was received as result!"); return reqToStatus(req, result); } else if (result == null || result instanceof NotFound) { // not found return HttpStatus.NOT_FOUND; } else if ((result instanceof Future<?>) || (result instanceof org.rapidoid.concurrent.Future<?>)) { // async if (req != null) { req.async(); } return HttpStatus.ASYNC; } else if (result instanceof Results) { return ((Results) result).all(); // fetch while still inside tx (potentially) } else { return result; } }