KEMBAR78
Play Framework: Intro & High-Level Overview | PDF
Intro to Play Framework &	

Modern Java Web App Development
Josh Padnick	

Desert Code Camp 2013.2	

November 9, 2013
Today’sTalk
• Java Web App DevelopmentToday	

• Modern Web App Development	

• Meet Play Framework	

• Build Stuff!
• Founder & Chief Innovation Officer at Omedix	

• 10+ years of web app development	

• Special interest in scalable, enterprise, web-based
applications using Java & open source
Josh
 Padnick
Java Web App 	

DevelopmentToday
Challenges
 of^
Lots ofTime Waiting for Server Redeploys…
SOURCE FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman

http://www.youtube.com/watch?v=8z3h4Uv9YbE	

!
SOURCE FOR GRAPHIC: http://zeroturnaround.com/rebellabs/java-ee-productivity-report-2011/#redeploy_times
Long, Ugly Error Messages
SOURCE: FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman

http://www.youtube.com/watch?v=8z3h4Uv9YbE	

!
SOURCE FOR GRAPHIC: http://ptrthomas.wordpress.com/2006/06/06/java-call-stack-from-http-upto-jdbc-as-a-picture/	

MVC Action
AOP TX Proxy
Business Logic
DAO
Spring-Hibernate
Hibernate
JDBC
Spring WebFlow
Spring MVC
?xml version=1.0 encoding=UTF-8?
web-app version=2.5 xmlns=http://java.sun.com/xml/ns/javaee xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
!
servlet
servlet-namemvc/servlet-name
servlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class
!-- we'll use AnnotationConfigWebApplicationContext instead of the default XmlWebApplicationContext... --
init-param
param-namecontextClass/param-name
param-valueorg.springframework.web.context.support.AnnotationConfigWebApplicationContext/param-value
/init-param
!
!-- ... and tell it which class contains the configuration --
init-param
param-namecontextConfigLocation/param-name
param-valuecom.zt.helloWeb.init.WebappConfig/param-value
/init-param
!
load-on-startup1/load-on-startup
!
/servlet
!
servlet-mapping
servlet-namemvc/servlet-name
url-pattern//url-pattern
/servlet-mapping
!
welcome-file-list
welcome-file//welcome-file
/welcome-file-list
!
/web-app
DefaultServletHandler
Crazy XML Configuration
SOURCE FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman

http://www.youtube.com/watch?v=8z3h4Uv9YbE
Bean Failures
org.omg.CORBA.OBJECT_NOT_EXIST
SOURCE FOR GRAPHIC: Beginning Java EE 6 Platform with Glassfish 3 by Antonio Goncalves, Page 5.
X
Clunky Road to	

RESTful URLs
WEB.XML
servlet-mapping
servlet-namespringmvc/servlet-name
url-pattern/rest/*/url-pattern
/servlet-mapping
!
CONTROLLER.JAVA
@Controller
@RequestMapping(/people)
public class PeopleController {
!
@RequestMapping(“entrypoint/{collectionName}”, method=RequestMethod.GET)
public @ResponseBody String getPeople() {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getP
}
!
@RequestMapping(value={id}, method=RequestMethod.GET)
public @ResponseBody String getPerson(@PathVariable String id) {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getP
}
}
A Lot of Complexity!
I just want to write working software!
Is this the architecture we would create today?
The root of the problem
Impedance Mismatch between 	

HTTP and Java EE!
RESTful URLs vs. Java Servlets Spec
Impedance Mismatch
Stateless HTTP vs. Stateful EJBs
SOURCE: http://cscie12.dce.harvard.edu/lecture_notes/2011/20110504/handout.html 	

SOURCE: Beginning Java EE 6 Platform with Glassfish 3 by Antonio Goncalves, Page 206.	

Impedance Mismatch
Impedance Mismatch
Code  Refresh vs. WAR Deployment
Modern Web App Development
Buzzwords!
• HTML5  Javascript
• MVVM Frameworks
• Mobile
• NoSQL
• Real-Time
• Big Data
• Asynchronous
• Immutability
• Connected Devices
Reactive Software
http://www.ReactiveManifesto.org/
The Reactive Manifesto
“Application requirements have changed dramatically in recent years. Both
from a runtime environment perspective, with multicore and cloud computing
architectures nowadays being the norm, as well as from a user requirements
perspective, with tighter SLAs in terms of lower latency, higher throughput,
availability and close to linear scalability.This all demands writing applications in
a fundamentally different way than what most programmers are used to.”
SOURCE: http://typesafe.com/blog/why_do_we_need_a_reactive_manifesto
Jonas Bonér
Reactive Software
SOURCE: http://www.ReactiveManifesto.org/
Meet Play Framework
Goal: Performance + Productivity
Performance
Productivity
SOURCE: http://typesafe.com/blog/webinar-a-java-developers-primer-to-the-typesafe-platform
No More JEE Container
SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper
Focused on Developer Productivity
• Live code changes when you refresh the browser	

• More friendly error messages directly in browser	

• Type safety in the templates	

• Cool console  build tools
Designed for the Modern Web
• RESTful by default	

• Auto-compile LESS and CoffeeScript files	

• JSON is a first-class citizen	

• Websockets, other HTTP Streaming Support
Stateless and Built for Scale
• Forces every aspect of your app to be stateless	

• Non-Blocking I/O	

• Well-suited for real-time
What exactly is it, though?
SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper
What exactly is it, though?
Integrated HTTP Server	

JBoss Netty (Non-Blocking IO)
Concurrent, Distributed, Fault-Tolerant 	

Background Processing	

Akka
Build System 	

Console	

SBT
JavaVirtual Machine
Template Engine, HTTP Request/Response Processing, Integrated
Cache, RESTful Routing Engine,Asset Compilation,
Internationalization,TestingTools	

Play Framework
eBean / Anorm
BoneCP
H2 Database
Lots of libraries…
Of course, nothing’s perfect
1. You can mostly avoid Scala, but not completely

(of course, Scala itself is pretty cool)	

2. For advanced build logic, SBT has a steep learning curve	

3. Template system works well, but sometimes the functional
paradigm can feel awkward
Let’s around!
Intro Stuff
1. Download and install	

2. Play Console	

3. Controllers	

4. URL Routing	

5. Templates
Intro Stuff
1. Download and install
2. Play Console	

3. Controllers	

4. URL Routing	

5. Templates
Intro Stuff
1. Download and install	

2. Play Console
3. Controllers	

4. URL Routing	

5. Templates
Intro Stuff
1. Download and install	

2. Play Console	

3. Controllers
4. URL Routing	

5. Templates
Intro Stuff
1. Download and install	

2. Play Console	

3. Controllers	

4. URL Routing
5. Templates
Intro Stuff
1. Download and install	

2. Play Console	

3. Controllers	

4. URL Routing	

5. Templates
Let’s Build Something	

in theTime Remaining
So what did you like best today?
• We’ll take some votes and show the results real-time
Learning Play Framework
• I preferred the books to the documentation	

• For official documentation, best formatting is on
playframework.com. Latest content is on github

(https://github.com/playframework/playframework/tree/master/documentation/manual)	

• Community itself is pretty great	

• Google Group is great 	

• Lots of questions on Stack Overflow

Play Framework: Intro & High-Level Overview

  • 1.
    Intro to PlayFramework & Modern Java Web App Development Josh Padnick Desert Code Camp 2013.2 November 9, 2013
  • 2.
    Today’sTalk • Java WebApp DevelopmentToday • Modern Web App Development • Meet Play Framework • Build Stuff!
  • 3.
    • Founder &Chief Innovation Officer at Omedix • 10+ years of web app development • Special interest in scalable, enterprise, web-based applications using Java & open source Josh
  • 4.
  • 5.
    Java Web App DevelopmentToday Challenges
  • 6.
  • 7.
    Lots ofTime Waitingfor Server Redeploys… SOURCE FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman
 http://www.youtube.com/watch?v=8z3h4Uv9YbE ! SOURCE FOR GRAPHIC: http://zeroturnaround.com/rebellabs/java-ee-productivity-report-2011/#redeploy_times
  • 8.
    Long, Ugly ErrorMessages SOURCE: FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman
 http://www.youtube.com/watch?v=8z3h4Uv9YbE ! SOURCE FOR GRAPHIC: http://ptrthomas.wordpress.com/2006/06/06/java-call-stack-from-http-upto-jdbc-as-a-picture/ MVC Action AOP TX Proxy Business Logic DAO Spring-Hibernate Hibernate JDBC Spring WebFlow Spring MVC
  • 9.
    ?xml version=1.0 encoding=UTF-8? web-appversion=2.5 xmlns=http://java.sun.com/xml/ns/javaee xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ! servlet servlet-namemvc/servlet-name servlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class !-- we'll use AnnotationConfigWebApplicationContext instead of the default XmlWebApplicationContext... -- init-param param-namecontextClass/param-name param-valueorg.springframework.web.context.support.AnnotationConfigWebApplicationContext/param-value /init-param ! !-- ... and tell it which class contains the configuration -- init-param param-namecontextConfigLocation/param-name param-valuecom.zt.helloWeb.init.WebappConfig/param-value /init-param ! load-on-startup1/load-on-startup ! /servlet ! servlet-mapping servlet-namemvc/servlet-name url-pattern//url-pattern /servlet-mapping ! welcome-file-list welcome-file//welcome-file /welcome-file-list ! /web-app DefaultServletHandler Crazy XML Configuration SOURCE FOR INSIGHT:The Play Framework at LinkedIn: Productivity and Performance at Scale byYevjeniy Brikman
 http://www.youtube.com/watch?v=8z3h4Uv9YbE
  • 10.
    Bean Failures org.omg.CORBA.OBJECT_NOT_EXIST SOURCE FORGRAPHIC: Beginning Java EE 6 Platform with Glassfish 3 by Antonio Goncalves, Page 5. X
  • 11.
    Clunky Road to RESTfulURLs WEB.XML servlet-mapping servlet-namespringmvc/servlet-name url-pattern/rest/*/url-pattern /servlet-mapping ! CONTROLLER.JAVA @Controller @RequestMapping(/people) public class PeopleController { ! @RequestMapping(“entrypoint/{collectionName}”, method=RequestMethod.GET) public @ResponseBody String getPeople() { return GsonFactory.getInstance().toJson(LookupDao.getInstance().getP } ! @RequestMapping(value={id}, method=RequestMethod.GET) public @ResponseBody String getPerson(@PathVariable String id) { return GsonFactory.getInstance().toJson(LookupDao.getInstance().getP } }
  • 12.
    A Lot ofComplexity!
  • 13.
    I just wantto write working software!
  • 14.
    Is this thearchitecture we would create today?
  • 15.
    The root ofthe problem Impedance Mismatch between HTTP and Java EE!
  • 16.
    RESTful URLs vs.Java Servlets Spec Impedance Mismatch
  • 17.
    Stateless HTTP vs.Stateful EJBs SOURCE: http://cscie12.dce.harvard.edu/lecture_notes/2011/20110504/handout.html SOURCE: Beginning Java EE 6 Platform with Glassfish 3 by Antonio Goncalves, Page 206. Impedance Mismatch
  • 18.
    Impedance Mismatch Code Refresh vs. WAR Deployment
  • 19.
    Modern Web AppDevelopment
  • 20.
    Buzzwords! • HTML5 Javascript • MVVM Frameworks • Mobile • NoSQL • Real-Time • Big Data • Asynchronous • Immutability • Connected Devices
  • 21.
  • 22.
    The Reactive Manifesto “Applicationrequirements have changed dramatically in recent years. Both from a runtime environment perspective, with multicore and cloud computing architectures nowadays being the norm, as well as from a user requirements perspective, with tighter SLAs in terms of lower latency, higher throughput, availability and close to linear scalability.This all demands writing applications in a fundamentally different way than what most programmers are used to.” SOURCE: http://typesafe.com/blog/why_do_we_need_a_reactive_manifesto Jonas Bonér
  • 23.
  • 24.
  • 25.
    Goal: Performance +Productivity Performance Productivity SOURCE: http://typesafe.com/blog/webinar-a-java-developers-primer-to-the-typesafe-platform
  • 26.
    No More JEEContainer SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper
  • 27.
    Focused on DeveloperProductivity • Live code changes when you refresh the browser • More friendly error messages directly in browser • Type safety in the templates • Cool console build tools
  • 28.
    Designed for theModern Web • RESTful by default • Auto-compile LESS and CoffeeScript files • JSON is a first-class citizen • Websockets, other HTTP Streaming Support
  • 29.
    Stateless and Builtfor Scale • Forces every aspect of your app to be stateless • Non-Blocking I/O • Well-suited for real-time
  • 30.
    What exactly isit, though? SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper
  • 31.
    What exactly isit, though? Integrated HTTP Server JBoss Netty (Non-Blocking IO) Concurrent, Distributed, Fault-Tolerant Background Processing Akka Build System Console SBT JavaVirtual Machine Template Engine, HTTP Request/Response Processing, Integrated Cache, RESTful Routing Engine,Asset Compilation, Internationalization,TestingTools Play Framework eBean / Anorm BoneCP H2 Database Lots of libraries…
  • 32.
    Of course, nothing’sperfect 1. You can mostly avoid Scala, but not completely
 (of course, Scala itself is pretty cool) 2. For advanced build logic, SBT has a steep learning curve 3. Template system works well, but sometimes the functional paradigm can feel awkward
  • 33.
  • 34.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 35.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 36.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 37.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 38.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 39.
    Intro Stuff 1. Downloadand install 2. Play Console 3. Controllers 4. URL Routing 5. Templates
  • 40.
    Let’s Build Something intheTime Remaining
  • 41.
    So what didyou like best today? • We’ll take some votes and show the results real-time
  • 42.
    Learning Play Framework •I preferred the books to the documentation • For official documentation, best formatting is on playframework.com. Latest content is on github
 (https://github.com/playframework/playframework/tree/master/documentation/manual) • Community itself is pretty great • Google Group is great • Lots of questions on Stack Overflow
  • 43.
  • 44.