BAEL-3059: Update Play Framework (#7674)
* Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of the tutorial for Introduction to Play Framework. * Updated code for Play Routing to 2.7.3 * Updated code for Play Routing to 2.7.3 * Initial Commit * Added request object to create end point * Finished implementing student-api * Finished implementing student-api * Implementation of the tutorial for Introduction to Play Framework. * Updated test names * Removed Lombok dependency * Corrected isSuccessful spelling and removed the +1 on student ids
This commit is contained in:
committed by
KevinGilmore
parent
0d648321dc
commit
5bce8b22a1
@@ -1,14 +1,25 @@
|
||||
package controllers;
|
||||
|
||||
import play.libs.concurrent.HttpExecutionContext;
|
||||
import play.mvc.*;
|
||||
import play.twirl.api.Html;
|
||||
|
||||
import views.html.*;
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
import static java.util.concurrent.CompletableFuture.supplyAsync;
|
||||
|
||||
/**
|
||||
* This controller contains an action to handle HTTP requests
|
||||
* to the application's home page.
|
||||
*/
|
||||
public class HomeController extends Controller {
|
||||
private HttpExecutionContext ec;
|
||||
|
||||
@Inject
|
||||
public HomeController(HttpExecutionContext ec) {
|
||||
this.ec = ec;
|
||||
}
|
||||
|
||||
/**
|
||||
* An action that renders an HTML page with a welcome message.
|
||||
@@ -17,7 +28,41 @@ public class HomeController extends Controller {
|
||||
* <code>GET</code> request with a path of <code>/</code>.
|
||||
*/
|
||||
public Result index() {
|
||||
return ok(index.render("Your new application is ready."));
|
||||
return ok(views.html.index.render());
|
||||
}
|
||||
|
||||
public Result applyHtml() {
|
||||
return ok(Html.apply("<h1>This text will appear as a heading 1</h1>"));
|
||||
}
|
||||
|
||||
public Result badRequestPage() {
|
||||
return badRequest("Your request data has issues.");
|
||||
}
|
||||
|
||||
public Result notFoundPage() {
|
||||
return notFound("Could not find the page you requested.");
|
||||
}
|
||||
|
||||
public Result customContentType() {
|
||||
return ok("This is some text content").as("text/html");
|
||||
}
|
||||
|
||||
public CompletionStage<Result> asyncOperation() {
|
||||
return supplyAsync(() -> {
|
||||
return longRunningTask();
|
||||
}, ec.current())
|
||||
.thenApplyAsync(s -> {
|
||||
return ok("Got result -> " + s);
|
||||
}, ec.current());
|
||||
}
|
||||
|
||||
private String longRunningTask() {
|
||||
return "Long running task has completed";
|
||||
}
|
||||
|
||||
public Result setHeaders() {
|
||||
return ok("This is some text content")
|
||||
.as("text/html")
|
||||
.withHeader("Header-Key", "Some value");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user