play2 java

26
2 Java @basav

Upload: xp-conference-india

Post on 20-Jan-2017

301 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Play2 Java

2 Java

@basav

Page 2: Play2 Java

Agenda

• Introduction to Play 2 Java framework

• Live Coding

• Deployment to Cloud

• QA

Page 3: Play2 Java

Who am I?

Software ArchitectEntrepreneur

Web 2.0 JavaScript

Page 4: Play2 Java

WE ARE STARTING A NEW PROJECT !YAY!

Page 5: Play2 Java

I AM READY TO CODE IT UP!!

Page 6: Play2 Java

STACK? What about POLYGLOT? DILEMMA !!!

Page 7: Play2 Java

SON !! TRUST ME!JAVA IS THE SAFE CHOICE! Many come back (think

Twitter)

But there is a curse…

Page 8: Play2 Java

The risk of dying - waiting for server start, complex tooling, redeployment, maintaining XML, HTTPSession ..etc

Page 9: Play2 Java

CAN YOU HAVE YOUR CAKE AND EAT IT TOO?

Page 10: Play2 Java

YES !!

Page 11: Play2 Java

Who is using Play?

Page 12: Play2 Java

What is Play?

• Easy to build web applications with Java & Scala.

• Based on a lightweight, stateless, web-friendly architecture.

• Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications

Page 13: Play2 Java

History• Play 1 Created By

Guillaume Bort at Zengularity SA in 2007

• Play 2 release in 2012 by Typesafe (rewrite using Scala)

• Part of Typesafe Activator

Page 14: Play2 Java

Philosophy• Build for Asynchronous

Programming

• Focused on Type Safety

• Native support for Java and Scala

• Powerful Build System

• Datastore and Model Integration

Page 15: Play2 Java

Full Stack Framework• HTTP Server (Netty)

• Routing

• Body Parsers

• Action composition

• Security

• Caching

• Database

• i18n

• Dependency Injection

• Template engine (HTML, XML...)

• HTTP forms (bindings, validation)

• JSON, XML

• Javascript Closure Compiler

• Coffeescript, Less

Page 16: Play2 Java

Twelve-Factor Manifesto1. Codebase

2. Dependencies

3. Config

4. Backing Services

5. Build, release, run

6. Processes

7. Port binding

8. Concurrency

9. Disposability

10. Dev/prod parity

11. Logs

12. Admin processes

http://12factor.net/

Page 17: Play2 Java

Lets CODE

Page 18: Play2 Java

Pre-Requisites

• Download (typesafe-activator - Play 2.4.2) from

• https://playframework.com/download

• Add activator your PATH

• activator new

Page 19: Play2 Java

IDE & JDK Support

• Play 2.4.2 is only supported JDK 8 onwards

• IntelliJ IDE

• Import as an SBT project

• Eclipse

• activator eclipse

Page 20: Play2 Java

Basic Demo

Page 21: Play2 Java

Whats the Usecase?

User Service

GET /github/:username

User Controller

GITHUB

User Repository

GET /users/list/

https://api.github.com

create(User)update(User)getAllUsers

allUsers():List<User>

Route TestFunctional Test

Integration TestUnit Test

GithubService

findUser():User

Unit Test

save(User)

Page 22: Play2 Java

Coding..

Page 23: Play2 Java

Heroku Deployment• Install the Heroku Toolbelt

• Write a Procfile

• $ git init

• $ git add .

• $ git commit -m “init"

• heroku create

• git push heroku master

Page 24: Play2 Java

Code on Github

https://github.com/basav/MyApp

Page 26: Play2 Java

Thank You!

@basav