For this recipe, we will explore how Play Framework provides the building blocks for creating reusable, custom actions.
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled.Modify
foo_java/app/controllers/Application.java
by adding the following action:@With(AuthAction.class) public static Result dashboard() { return ok("User dashboard"); } public static Result login() { return ok("Please login"); }
Add our new action class to
foo_java/app/controllers/AuthAction.java
as well:package controllers; import play.*; import play.mvc.*; import play.libs.*; import play.libs.F.*; public class AuthAction extends play.mvc.Action.Simple { public F.Promise<Result> call(Http.Context ctx) throws Throwable { Http.Cookie authCookie = ctx.request().cookie("auth"); if (authCookie != null) { Logger.info("Cookie: " + authCookie); return delegate...