@Override public Object handle(Request request, Response response) throws Exception { return route.handle(request, response); } };
private static void addRoute(String httpMethod, Route route) { init(); routeMatcher.parseValidateAddRoute( httpMethod + " '" + route.getPath() + "'", route.getAcceptType(), route); }
@Override public Object handle(Request request, Response response) throws Exception { return route.handle(request, response); } };
/** * Gets the custom error page for a given status code. If the custom * error page is a route, the output of its handle method is returned. * If the custom error page is a String, it is returned as an Object. * @param status * @param request * @param response * @return Object representing the custom error page */ public static Object getFor(int status, Request request, Response response) { Object customRenderer = CustomErrorPages.getInstance().customPages.get(status); Object customPage = CustomErrorPages.getInstance().getDefaultFor(status); if (customRenderer instanceof String) { customPage = customRenderer; } else if (customRenderer instanceof Route) { try { customPage = ((Route) customRenderer).handle(request, response); } catch (Exception e) { // The custom page renderer is causing an internal server error. Log exception as a warning and use default page instead LOG.warn("Custom error page handler for status code {} has thrown an exception: {}. Using default page instead.", status, e.getMessage()); } } return customPage; }
@Override public Object handle(Request request, Response response) throws Exception { return route.handle(request, response); } };
@Override public Object handle(Request request, Response response) throws Exception { return route.handle(request, response); } };
public static Route text(Route route) { return (req, res) -> { res.header("Content-Type", "text/plain"); Object result = route.handle(req, res); return result instanceof String ? result : result.toString(); }; }
@SuppressWarnings("Duplicates") public String process(Request request, Response response) throws Exception { for (Require require : requires) { if (!require.verify(request)) { response.status(400); JsonObject error = new JsonObject(); error.addProperty("error", String.format("Require for '%s' failed!", require.getName())); return error.toString(); } } return FlareBot.GSON.toJson(consumer.handle(request, response)); } }
@SuppressWarnings("Duplicates") public String process(Request request, Response response) throws Exception { for (Require require : requires) { if (!require.verify(request)) { response.status(400); JsonObject error = new JsonObject(); error.addProperty("error", String.format("Require for '%s' failed!", require.getName())); return error.toString(); } } return FlareBot.GSON.toJson(consumer.handle(request, response)); } }
public static Route promethize(Route route){ return (req,res) ->{ res.header("Content-Type", "text/plain"); Object result = route.handle(req,res); return result instanceof MetricRegistry ? parse(result) : null; }; }
public static Route json(Route route) { return (req, res) -> { res.header("Content-Type", "application/json"); return json.render(route.handle(req, res)); }; }
/** * Gets the custom error page for a given status code. If the custom * error page is a route, the output of its handle method is returned. * If the custom error page is a String, it is returned as an Object. * @param status * @param request * @param response * @return Object representing the custom error page */ public static Object getFor(int status, Request request, Response response) { Object customRenderer = CustomErrorPages.getInstance().customPages.get(status); Object customPage = CustomErrorPages.getInstance().getDefaultFor(status); if (customRenderer instanceof String) { customPage = customRenderer; } else if (customRenderer instanceof Route) { try { customPage = ((Route) customRenderer).handle(request, response); } catch (Exception e) { // The custom page renderer is causing an internal server error. Log exception as a warning and use default page instead LOG.warn("Custom error page handler for status code {} has thrown an exception: {}. Using default page instead.", status, e.getMessage()); } } return customPage; }