@Override public Map<String, Object> attributes() { return http().attributes(); }
HttpIO.INSTANCE.removeTrailingSlash(buf, uri); String err = validateRequest(buf, verb, uri); if (err != null) { HttpIO.INSTANCE.writeBadRequest(channel); HandlerMatch match; if (isGet && shouldServeBuiltInResources(buf, path)) { match = routes.builtInResourcesHandler(); if (match != null) { req = createReq(channel, isGet, isKeepAlive, data, buf, matchingRoute, match, handler); if (serveFromCache(req)) return; status = handleIfFound(channel, isKeepAlive, handler, req); status = tryGenericHandlers(channel, isKeepAlive, req); if (handleError(channel, isKeepAlive, req, e)) return; handleNotFound(channel, isKeepAlive, req); return;
public ReqImpl(FastHttp http, Channel channel, boolean isKeepAlive, String verb, String uri, String path, String query, byte[] body, Map<String, String> params, Map<String, String> headers, Map<String, String> cookies, Map<String, Object> posted, Map<String, List<Upload>> files, boolean pendingBodyParsing, MediaType defaultContentType, String zone, Route route) { this.http = http; this.channel = channel; this.isKeepAlive = isKeepAlive; this.verb = verb; this.uri = uri; this.path = path; this.query = query; this.body = body; this.params = params; this.headers = headers; this.cookies = cookies; this.posted = posted; this.files = files; this.pendingBodyParsing = pendingBodyParsing; this.defaultContentType = defaultContentType; this.zone = zone; this.routes = http.routes(); this.route = route; this.connId = channel.connId(); this.handle = channel.handle(); this.requestId = channel.requestId(); this.custom = http.custom(); this.cacheKey = createCacheKey(); }
public void notFound(Channel ctx, boolean isKeepAlive, MediaType contentType, HttpHandler fromHandler, Req req) { HttpStatus status = HttpStatus.NOT_FOUND; List<HttpHandler> genericHandlers = routes.genericHandlers(); int count = genericHandlers.size(); for (int i = 0; i < count; i++) { HttpHandler handler = genericHandlers.get(i); if (handler == fromHandler) { // a generic handler returned "not found" -> go to the next one if (i < count - 1) { HttpHandler nextHandler = genericHandlers.get(i + 1); status = handleIfFound(ctx, isKeepAlive, nextHandler, req); break; } } } if (status == HttpStatus.NOT_FOUND) { handleNotFound(ctx, isKeepAlive, req); } }
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); }
public static Setup create(String name) { IoCContext ioc = IoC.createContext().name(name); Config config = Conf.section(name); Customization customization = new Customization(name, My.custom(), config); HttpRoutesImpl routes = new HttpRoutesImpl(name, customization); Screen gui = new ScreenBean(); FastHttp http = new FastHttp(routes, config, gui); Setup setup = new SetupImpl(name, "main", http, ioc, config, customization, routes, gui, false); instances.add(setup); return setup; }
@Override public boolean hasRoute(HttpVerb verb, String uri) { ReqImpl reqq = (ReqImpl) req(); return reqq.http().hasRouteOrResource(verb, uri); }
private HttpStatus tryGenericHandlers(Channel channel, boolean isKeepAlive, ReqImpl req) { for (HttpHandler handler : routes.genericHandlers()) { HttpStatus status = handleIfFound(channel, isKeepAlive, handler, req); if (status != HttpStatus.NOT_FOUND) { return status; } } return HttpStatus.NOT_FOUND; }
private static HttpWrapper[] getConfiguredWrappers(FastHttp http, RouteOptions options) { return U.or( options.wrappers(), // wrappers specific to the route http.custom().wrappers(), // or wrappers for the http setup new HttpWrapper[0] // or no wrappers ); }
private void handleNotFound(Channel channel, boolean isKeepAlive, Req req) { handleError(channel, isKeepAlive, req, new NotFound()); }
private boolean handleError(Channel channel, boolean isKeepAlive, Req req, Throwable e) { if (req != null) { if (!((ReqImpl) req).isStopped()) { try { HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } catch (Exception e1) { Log.error("HTTP error handler error!", e1); internalServerError(channel, isKeepAlive, req); } } return true; } else { Log.error("Low-level HTTP handler error!", e); internalServerError(channel, isKeepAlive, null); } return false; }
public void notFound(Channel ctx, boolean isKeepAlive, MediaType contentType, HttpHandler fromHandler, Req req) { HttpStatus status = HttpStatus.NOT_FOUND; List<HttpHandler> genericHandlers = routes.genericHandlers(); int count = genericHandlers.size(); for (int i = 0; i < count; i++) { HttpHandler handler = genericHandlers.get(i); if (handler == fromHandler) { // a generic handler returned "not found" -> go to the next one if (i < count - 1) { HttpHandler nextHandler = genericHandlers.get(i + 1); status = handleIfFound(ctx, isKeepAlive, nextHandler, req); break; } } } if (status == HttpStatus.NOT_FOUND) { handleNotFound(ctx, isKeepAlive, req); } }
http.notFound(ctx, isKeepAlive, ctype, handler, req); return HttpStatus.NOT_FOUND;
DefaultSetup() { Customization customization = new Customization("main", My.custom(), Conf.ROOT); HttpRoutesImpl routes = new HttpRoutesImpl("main", customization); FastHttp http = new FastHttp(routes, MAIN_CFG, gui); main = new SetupImpl("main", MAIN_ZONE, http, IoC.defaultContext(), MAIN_CFG, customization, routes, gui, true); Setups.register(main); initDefaults(); }
@Override public boolean hasRoute(HttpVerb verb, String uri) { ReqImpl reqq = (ReqImpl) req(); return reqq.http().hasRouteOrResource(verb, uri); }
private HttpStatus tryGenericHandlers(Channel channel, boolean isKeepAlive, ReqImpl req) { for (HttpHandler handler : routes.genericHandlers()) { HttpStatus status = handleIfFound(channel, isKeepAlive, handler, req); if (status != HttpStatus.NOT_FOUND) { return status; } } return HttpStatus.NOT_FOUND; }
private static HttpWrapper[] getConfiguredWrappers(FastHttp http, RouteOptions options) { return U.or( options.wrappers(), // wrappers specific to the route http.custom().wrappers(), // or wrappers for the http setup new HttpWrapper[0] // or no wrappers ); }
private void handleNotFound(Channel channel, boolean isKeepAlive, Req req) { handleError(channel, isKeepAlive, req, new NotFound()); }
private boolean handleError(Channel channel, boolean isKeepAlive, Req req, Throwable e) { if (req != null) { if (!((ReqImpl) req).isStopped()) { try { HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR); } catch (Exception e1) { Log.error("HTTP error handler error!", e1); internalServerError(channel, isKeepAlive, req); } } return true; } else { Log.error("Low-level HTTP handler error!", e); internalServerError(channel, isKeepAlive, null); } return false; }
HttpIO.INSTANCE.removeTrailingSlash(buf, uri); String err = validateRequest(buf, verb, uri); if (err != null) { HttpIO.INSTANCE.writeBadRequest(channel); HandlerMatch match; if (isGet && shouldServeBuiltInResources(buf, path)) { match = routes.builtInResourcesHandler(); if (match != null) { req = createReq(channel, isGet, isKeepAlive, data, buf, matchingRoute, match, handler); if (serveFromCache(req)) return; status = handleIfFound(channel, isKeepAlive, handler, req); status = tryGenericHandlers(channel, isKeepAlive, req); if (handleError(channel, isKeepAlive, req, e)) return; handleNotFound(channel, isKeepAlive, req); return;