Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

eXo Platform SEA - Play Framework Introduction

Nächste SlideShare
Play Framework: The Basics
Play Framework: The Basics
Wird geladen in …3

Hier ansehen

1 von 26 Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie eXo Platform SEA - Play Framework Introduction (20)


Aktuellste (20)

eXo Platform SEA - Play Framework Introduction

  1. 1. Vu Viet Phuong - PortalTeam Play Framework Introduction
  2. 2. <ul><li>Introduce key features of Play! framework </li></ul><ul><li>Some great new ideas for Web Framework </li></ul>Objective
  3. 3. <ul><li>Play! Framework Introduction </li></ul>Subject <ul><li>Demo sample applications </li></ul>
  4. 4. Play! Framework Introduction
  5. 5. <ul><li>Simple stateless MVC architecture </li></ul><ul><li>No configuration: download, unpack and develop </li></ul><ul><li>Integrated unit testing: </li><ul><li>JUnit and Selenium support is included in the core </li></ul></ul><ul><li>Elegant API: rarely will a developer need to import any third party library - Play comes with all the typical stuff built-in </li></ul>Major differences
  6. 6. <ul><li>Uses Java but tries to push all the good things </li><ul><ul><li>from the frameworks based on scripting languages </li></ul></ul></ul><ul><li>Get the best of the Java platform without </li><ul><ul><li>getting the pain of traditional Java web development </li></ul></ul></ul>Advantage
  7. 7. <ul><li>Very good documented and easy to use product </li><ul><li>- JavaDoc
  8. 8. - User guide
  9. 9. - Sample apps </li></ul></ul><ul><li>Full-stack application framework </li></ul><ul><li>Introduce a completely new way to develop web apps </li></ul>Advantage
  10. 10. <ul><li>Database support : JDBC, object-relational mapping using Hibernate (with the JPA API). </li></ul><ul><li>Integrated cache support with easy use of the distributed memcached system if needed </li></ul><ul><li>Straightforward web services consumption either in JSON or XML </li></ul>Full-stack application framework
  11. 11. <ul><li>OpenID support for distributed authentication </li></ul><ul><li>Ready to be deployed anywhere (application server, Google App Engine, Cloud, etc…) </li></ul><ul><li>Image manipulation API </li></ul>Full-stack application framework
  12. 12. <ul><li>Build and deployment is all handled by Python scripts </li></ul><ul><li>Introduce a new way to develop web apps </li></ul><ul><ul><ul><li>Fix the bug and hit Reload </li></ul></ul></ul><ul><li>Lifting away the Java EE constraints </li></ul><ul><li>Test framework </li></ul>Easy to use
  13. 13. <ul><li>The Java platform is infamous for its low productivity </li><ul><ul><li>Repeated and tedious compile-package-deploy cycles </li></ul></ul></ul><ul><li>Hot code reloading and display of errors in the browser
  14. 14. - Play will detect changes and automatically reload them at runtime
  15. 15. - Stack traces are stripped down and optimized to make it easier to solve problems </li></ul>Fix the bug and hit Reload
  16. 16. <ul><li>It is a very different thing to write a generic and reusable Java library and to create a web application
  17. 17. An easy-to-develop and elegant stack aimed at productivity </li></ul><ul><li>Java itself is a very generic programming language and not originally designed for web application development </li></ul><ul><li>Traditional Java web development:
  18. 18. Slow development cycle, too much abstraction, configuration... </li></ul>Lifting away the Java EE constraints
  19. 19. <ul><li>JBoss Netty for the web server </li></ul><ul><li>Hibernate for the data layer </li></ul><ul><li>Groovy for the template engine </li></ul><ul><li>The Eclipse compiler for hot-reloading </li></ul><ul><li>Apache Ivy for dependency management </li></ul>Popular Java libraries
  20. 20. <ul><li>The conf/ directory for the application </li></ul><ul><li>The $PLAY_PATH/framework/play-$version.jar </li></ul><ul><li>All JAR files found in your application’s lib/ directory </li></ul><ul><li>All JAR files found in the $PLAY_PATH/framework/lib/ directory </li></ul>Classpath settings
  21. 21. <ul><li>Play provides a built-in test framework for </li><ul><ul><li>unit testing and functional testing </li></ul></ul></ul><ul><li>Tests are run directly in the browser </li></ul><ul><li>By default all testing is done against </li></ul><ul><ul><ul><li>the included H2 in-memory database </li></ul></ul></ul>Testing framework
  22. 22. <ul><li>Extensions </li><ul><ul><li>http://www.playframework.org/modules </li></ul></ul></ul><ul><li>Download and installation
  23. 23. http://www.playframework.org/download
  24. 24. ---> unpack, setup classpath ---> play! …. </li></ul><ul><li>Some sample public websites </li><ul><ul><li>Playapps.net, Zibbet Search, Masterbranch ... </li></ul></ul></ul>Resources
  25. 25. Demo
  26. 26. <ul><li>app/ - the application’s core, split between models, controllers and views directories
  27. 27. conf/ - application’s configuration files
  28. 28. lib/ - optional Java libraries
  29. 29. test/ - JUnit tests or as Selenium tests </li></ul><ul>~$ play new helloworld </ul>Project creation
  30. 30. <ul><li>Translating incoming HTTP Requests into action calls </li><ul><ul><li>/conf/routes </li></ul></ul></ul><ul>* /clients/{id} Clients.show <ul><ul><ul><ul><li>---> GET /clients/1541
  31. 31. ---> PUT /clients/abcd </li></ul></ul></ul></ul></ul><ul><li>The default matching strategy /[^/]+/ </li></ul><ul><li>User defined pattern /clients/{<[0-9]+>id} </li></ul>Router
  32. 32. <ul><li>Routes priority : first available </li></ul><ul><ul><ul><li>GET /clients/all Clients.listAll
  33. 33. GET /clients/{id} Clients.show </li></ul></ul></ul><ul><li>Serving static resources </li><ul><li>staticDir: mapping GET /public/ staticDir:public </li></ul></ul><ul><ul><li>staticFile: mapping GET /home staticFile:/test.html </li></ul></ul><ul><li>Reverse routing: generate some URL </li></ul><ul><ul><li>map.put(&quot;id&quot;, 1541);
  34. 34. String url = Router.reverse(&quot;Clients.show&quot;, map).url; // GET /clients/1541 </li></ul></ul>Router
  35. 35. <ul><li>Variables and scripts: </li></ul><ul><ul><ul><li>GET ${context} Secure.login </li></ul></ul></ul><ul><li>Setting content types -> determines which view template file </li></ul><ul><ul><ul><li>GET /index.xml Application.index(format:'xml') </li></ul><li> GET /index.{format} Application.index </li></ul></ul>Router
  36. 36. <ul><li>The last part of a route definition is the Java call </li></ul><ul><li>A Controller should be defined in the controllers package </li><ul><ul><li>and must be a subclass of Controller class </li></ul></ul></ul><ul><li>The action method must be a public static void method </li></ul>Controller
  37. 37. <ul><li>Using the params map </li></ul><ul><li>From the action method signature </li></ul><ul><li>JPA object binding : </li><ul><li>loads the matching instance from the DB before editing it </li></ul></ul><ul>public static void save(User user) { user.save(); // ok with 1.0.1 } </ul><ul>user.id = 1 &user.name=morten &user.address.id=34 &user.address.street=MyStreet </ul>Retrieving HTTP parameters
  38. 38. <ul><li>There is no equivalent to the Servlet API forward </li></ul><ul><ul><ul><li>An HTTP request can only invoke one action </li></ul></ul></ul><ul><li>Filter ~ Interceptions </li><ul><ul><ul><ul><li>@Before @After @Catch @Finally </li></ul></ul></ul></ul></ul><ul><li>Session and Flash scope </li><ul><ul><li>Using the Cookie mechanism </li></ul></ul></ul>Compare to J2EE
  39. 39. <ul><li>If you have used Hibernate or JPA before </li><ul><ul><li>you will be surprised by the simplicity added by Play </li></ul></ul></ul><ul><li>CRUD module </li><ul><li>help quickly generate a basic administration area </li></ul></ul><ul><li>Secure, validation framework, JSON and XML parsers, OpenID support, full embedded testing framework … </li></ul>Make life easier
  40. 40. <ul><li>Unit test </li><ul><ul><li>A unit test is written using JUnit </li></ul></ul></ul><ul><li>Functional test </li></ul><ul><ul><ul><li>Accessing directly the controller objects </li></ul></ul></ul><ul><li>Selenium test </li></ul><ul><ul><ul><li>Running it in an automated browser </li></ul></ul></ul>Test your application