Successfully reported this slideshow.
Your SlideShare is downloading. ×

Modern web application development with java ee 7

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 52 Ad

More Related Content

Slideshows for you (16)

Similar to Modern web application development with java ee 7 (20)

Advertisement

More from Shekhar Gulati (13)

Recently uploaded (20)

Advertisement

Modern web application development with java ee 7

  1. 1. Modern Web Applica0on Development with Java EE 7 By Shekhar Gula0 Software Development Done Right 1
  2. 2. Who am I – Shekhar Gula0 Software Development Done Right • Currently working @ Xebia • Polyglot programmer • Previously OpenShiG Evangelist @ Red Hat • Author of OpenShiG Cookbook • TwiLer handle @ shekhargula0 2
  3. 3. Agenda Software Development Done Right • Showcase miles2run • Defining modern web applica0on • How we built this applica0on using Java EE 7 – GeOng started with Java EE 7 – Technology Stack – Cloud deployment op0ons – Java EE 7 limita0ons and challenges • Going polyglot persistence 3
  4. 4. How it all started? Software Development Done Right • A cool Java EE 7 demo applica0on • A Java EE 7 app that would allow users to store their running ac0vi0es • It should run on OpenShiG • It should use modern technologies • It should look and feel modern • It should be open source 4
  5. 5. PetStore or CargoTracker are not modern real applica0ons Software Development Done Right 5
  6. 6. Software Development Done Right 6 https://github.com/miles2run/miles2run
  7. 7. 7 Modern Java Web Application Software Development Done Right
  8. 8. Software Development Done Right 8
  9. 9. What makes a modern web applica0on? Software Development Done Right • Exposes REST JSON web services • Embraces HTML 5 • Single page web applica0on • Stateless so that you can scale horizontally • Uses Oauth • Embraces Polyglot Persistence • Responsive • Cloud aware • Social
  10. 10. Some op0ons in Java world Software Development Done Right 10
  11. 11. Building Miles2Run – Ini0al Requirements Software Development Done Right • Applica0on that can store daily running ac0vi0es • Authen0ca0on using TwiLer • Responsive web applica0on • Each user should have a public profile 11
  12. 12. Technology Stack Software Development Done Right • Java EE 7 with JDK 7 – JPA, EJB, CDI, JAX-­‐RS • SLF4J • MySQL • AngularJS • TwiLer Bootstrap • WildFly on OpenShiG 12
  13. 13. Java EE 7 Software Development Done Right • Standards based development • Portability across applica0on servers • Lightweight deployment • Easy to get started • Java EE API provides a good star0ng point – CDI, JAX-­‐RS, JPA are at the heart of any modern web applica0on 13
  14. 14. Java EE 7 Software Development Done Right 14
  15. 15. LOOK AT FEW JAVA EE API Software Development Done Right 15
  16. 16. CDI 1.1-­‐-­‐ Context and Dependency Injec0on • Allows you to use dependency injec0on in Java EE environment without third party libraries. Software Development Done Right • Don’t call us. We will call you. • CDI container manages the life cycle of components. • CDI brings dependency injec0on, context and scopes, interceptors, loose coupling and strong typing. • Injected bean lifecycle depends on the target bean. • Turns nearly every Java class into CDI bean • It is not a non sta0c inner class • It is a concrete class or annotated with decorators • Has default constructor with no parameters or declares a constructor with @Inject
  17. 17. CDI 1.1: What’s new in Java EE 7? Software Development Done Right • Finer scanning control in beans.xml • bean-­‐discovery-­‐mode aLribute – all, none, annotated • @Vetoed annota0on to veto processing of a package or class. • You can use @Transac0onal with CDI beans. • You can get away from EJBs.
  18. 18. JPA Software Development Done Right • Describes the management of rela0onal data in applica0ons. • JPA implementa0ons provide ORM framework • JPA provides an API to perform CRUD and find opera0ons on en00es. • An en0ty is a POJO, whose state is mapped to a rela0onal database table. • JPA also provides a query language to make queries against en00es stored in rela0onal database.
  19. 19. JPA 2.1 – What’s new in Java EE 7? Software Development Done Right • Schema genera0on using standard proper0es. • Use @Index to define addi0onal indexes in schema genera0on. • New En0tyGraph API available in En0tyManager.
  20. 20. Storing data in UTC Software Development Done Right • Store all the dates in the UTC format and then depending on the client 0mezone show it to the user 20
  21. 21. Bean Valida0on Software Development Done Right • Specifies common valida0on concept for JavaBeans. • Allow you to put constraints on data to make sure it is valid. • Annota0on based constraints • Use constraint in any layer
  22. 22. Bean Valida0on Example public class Status{ @NotNull @Size(max = 140) private String message; @NotNull @Past private final Date postedAt; @UniqueUrl private String url; public Status() {} } Software Development Done Right
  23. 23. Bean Valida0on 1.1 – What’s new in Java EE 7? Software Development Done Right • Approaches Programming by Contract • Can inject with CDI into Validator implementa0ons • Integra0on with JAX-­‐RS @Path(“/statuses”) public class StatusService { @POST @Produces(“application/json”) public @NotNull Status postStatus(@Valid @NotNull Status status) { // persist in database return status; } }
  24. 24. JAX-­‐RS Software Development Done Right • Java API for RESTful web services • Annota0on driven API that aims to help developers build RESTful web services in Java • POJO based Resource classes • HTTP centric – Maps HTTP requests to Java method invoca0ons 24
  25. 25. JAX-­‐RS Resource Software Development Done Right 25
  26. 26. What’s new in Java EE 7? Software Development Done Right • Client API • Asynchronous JAX-­‐RS services • Filters and interceptors 26
  27. 27. SLF4J Software Development Done Right • Abstrac0on or façade on top of different logging API • SLF4J with Logback provides a faster logging implementa0on • SLF4J has great paLern subs0tu0on support. logger.debug("Calcula0ng Goal-­‐{} progress between {} and {}", goalId, startDate, endDate); 27
  28. 28. AngularJS Software Development Done Right • Extends HTML to add dynamic nature so that we can build modern web applica0ons with ease • Declara0ve approach • Eliminates DOM manipula0on by two way data binding • Ideal for building single page web applica0ons 28
  29. 29. AngularJS in Ac0on Software Development Done Right 29
  30. 30. OpenShift is PaaS by Red Hat Multi-language, Auto-Scaling, Self-service, Elastic, Cloud Application Platform Software Development Done Right
  31. 31. CLOUD COMPUTING 101 APPLICATION APPLICATION PLATFORM (App Server, Middleware, Languages) OPERATING SYSTEM VIRTUAL GUEST IMAGES COMPUTE RESOURCES (CPU, RAM, NETWORK, DISK) Automated and Managed by the Cloud Provider Software Development Done Right Provided and Controlled by Cloud Consumer IaaS PaaS SaaS Increased Control Increased Automation DEVELOPER TOOLING (IDE, Source Control, Build Tools, CI)
  32. 32. Why OpenShiZ? l Focus on code, not on configura0on l Speeds up deployment l Scales your app Software Development Done Right l Efficient l Embraces polyglot programming and persistence.
  33. 33. Bringing everything together Software Development Done Right • Start by crea0ng WildFly app on OpenShiG • OpenShiG will create a Maven app • Clone the app Git repo on your local machine • Import the app in your favorite IDE • Write domain model • Write EJB services that uses JPA en0ty manager • Expose REST API • Commit the code to local repo and push changes to remote Git repository 33
  34. 34. Challenges Software Development Done Right • Rendering HTML 5 pages from JAX-­‐RS • Use JAX-­‐RS as MVC framework • Servlet containers do not create sessions when you render HTML 5 pages • Your whole applica0on is not a single SPA • Java EE has no support for OAuth providers like TwiLer 34
  35. 35. To overcome some of these challenges I wrote a small framework called JUG hLps://github.com/miles2run/jug It allows me to render HTML 5 pages using Thymeleaf template engine Provides basic security check Enables sessions for HTML 5 pages Software Development Done Right 35
  36. 36. JUG Example Software Development Done Right 36
  37. 37. Why Thymeleaf? Software Development Done Right • Thymeleaf documents are valid HTML 5 documents so you can work with them offline • Extends HTML by a tag library • All thymeleaf documents are valid HTML 5 documents • Allows designers and developers to work together 37 createProfile.html
  38. 38. Make app social – new requirements • Ability to follow other users Software Development Done Right • View their ac0vi0es on my home page 38
  39. 39. Redis to rescue Software Development Done Right • REmote DIc0onary Server • Redis is an in-­‐memory key value data store • Supports persistence • Supports rich set of data types – List, Set, Sorted Set, Hash 39
  40. 40. Redis Set for storing follower and following Software Development Done Right 40
  41. 41. Redis update 0meline with follower 0meline Software Development Done Right 41 TimelineRepository.java
  42. 42. Redis – Storing Ac0vi0es Software Development Done Right 42 TimelineRepository.java
  43. 43. Other use case of Redis Software Development Done Right • Maintaining applica0on counters • Latest ac0vi0es on user home page • Caching ac0vi0es 43
  44. 44. Sugges0ng users – another requirement Software Development Done Right • Sugges0ng users based on loca0on 44
  45. 45. MongoDB to rescue Software Development Done Right 45
  46. 46. Storing GeoSpa0al data Software Development Done Right 46
  47. 47. Querying data Software Development Done Right 47
  48. 48. Loca0onBasedUserSuggester Software Development Done Right 48
  49. 49. Adding beau0ful graphs Software Development Done Right • C3.js for crea0ng graphs • Provides API to write D3 based charts • No need to work with D3 API • Examples hLp://c3js.org/examples.html 49
  50. 50. Genera0ng a Donut chart Software Development Done Right 50
  51. 51. Configuring error pages Software Development Done Right 51
  52. 52. THANKS Q & A Software Development Done Right 52

×