Table des matières
Play! framework
The High Velocity Web Framework For Java and Scala : www.playframework.org
C'est le Symfony (Php) de Java ! Ce framework n'est pas basé sur J2EE, il embarque directement sont serveur (Netty).
Play Framework is the High Velocity Web Framework for Java and Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource comsumption (CPU, memory, threads) for highly-scalable applications.
Play! utilise les frameworks
-
- Activator includes the sbt build tool, a quick-start GUI, and a catalog of template applications. Activator’s quick-start UI walks you through Typesafe Reactive Platform tutorials and is a hub for developers wanting to build Reactive applications. Common development patterns are presented through reusable templates that are linked to in-context tutorials
- sbt is an interactive build tool with customizable build tasks and an “execute-task-on-file-change” feature
- Akka pour son fonctionnement asynchrone.
- Ebean a Java ORM
Hébergement sur le web
what-cloud-platform-supports-playframework
- playframework-cloud by Clever Cloud
Community
doc
Présentations:
- Intro to Play Framework & Modern Java Web App Development by Josh Padnick, November 9, 2013
-
- Play Framework & SF Scala: Jim Brikman, Composable Applications in Play (2014) - Jim shows how to build an equivalent of Facebook's BigPipe in Play, where components of a page are delivered in parallel, decreasing latency dramatically, especially for mobile. (Async, Promise, Enumerator, Stream)
Tutoriels:
- Play2torial for Java by James Ward
- Anand Kumar Singh:
- Livre Play! par 3Monkeys (2013)
- mariussoutier / PlayBasics code for his tutorial series about Play Framework 2.x
Autres:
- Play-Bootstrap Play Framework library for Bootstrap
- PlayStartApp Starting APP Play Framework 2.x with Signup, Signin, Reset password, Change Email from Settings… Common uses cases
- Computer Database Java This is a classic Play CRUD application, backed by a JDBC database. It demonstrates DB access with Ebean, classic pagination, and integration with a CSS framework (Twitter Bootstrap).
- Play! Framework 2.0 + DataTables + Server-side processing with jquery.dataTables
- PublicPlay is yet another forum application built with the play framework
Encore:
- Auth (Authentication/Authorization):
- play-authenticate an extensible authentication plugin for Play! Framework 2 (Java)
- play-pac4j Oatuh 1 & 2, CAS, …
- SecureSocial for Play 2 (Scala & Java)
- play-silhouette (Scala only), Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, Credentials, Basic Authentication, Two Factor Authentication or custom authentication schemes. http://silhouette.mohiva.com
- Deadbolt, only Authorization, no Authentication
- play2-crud Simple CRUD & DAO implementation for play2.
- BigPipe streaming for the Play Framework, The ping-play project brings BigPipe streaming to the Play Framework. It includes tools for
- a) splitting your pages up into small “pagelets”, which makes it easier to maintain large websites, and
- b) streaming those pagelets down to the browser as soon as they are ready, which can significantly reduce page load time.
- Swagger API spec generator for Play, a library that generates swagger specs from route files and case class reflection, no code annotation needed
- Localization tool for play framework, this module gives you a tool for localizing your application
- Chat:
- SSE Chat, a Chat example app using Server Sent Events (SSE) plus REST calls
- play-aloha - Play! Framework example project with Aloha WYSIWYG HTML Editor
- play-thymeleaf: a Play framework 1.x module to use Thymeleaf as a template engine
Livres:
- Learning Play! Framework 2, Andy Petrella, March 2013
- Play Framework Essentials, Julien Richard-Foy, September 2014
En vrac
Activator & SBT
Typesafe Activator Templates: https://www.typesafe.com/activator/templates
Les dossiers pour le cache:
- Les packages chargés sont stockés dans ~/.ivy2/cache
- Les fichiers SBT sont stockés dans ~/.sbt
Après installation, création et run du projet essai01 (activator new essai01 play-java) le volume utilisé sur le disque est de 822,6 Mo:
- activator-dist-1.3.7: 7 657 éléments, 601,4 Mo
- .ivy2: 1 384 éléments, 120,8 Mo
- .sbt: 115 éléments, 90,6 Mo
- essai01 (play-java template): 323 éléments, 9,8 Mo
Un run ressemble à:
$ activator run [info] Loading project definition from /home/cyrille/Taf/CEFIM_2016_Java/essai01/project [info] Set current project to essai01 (in build file:/home/cyrille/Taf/CEFIM_2016_Java/essai01/) --- (Running the application, auto-reloading is enabled) --- [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...)
Puis à la visite de http://localhost:9000/:
[info] Compiling 6 Scala sources and 2 Java sources to /home/cyrille/Taf/CEFIM_2016_Java/essai01/target/scala-2.11/classes... [info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling... [info] Compilation completed in 6.524 s [info] - play.api.Play - Application started (Dev)
Run un sous-projet
Par exemple dans SecureSocial2 il y a les sous-projets javaDemo et scalaDemo. Pour les runner:
$ activator 'project javaDemo' run
Changer le port HTTP ou DEBUG
Run avec le serveur http écoutant le port 9001:
$ activator "~run 9001"
Pour changer le port du debuggage (JPDA Port)
$ activator -jvm-debug 9999 ~run
Websocket & Akka actor
Chat:
- Using WebSockets on Heroku with Java and the Play Framework - There are 3 important pieces to the interaction that takes place here: a controller method that returns a WebSocket object, a JavaScript method that opens that WebSocket, and an Akka actor that sends the payload across that WebSocket every second. Let’s explore each
- And the scalable version Writing Scalable WebSocket Applications on Heroku with Java and the Play Framework
- En Scala (pour inspiration)
- play-actor-room - A Room manager for Play Framework 2.2 based on Websockets & Bots
Map update:
Forms
- play-jqvalidate Client-side form validation based on your Play framework model annotations.
Accesing directly the request body:
package controllers; import play.mvc.*; import views.html.*; import java.util.Map; public class JavaPoster extends Controller { public static Result save() { final Map<String, String[]> values = request().body().asFormUrlEncoded(); final String name = values.get("java_name")[0]; final String surname = values.get("java_surname")[0]; return ok(index.render(String.format("You are %s, %s",surname, name))); } }
Or using a DynamicForm:
package controllers; import play.mvc.*; import views.html.*; import play.data.DynamicForm; public class JavaPoster extends Controller { public static Result save() { final DynamicForm form = form().bindFromRequest(); final String name = form.get("java_name"); final String surname = form.get("java_surname"); return ok(index.render(String.format("You are %s, %s",surname, name))); } }