Object handleReqAndPostProcess(Channel ctx, boolean isKeepAlive, Req req) { Object result; try { result = handler.handleReq(ctx, isKeepAlive, req); } catch (Throwable e) { result = e; } return HandlerResultProcessor.INSTANCE.postProcessResult(req, result); }
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; }
private HttpStatus handleIfFound(Channel channel, boolean isKeepAlive, HttpHandler handler, Req req) { try { return handler.handle(channel, isKeepAlive, req); } catch (NotFound nf) { return HttpStatus.NOT_FOUND; } }
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); }
static HttpWrapper[] assembleWrappers(FastHttp http, RouteOptions options) { List<HttpWrapper> wrappers = U.list(); wrappers.add(new HttpAuthWrapper(options.roles())); TransactionMode txMode = U.or(options.transaction(), TransactionMode.NONE); if (txMode != TransactionMode.NONE) { wrappers.add(new HttpTxWrapper(txMode)); } Collections.addAll(wrappers, getConfiguredWrappers(http, options)); return U.arrayOf(HttpWrapper.class, wrappers); }
@Override public String toString() { return contentTypeInfo(method.getDeclaringClass().getSimpleName() + "#" + method.getName() + paramsToString()); }
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()); }
@Override public Object invokeAndTransformResult(Mapper<Object, Object> transformation) throws Exception { Object result = invokeNext(); if (result instanceof Throwable) { return result; } else { return transform(transformation, result); } }
@Override public String toString() { return contentTypeInfo("() -> (predefined response)"); }
@Override public final HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) { return decorator.handle(ctx, isKeepAlive, req); }
public HttpRoutesImpl(String setupName, Customization customization) { this.id = ID_GEN.incrementAndGet(); this.setupName = setupName; this.customization = customization; this.staticResourcesHandler = new StaticResourcesHandler(customization); this.builtInResourcesHandler = new StaticResourcesHandler(customization); }
HttpManagedHandlerDecorator(AbstractDecoratingHttpHandler handler, final FastHttp http, final RouteOptions options) { super(handler, http); this.options = options; this.wrappers = new LazyInit<>(() -> HttpWrappers.assembleWrappers(http, options)); }
@Override public String toString() { return contentTypeInfo(U.frmt("() -> (static response of %s bytes)", response.length)); }
@Override public String toString() { return contentTypeInfo(U.frmt("() -> (resource %s)", resource.getName())); }
@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; }
static void registerStatic(SetupImpl setup, String verb, String path, RouteOptions options, byte[] response) { setup.routes().on(verb, path, new StaticHttpHandler(options, response)); setup.autoActivate(); }
static void registerPredefined(SetupImpl setup, String verb, String path, RouteOptions options, Object response) { FastHttp http = setup.http(); HttpRoutes routes = setup.routes(); routes.on(verb, path, new PredefinedResponseHandler(http, routes, options, response)); setup.autoActivate(); }
static void register(SetupImpl setup, String verb, String path, RouteOptions options, Method method, Object instance) { FastHttp http = setup.http(); HttpRoutes routes = setup.routes(); routes.on(verb, path, new MethodReqHandler(http, routes, options, method, instance)); setup.autoActivate(); }
@Override public Object invoke() throws Exception { return invokeNext(); }
@Override public Object invokeAndTransformResultCatchingErrors(Mapper<Object, Object> transformation) { Object resultOrError; try { resultOrError = invokeNext(); } catch (Throwable e) { resultOrError = e; } try { return transform(transformation, resultOrError); } catch (Throwable e) { return e; } }