private boolean isCacheable() { return route != null && HttpUtils.isGetReq(this) && route.cache() != null && cookies.isEmpty() && U.notEmpty(host()) && !hasToken(); }
@Override public Object wrap(final Req req, final HandlerInvocation invocation) { final AtomicReference<Object> resultHolder = new AtomicReference<>(); U.must(txMode != null && txMode != TransactionMode.NONE); boolean readOnly = (txMode == TransactionMode.AUTO) ? HttpUtils.isGetReq(req) : txMode == TransactionMode.READ_ONLY; try { JPA.transaction(() -> { Object res = invocation.invokeAndTransformResultCatchingErrors(result -> { if (result instanceof Throwable) { return result; } // serialize the result into a HTTP response body, while still inside tx (see #153) RespBody body = BodyRenderer.resultToRespBody(req.response(), result); return body; }); if (res instanceof Throwable) { // throw to rollback Throwable err = (Throwable) res; throw U.rte("Error occurred inside the transactional web handler!", err); } else { resultHolder.set(res); } }, readOnly); } catch (Throwable e) { resultHolder.set(e); } return resultHolder.get(); }
private void handleError(Throwable error, final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) { if (error instanceof ConnectException || error instanceof IOException) { if (HttpUtils.isGetReq(req) && !U.timedOut(since, timeout())) { Jobs.after(retryDelay()).milliseconds(() -> process(req, resp, mapping, attempts + 1, since)); } else { HttpIO.INSTANCE.errorAndDone(req, U.rte("Couldn't connect to the upstream!", error), LogLevel.DEBUG); } } else { HttpIO.INSTANCE.errorAndDone(req, error, LogLevel.ERROR); } }
@Override public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND; try { String[] staticFilesLocations = customization.staticFilesPath(); if (!U.isEmpty(staticFilesLocations)) { Res res = HttpUtils.staticResource(req, staticFilesLocations); if (res != null) { StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity(); if (staticFilesSecurity.canServe(req, res)) { byte[] bytes = res.getBytesOrNull(); if (bytes != null) { MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY); HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes); return HttpStatus.DONE; } } } } return HttpStatus.NOT_FOUND; } catch (Exception e) { return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } }
? HttpUtils.isGetReq(req) : txMode == TransactionMode.READ_ONLY;
private boolean isCacheable() { return route != null && HttpUtils.isGetReq(this) && route.cache() != null && cookies.isEmpty() && U.notEmpty(host()) && !hasToken(); }
@Override public Object execute(Req req, Resp resp) { if (HttpUtils.isGetReq(req)) { Results items = sqlItems(api.sql); return api.single ? U.single(items) : items; } else { int changes = executeSql(api.sql); return U.map("success", true, "changes", changes); // FIXME improve } }
private void handleError(Throwable error, final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) { if (error instanceof ConnectException || error instanceof IOException) { if (HttpUtils.isGetReq(req) && !Msc.timedOut(since, timeout())) { Jobs.after(retryDelay()).milliseconds(new Runnable() { @Override public void run() { process(req, resp, mapping, attempts + 1, since); } }); } else { HttpIO.INSTANCE.errorAndDone(req, U.rte("Couldn't connect to the upstream!", error), LogLevel.DEBUG); } } else { HttpIO.INSTANCE.errorAndDone(req, error, LogLevel.ERROR); } }
@Override public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND; try { String[] staticFilesLocations = customization.staticFilesPath(); if (!U.isEmpty(staticFilesLocations)) { Res res = HttpUtils.staticResource(req, staticFilesLocations); if (res != null) { StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity(); if (staticFilesSecurity.canServe(req, res)) { byte[] bytes = res.getBytesOrNull(); if (bytes != null) { MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY); HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes); return HttpStatus.DONE; } } } } return HttpStatus.NOT_FOUND; } catch (Exception e) { return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } }