default Route addResourceRoute(ResourceHandler resourceHandler) { Route route = Route.GET(resourceHandler.getUriPattern(), resourceHandler); addRoute(route); return route; }
/** * Add a route that serves webjars (http://www.webjars.org/) resources. */ default Route addWebjarsResourceRoute(String urlPath) { return addResourceRoute(new WebjarsResourceHandler(urlPath)); }
/** * Add a route that serves resources from the "public" directory within your classpath. */ default Route addPublicResourceRoute(String urlPath) { return addResourceRoute(new PublicResourceHandler(urlPath)); }
public static Response get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getResponse() : null; }
public static Request get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getRequest() : null; }
/** * Returns not null only in the context of the web layer (on a HTTP request). * It cannot be useful in a service (server side business layer). * For example if want to have access to PippoSettings from a service you must to inject PippoSettings * in that service and not to use Application.get().getPippoSettings(). * * @return The application instance or null */ public static Application get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getApplication() : null; }
@Override public String uriPatternFor(Class<? extends ResourceHandler> resourceHandlerClass) { Route route = getRoute(resourceHandlerClass); return (route != null) ? route.getUriPattern() : null; }
/** * Create a {@code HEAD} route. * * @param uriPattern * @param routeHandler * @return */ public static Route HEAD(String uriPattern, RouteHandler routeHandler) { return new Route(HttpConstants.Method.HEAD, uriPattern, routeHandler); }
/** * Add a route that serves resources from a directory(file system). */ default Route addFileResourceRoute(String urlPath, File directory) { return addResourceRoute(new FileResourceHandler(urlPath, directory)); }
/** * Add a route that serves resources from classpath. */ default Route addClasspathResourceRoute(String urlPath, String resourceBasePath) { return addResourceRoute(new ClasspathResourceHandler(urlPath, resourceBasePath)); }
@Override public void onPreDispatch(final Request request, final Response response) { notify(listener -> listener.onPreDispatch(request, response)); }
@Override public void onPostDispatch(final Request request, final Response response) { notify(listener -> listener.onPostDispatch(request, response)); }