eXo Platform SEA - Play Framework Introduction

Embed Size (px)

Citation preview

  • 1. Vu Viet Phuong - PortalTeam Play Framework Introduction

2.

  • Introduce key features of Play! framework
  • Some great new ideas for Web Framework

Objective 3.

  • Play! Framework Introduction

Subject

  • Demo sample applications

4. Play! Framework Introduction 5.

  • Simple stateless MVC architecture
  • No configuration: download, unpack and develop
  • Integrated unit testing:
  • JUnit and Selenium support is included in the core
  • Elegant API: rarely will a developer need to import any third party library - Play comes with all the typical stuff built-in

Major differences 6.

  • Uses Java but tries to push all the good things
    • from the frameworks based on scripting languages
  • Get the best of the Java platform without
    • getting the pain of traditional Java web development

Advantage 7.

  • Very good documented and easy to use product
  • - JavaDoc

8. - User guide 9. - Sample apps

  • Full-stack application framework
  • Introduce a completely new way to develop web apps

Advantage 10.

  • Database support : JDBC,object-relational mapping using Hibernate (with the JPA API).
  • Integrated cache support with easy use of the distributed memcached system if needed
  • Straightforward web services consumption either in JSON or XML

Full-stack application framework 11.

  • OpenID support for distributed authentication
  • Ready to be deployed anywhere (application server, Google App Engine, Cloud, etc)
  • Image manipulation API

Full-stack application framework 12.

  • Build and deployment is all handled by Python scripts
  • Introduce a new way to develop web apps
      • Fix the bug and hit Reload
  • Lifting away the Java EE constraints
  • Test framework

Easy to use 13.

  • The Java platform is infamous for its low productivity
    • Repeated and tedious compile-package-deploy cycles
  • Hot code reloading and display of errors in the browser

14. - Play will detect changes and automatically reload them at runtime 15. - Stack traces are stripped down and optimized to make it easier to solve problems Fix the bug and hit Reload 16.

  • It is a very different thing to write a generic and reusable Java library and to create a web application

17. An easy-to-develop and elegant stack aimed at productivity

  • Java itself is a very generic programming language and not originally designed for web application development
  • Traditional Java web development:

18. Slow development cycle, too much abstraction, configuration... Lifting away the Java EE constraints 19.

  • JBoss Netty for the web server
  • Hibernate for the data layer
  • Groovy for the template engine
  • The Eclipse compiler for hot-reloading
  • Apache Ivy for dependency management

Popular Java libraries 20.

  • The conf/ directory for the application
  • The $PLAY_PATH/framework/play-$version.jar
  • All JAR files found in your applications lib/ directory
  • All JAR files found in the $PLAY_PATH/framework/lib/ directory

Classpath settings 21.

  • Play provides a built-in test framework for
    • unit testing and functional testing
  • Tests are run directly in the browser
  • By default all testing is done against
      • the included H2 in-memory database

Testing framework 22.

  • Extensions
    • http://www.playframework.org/modules
  • Download and installation

23. http://www.playframework.org/download 24. ---> unpack, setup classpath ---> play! .

  • Some sample public websites
    • Playapps.net, Zibbet Search, Masterbranch ...

Resources 25. Demo 26.

  • app/- the applications core, split between models, controllers and views directories

27. conf/-applications configuration files 28. lib/-optional Java libraries 29. test/-JUnit tests or as Selenium tests

  • ~$ play new helloworld

Project creation 30.

  • Translating incoming HTTP Requests into action calls
    • /conf/routes
  • */clients/{id}Clients.show
          • --->GET/clients/1541
        • 31. ---> PUT/clients/abcd
  • The default matching strategy /[^/]+/
  • User defined pattern /clients/{id}

Router 32.

  • Routes priority : first available
      • GET/clients/allClients.listAll
    • 33. GET/clients/{id}Clients.show
  • Serving static resources
  • staticDir: mapping GET/public/staticDir:public
    • staticFile: mappingGET/homestaticFile:/test.html
  • Reverse routing: generate some URL
    • map.put("id", 1541);
  • 34. String url = Router.reverse("Clients.show", map).url;// GET /clients/1541

Router 35.

  • Variables and scripts:
      • GET${context}Secure.login
  • Setting content types ->determines which view template file
      • GET/index.xmlApplication.index(format:'xml')
  • GET/index.{format}Application.index

Router 36.

  • The last part of a route definition is the Java call
  • A Controller should be defined in the controllers package
    • and must be a subclass of Controller class
  • The action method must be a public static void method

Controller 37.

  • Using the params map
  • From the action method signature
  • JPA object binding :
  • loads the matching instance from the DB before editing it
  • public static void save(User user) { user.save(); // ok with 1.0.1 }
  • user.id = 1 &user.name=morten &user.address.id=34 &user.address.street=MyStreet

Retrieving HTTP parameters 38.

  • There is no equivalent to the Servlet API forward
      • An HTTP request can only invoke one action
  • Filter ~ Interceptions
        • @Before @After @Catch @Finally
  • Session and Flash scope
    • Using the Cookie mechanism

Compare to J2EE 39.

  • If you have used Hibernate or JPA before
    • you will be surprised by the simplicity added by Play
  • CRUD module
  • help quickly generate a basic administration area
  • Secure, validation framework, JSON and XML parsers, OpenID support, full embedded testing framework

Make life easier 40.

  • Unit test
    • A unit test is written using JUnit
  • Functional test
      • Accessing directly the controller objects
  • Selenium test
      • Running it in an automated browser

Test your application