@Override public void onApplicationStart() { final Set<Class<?>> resourceClasses = ApiHelpInventory.getInstance().getRootResources(); if (resourceClasses.size() > 0) { Map<String, Route> router = new HashMap<>(); for(Route route : Router.routes){ router.put(route.action, route); } RouteWrapper routeWrapper = new RouteWrapper(router); RouteFactory.setRoute(routeWrapper); PlaySwaggerConfig playSwaggerConfig = new PlaySwaggerConfig(); PlayConfigFactory.setConfig(playSwaggerConfig); Router.prependRoute("GET", RESOURCES_JSON, "ApiHelpController.catchAll"); Logger.info("Swagger: Added ROOT help api @ " + RESOURCES_JSON); } }
ArrayList<String> getTransformedFilesRelativeURLs() throws IOException { ArrayList<JSSourceDatabaseEntry> all_entries = getDatabase().getSortedEntries(); ArrayList<String> results = new ArrayList<String>(all_entries.size() + 1); String url; if (reduced_declaration_file.exists()) { try { url = Router.reverse(VirtualFile.open(reduced_declaration_file)); results.add(url); } catch (NoRouteFoundException e) { throw new IOException("Play can't resolve route for " + reduced_declaration_file.getPath()); } } File transformed_file; for (int pos = 0; pos < all_entries.size(); pos++) { transformed_file = all_entries.get(pos).computeTransformedFilepath(module_path, transformed_directory); if (transformed_file.exists() == false) { Loggers.Play_JSSource.warn("A transformed file don't exists: " + transformed_file); continue; } url = Router.reverse(VirtualFile.open(transformed_file)); results.add(url); } return results; }
/** * @param hashtag_to_add (should be start with #) */ void pack(String hashtag_to_add) { if (url != null) { return; } if (hashtag_to_add == null) { hashtag_to_add = ""; } try { if (controler_args.isEmpty()) { url = Router.reverse(controler_name).url + hashtag_to_add; } else { url = Router.reverse(controler_name, controler_args).url + hashtag_to_add; } } catch (NoRouteFoundException e) { Loggers.Play.error("Can't found route for " + controler_name); return; } }
@Override public void onApplicationStart() { genericRouteIndex = Router.routes.size(); for (int i = 0; i < Router.routes.size(); i++) { Router.Route route = Router.routes.get(i); if (route.action.startsWith("{controller}")) { genericRouteIndex = i; break; } } addWebRoutes(WebPage.ROOT.children()); for (WebPage page : WebPage.all()) { String alias = page.metadata.getProperty("alias"); if (isNotEmpty(alias)) { if (!alias.startsWith("/")) alias = "/" + alias; Router.appendRoute("GET", alias + "/?", "Web." + WEB_REDIRECT_ALIAS_METHOD, "{path:'" + page.path + "'}", null, null, 0); } if ("news".equals(page.metadata.getProperty("template"))) { WebPage.News.pathPrefixes.add(page.path.replaceFirst("/$", "")); Router.addRoute(genericRouteIndex, "GET", page.path + ".*", "Web." + WEB_NEWS_METHOD, null); } } lastModified = WebPage.ROOT.dir.lastModified(); }
@Before public void setUp() { Play.configuration.clear(); Http.Request.current.set(request = newHttpRequest()); Http.Response.current.set(response = new Http.Response()); Scope.Session.current.set(new Scope.Session()); Scope.RenderArgs.current.set(new Scope.RenderArgs()); request.path = "/"; Play.langs.add("en"); Play.langs.add("ru"); Play.mode = DEV; Router.routes.clear(); plugin = new WebContentPlugin(); pages = asList(forPath("/en/marketing/"), forPath("/ru/marketing/")); resetWebCacheSetting(); }
@Override public void onRoutesLoaded() { Router.addRoute("GET", "/@tests", "TestRunner.index"); Router.addRoute("GET", "/@tests.list", "TestRunner.list"); Router.addRoute("GET", "/@tests/{<.*>test}", "TestRunner.run"); Router.addRoute("POST", "/@tests/{<.*>test}", "TestRunner.saveResult"); Router.addRoute("GET", "/@tests/emails", "TestRunner.mockEmail"); Router.addRoute("GET", "/@tests/cache", "TestRunner.cacheEntry"); }
@Override public void onRoutesLoaded() { if (Play.configuration.contains("play.search.password" ) || Play.mode == Play.Mode.DEV) { Router.addRoute("GET", "/@search/?", "modules.search.Administration.index"); Router.addRoute("GET", "/@search/optimize/{name}", "modules.search.Administration.optimize"); Router.addRoute("GET", "/@search/reindex/{name}", "modules.search.Administration.reindex"); Router.addRoute("GET", "/@search/reopen/{name}", "modules.search.Administration.reopen"); } }
/** * Stop the application */ public static synchronized void stop() { if (started) { Logger.trace("Stopping the play application"); pluginCollection.onApplicationStop(); started = false; Cache.stop(); Router.lastLoading = 0L; } }
private static synchronized void loadRouter(String contextPath) { // Reload the rules, but this time with the context. Not really efficient through... // Servlet 2.4 does not allow you to get the context path from the servletcontext... if (routerInitializedWithContext) return; Play.ctxPath = contextPath; Router.load(contextPath); routerInitializedWithContext = true; }
public String getConcatedFileRelativeURL() throws IOException { CopyMove.checkExistsCanRead(allfiles_concated_file); HashMap<String, Object> args = new HashMap<String, Object>(2); args.put("name", allfiles_concated_file.getName()); args.put("suffix_date", allfiles_concated_file.lastModified() / 1000); return Router.reverse(AsyncJavascript.class.getName() + "." + "JavascriptRessource", args).url; }
/** * Not need to pack. */ void setStaticFile(String relative_file) { try { url = Router.reverse(VirtualFile.fromRelativePath(relative_file)); } catch (NoRouteFoundException e) { Loggers.Play.error("Can't found route for " + relative_file); url = "/"; } }
void addWebRoutes(List<WebPage> pages) { for (WebPage page : pages) { String path = page.path; if (path.endsWith("/")) path = substring(path, 0, -1); Router.addRoute(genericRouteIndex, "GET", path + "/?.*", "Web." + WEB_CONTENT_METHOD, null); if (cacheEnabled()) // cache top-level pages on production Router.addRoute(genericRouteIndex, "GET", path + "/", "Web." + WEB_CACHED_CONTENT_METHOD, null); } }
@Override public void onRoutesLoaded() { Router.prependRoute("GET", "/@accesslog", "AccessLogs.index"); Router.prependRoute("WS", "/@accesslog/logs", "AccessLogWebsockets.logs"); }
@Override public void onRoutesLoaded() { Router.addRoute("GET", "/@profiler/results", "ProfilerActions.results"); Router.addRoute("GET", "/@profiler/public/", "staticDir:public/"); }
public Object getListAction() { return Router.reverse(controllerClass.getName().replace("$", "") + ".list"); }
public Object getBlankAction() { return Router.reverse(controllerClass.getName().replace("$", "") + ".blank"); }
private String __reverseWithCheck(String action, boolean absolute) { return Router.reverseWithCheck(action, Play.getVirtualFile(action), absolute); }
public static Request parseRequest(HttpServletRequest httpServletRequest) throws Exception { URI uri = new URI(httpServletRequest.getRequestURI()); String method = httpServletRequest.getMethod().intern(); String path = uri.getPath(); String querystring = httpServletRequest.getQueryString() == null ? "" : httpServletRequest.getQueryString(); if (Logger.isTraceEnabled()) { Logger.trace("httpServletRequest.getContextPath(): " + httpServletRequest.getContextPath()); Logger.trace("request.path: " + path + ", request.querystring: " + querystring); } String contentType = null; if (httpServletRequest.getHeader("Content-Type") != null) { contentType = httpServletRequest.getHeader("Content-Type").split(";")[0].trim().toLowerCase().intern(); } else { contentType = "text/html".intern(); } if (httpServletRequest.getHeader("X-HTTP-Method-Override") != null) { method = httpServletRequest.getHeader("X-HTTP-Method-Override").intern(); } InputStream body = httpServletRequest.getInputStream(); boolean secure = httpServletRequest.isSecure(); String url = uri.toString() + (httpServletRequest.getQueryString() == null ? "" : "?" + httpServletRequest.getQueryString()); String host = httpServletRequest.getHeader("host"); int port = 0; String domain = null; if (host.contains(":")) { port = Integer.parseInt(host.split(":")[1]); domain = host.split(":")[0]; } else { port = 80; domain = host; } String remoteAddress = httpServletRequest.getRemoteAddr(); boolean isLoopback = host.matches("^127\\.0\\.0\\.1:?[0-9]*$"); final Request request = Request.createRequest( remoteAddress, method, path, querystring, contentType, body, url, host, isLoopback, port, domain, secure, getHeaders(httpServletRequest), getCookies(httpServletRequest)); Request.current.set(request); Router.routeOnlyStatic(request); return request; }
public void onRequestRouting(Router.Route route){ for (PlayPlugin plugin : getEnabledPlugins()) { plugin.onRequestRouting(route); } }
private void assertCached(String url) { assertEquals("Web.serveContentCached", Router.route("GET", url).get("action")); }
private void assertNonCached(String url) { assertEquals("Web.serveContent", Router.route("GET", url).get("action")); }