Play Framework: Intro & High-Level Overview

42
Intro to Play Framework & Modern Java Web App Development Josh Padnick Desert Code Camp 2013.2 November 9, 2013

description

My presentation on Play Framework from Desert Code CAmp 2013

Transcript of Play Framework: Intro & High-Level Overview

Page 1: Play Framework: Intro & High-Level Overview

Intro to Play Framework & Modern Java Web App Development

Josh Padnick Desert Code Camp 2013.2 November 9, 2013

Page 2: Play Framework: Intro & High-Level Overview

Today’s Talk

• Java Web App Development Today

• Modern Web App Development

• Meet Play Framework

• Build Stuff!

Page 3: Play Framework: Intro & High-Level Overview

• 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

Page 4: Play Framework: Intro & High-Level Overview

Java Web App Development Today

Challenges����������� ������������������  of^

Page 5: Play Framework: Intro & High-Level Overview

Lots of Time Waiting for Server Redeploys…

SOURCE FOR INSIGHT: The Play Framework at LinkedIn: Productivity and Performance at Scale by Yevjeniy Brikman http://www.youtube.com/watch?v=8z3h4Uv9YbE !SOURCE FOR GRAPHIC: http://zeroturnaround.com/rebellabs/java-ee-productivity-report-2011/#redeploy_times

Page 6: Play Framework: Intro & High-Level Overview

Long, Ugly Error Messages

SOURCE: FOR INSIGHT: The Play Framework at LinkedIn: Productivity and Performance at Scale by Yevjeniy 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

Acegi

Spring MVC

Tomcat / JBoss

Page 7: Play Framework: Intro & High-Level Overview

<?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-name>mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- we'll use AnnotationConfigWebApplicationContext instead of the default XmlWebApplicationContext... --> <init-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> </init-param> ! <!-- ... and tell it which class contains the configuration --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>com.zt.helloWeb.init.WebappConfig</param-value> </init-param> ! <load-on-startup>1</load-on-startup> ! </servlet> ! <servlet-mapping> <servlet-name>mvc</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 by Yevjeniy Brikman http://www.youtube.com/watch?v=8z3h4Uv9YbE

Page 8: Play Framework: Intro & High-Level Overview

Bean Failuresorg.omg.CORBA.OBJECT_NOT_EXIST

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

X

Page 9: Play Framework: Intro & High-Level Overview

Clunky Road to RESTful URLs

WEB.XML <servlet-mapping> <servlet-name>springmvc</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().getPeople()); } ! @RequestMapping(value="{id}", method=RequestMethod.GET) public @ResponseBody String getPerson(@PathVariable String id) { return GsonFactory.getInstance().toJson(LookupDao.getInstance().getPerson(id)); } }

Page 10: Play Framework: Intro & High-Level Overview

A Lot of Complexity!

Page 11: Play Framework: Intro & High-Level Overview

I just want to write working software!

Page 12: Play Framework: Intro & High-Level Overview

Is this the architecture we would create today?

Page 13: Play Framework: Intro & High-Level Overview

The root of the problem

Impedance Mismatch between HTTP and Java EE!

Page 14: Play Framework: Intro & High-Level Overview

RESTful URLs vs. Java Servlets SpecImpedance Mismatch

Page 15: Play Framework: Intro & High-Level Overview

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

Page 16: Play Framework: Intro & High-Level Overview

Impedance Mismatch

Code & Refresh vs. WAR Deployment

Page 17: Play Framework: Intro & High-Level Overview

Modern Web App Development

Page 18: Play Framework: Intro & High-Level Overview

Buzzwords!• HTML5 & Javascript

• MVVM Frameworks

• Mobile

• NoSQL

• Real-Time

• Big Data

• Asynchronous

• Immutability

• Connected Devices

Page 19: Play Framework: Intro & High-Level Overview

Reactive Softwarehttp://www.ReactiveManifesto.org/

Page 20: Play Framework: Intro & High-Level Overview

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

Page 21: Play Framework: Intro & High-Level Overview

Reactive Software

SOURCE: http://www.ReactiveManifesto.org/

Page 22: Play Framework: Intro & High-Level Overview

Meet Play Framework

Page 23: Play Framework: Intro & High-Level Overview

Goal: Performance + Productivity

Performance

Prod

ucti

vity

SOURCE: http://typesafe.com/blog/webinar-a-java-developers-primer-to-the-typesafe-platform

Page 24: Play Framework: Intro & High-Level Overview

No More JEE Container

SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper

Page 25: Play Framework: Intro & High-Level Overview

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

Page 26: Play Framework: Intro & High-Level Overview

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

Page 27: Play Framework: Intro & High-Level Overview

Stateless and Built for Scale• Forces every aspect of your app to be stateless

• Non-Blocking I/O

• Well-suited for real-time

Page 28: Play Framework: Intro & High-Level Overview

What exactly is it, though?

SOURCE: Play for Java by Nicolas Leroux and Sietse de Kaper

Page 29: Play Framework: Intro & High-Level Overview

What exactly is it, though?Integrated HTTP Server

JBoss Netty (Non-Blocking IO)

Concurrent, Distributed, Fault-Tolerant Background Processing

Akka

Build System & Console

SBT

Java Virtual Machine

Template Engine, HTTP Request/Response Processing, Integrated Cache, RESTful Routing Engine, Asset Compilation,

Internationalization, Testing Tools Play Framework

eBean / Anorm BoneCP

H2 Database Lots of libraries…

Page 30: Play Framework: Intro & High-Level Overview

Of course, nothing’s perfect1. 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

Page 31: Play Framework: Intro & High-Level Overview

Let’s around!

Page 32: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 33: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 34: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 35: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 36: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 37: Play Framework: Intro & High-Level Overview

Intro Stuff1. Download and install

2. Play Console

3. Controllers

4. URL Routing

5. Templates

Page 38: Play Framework: Intro & High-Level Overview

Let’s Build Something in the Time Remaining

Page 39: Play Framework: Intro & High-Level Overview

So what did you like best today?• We’ll take some votes and show the results real-time

Page 40: Play Framework: Intro & High-Level Overview

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

Page 41: Play Framework: Intro & High-Level Overview

Check Out TypeSafe Activator

Page 42: Play Framework: Intro & High-Level Overview

Q&A