@Override public Setup req(HttpHandler handler) { routes.addGenericHandler(handler); autoActivate(); return this; }
@Override public synchronized void remove(String verb, String path) { addOrRemove(false, verb, path, null); }
@Override public Route find(HttpVerb verb, String path) { return Do.findIn(all()) .first(route -> route.verb().equals(verb) && route.path().equals(path)) .orElse(null); }
@Override public boolean hasRouteOrResource(HttpVerb verb, String uri) { if (verb == HttpVerb.GET) { String[] staticFilesLocations = custom().staticFilesPath(); if (U.notEmpty(staticFilesLocations)) { String filename = Str.triml(uri, '/'); if (filename.isEmpty()) filename = "index.html"; if (Res.from(filename, staticFilesLocations).exists()) return true; } } return find(verb, uri) != null; }
initialize(); Log.info(httpVerbColor(verbs) + AnsiColor.bold(" " + path) + Str.mul(" ", space), "setup", setupName, "!roles", opts.roles(), "transaction", tx, "mvc", opts.mvc(), "cacheTTL", opts.cacheTTL()); deregister(verb, path); register(verb, path, handler); } else { deregister(verb, path); notifyChanged();
match = routes.builtInResourcesHandler(); if (match != null) { matchingRoute = match.getRoute(); match = routes.findHandler(buf, isGet, verb, path); if (match != null) { matchingRoute = match.getRoute(); match = routes.staticResourcesHandler(); if (match != null) { matchingRoute = match.getRoute();
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; }
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; }
public Customization custom() { return routes.custom(); }
initialize(); Log.info(httpVerbColor(verbs) + AnsiColor.bold(" " + path) + Str.mul(" ", space), "setup", setupName, "!roles", opts.roles(), "transaction", tx, "mvc", opts.mvc(), "cacheTTL", opts.cacheTTL()); deregister(verb, path); register(verb, path, handler); } else { deregister(verb, path); notifyChanged();
match = routes.builtInResourcesHandler(); if (match != null) { matchingRoute = match.getRoute(); match = routes.findHandler(buf, isGet, verb, path); if (match != null) { matchingRoute = match.getRoute(); match = routes.staticResourcesHandler(); if (match != null) { matchingRoute = match.getRoute();
@Override public boolean hasRouteOrResource(HttpVerb verb, String uri) { if (verb == HttpVerb.GET) { String[] staticFilesLocations = custom().staticFilesPath(); if (U.notEmpty(staticFilesLocations)) { String filename = Str.triml(uri, '/'); if (filename.isEmpty()) filename = "index.html"; if (Res.from(filename, staticFilesLocations).exists()) return true; } } return find(verb, uri) != null; }
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(); }
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); } }
public Customization custom() { return routes.custom(); }
@Override public synchronized void on(String verb, String path, HttpHandler handler) { addOrRemove(true, verb, path, handler); }
@Override public Setup req(ReqHandler handler) { routes.addGenericHandler(new DelegatingParamsAwareReqHandler(http(), routes, opts(), handler)); autoActivate(); return this; }
@Override public Set<Route> allInternal() { return U.set(Do.findIn(all()).all(Route::isInternal)); }
DefaultSetup() { boolean onSameServer = Setup.appAndAdminOnSameServer(); Customization appCustomization = new Customization("main", My.custom(), Conf.ROOT); Customization adminCustomization = onSameServer ? appCustomization : new Customization("admin", My.custom(), Conf.ROOT); HttpRoutesImpl appRoutes = new HttpRoutesImpl("main", appCustomization); HttpRoutesImpl adminRoutes = onSameServer ? appRoutes : new HttpRoutesImpl("admin", adminCustomization); on = new Setup("main", MAIN_ZONE, IoC.defaultContext(), Setup.MAIN_CFG, appCustomization, appRoutes); admin = new Setup("admin", ADMIN_ZONE, IoC.defaultContext(), Setup.ADMIN_CFG, adminCustomization, adminRoutes); Setup.instances.add(on); Setup.instances.add(admin); initDefaults(); }
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; }