private void handleWithWrappers(Channel channel, boolean isKeepAlive, MediaType contentType, Req req, HttpWrapper[] wrappers) { Object result; try { if (!U.isEmpty(wrappers)) { result = wrap(channel, isKeepAlive, req, 0, wrappers); } else { result = handleReqAndPostProcess(channel, isKeepAlive, req); } } catch (Throwable e) { result = e; } complete(channel, isKeepAlive, contentType, req, result); }
@Override public final HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!ctx.isAsync()) { // first checks if not async, to avoid exceptions when running the second time from non-IO thread ctx.async(); } execHandlerJob(ctx, isKeepAlive, options.contentType(), req); return HttpStatus.ASYNC; }
private void complete(Channel ctx, boolean isKeepAlive, MediaType contentType, Req req, Object result) { U.must(result != null, "The post-processed result cannot be null!"); U.must(!(result instanceof Req), "The post-processed result cannot be a Req instance!"); U.must(!(result instanceof Resp), "The post-processed result cannot be a Resp instance!"); if (result instanceof Throwable) { handleError(req, (Throwable) result); return; } if (result == HttpStatus.ERROR) { complete(ctx, isKeepAlive, contentType, req, U.rte("Handler error!")); return; } if (result == HttpStatus.NOT_FOUND) { http.notFound(ctx, isKeepAlive, contentType, handler, req); return; } if (result == HttpStatus.ASYNC) { return; } processNormalResult(req, result); }
private void execHandlerJob(final Channel channel, final boolean isKeepAlive, final MediaType contentType, final Req req) { With.tag(CTX_TAG_HANDLER).exchange(req).run(() -> { try { req.response() .view(options.view()) .contentType(options.contentType()) .mvc(options.mvc()); handleWithWrappers(channel, isKeepAlive, contentType, req, wrappers.get()); } catch (Throwable e) { handleError(req, e); } }); }
private Object invokeNext() throws Exception { int next = index + 1; Object result; if (next < wrappers.length) { result = wrap(channel, isKeepAlive, req, next, wrappers); } else { result = handleReqAndPostProcess(channel, isKeepAlive, req); } return result; }
public AbstractDecoratingHttpHandler(FastHttp http, RouteOptions options) { super(options); U.notNull(http, "http"); this.decorator = options.managed() ? new HttpManagedHandlerDecorator(this, http, options) : new HttpUnmanagedHandlerDecorator(this, http, options.contentType()); }
private Object invokeNext() throws Exception { int next = index + 1; Object result; if (next < wrappers.length) { result = wrap(channel, isKeepAlive, req, next, wrappers); } else { result = handleReqAndPostProcess(channel, isKeepAlive, req); } return result; }
public AbstractDecoratingHttpHandler(FastHttp http, RouteOptions options) { super(options); U.notNull(http, "http"); this.decorator = options.managed() ? new HttpManagedHandlerDecorator(this, http, options) : new HttpUnmanagedHandlerDecorator(this, http, options.contentType()); }
private void handleWithWrappers(Channel channel, boolean isKeepAlive, MediaType contentType, Req req, HttpWrapper[] wrappers) { Object result; try { if (!U.isEmpty(wrappers)) { result = wrap(channel, isKeepAlive, req, 0, wrappers); } else { result = handleReqAndPostProcess(channel, isKeepAlive, req); } } catch (Throwable e) { result = e; } complete(channel, isKeepAlive, contentType, req, result); }
private void complete(Channel ctx, boolean isKeepAlive, MediaType contentType, Req req, Object result) { U.must(result != null, "The post-processed result cannot be null!"); U.must(!(result instanceof Req), "The post-processed result cannot be a Req instance!"); U.must(!(result instanceof Resp), "The post-processed result cannot be a Resp instance!"); if (result instanceof Throwable) { handleError(req, (Throwable) result); return; } if (result == HttpStatus.ERROR) { complete(ctx, isKeepAlive, contentType, req, U.rte("Handler error!")); return; } if (result == HttpStatus.NOT_FOUND) { http.notFound(ctx, isKeepAlive, contentType, handler, req); return; } if (result == HttpStatus.ASYNC) { return; } processNormalResult(req, result); }
@Override public final HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { if (!ctx.isAsync()) { // first checks if not async, to avoid exceptions when running the second time from non-IO thread ctx.async(); } execHandlerJob(ctx, isKeepAlive, options.contentType(), req); return HttpStatus.ASYNC; }