Efficient Java development
with RESThub framework
Sébastien Deleuze - Atos Worldline
Hi and welcome to this presentation. My name is Sébastien Deleuze, I am software architect at Atos Worldline (an Atos Origin company), and the founder and lead developer of RESThub. The goal of this presentation is to explain what RESThub is, how it compares to other frameworks and why it could help you build better Java applications.
Basically, RESThub is a full stack framework. That means it provides all you need to build your applications from database to GUI. RESThub is modular, so each part of the stack could be replaced by your own.
Before speaking about technical details, we are going to have a look at the principles behind the framework. The first one is efficiency. Efficiency for developing, running, debugging and deploying your applications.
The second one is DRY, for Don't Repeat Yourself. Code duplication is a major waste of time and it produces a lot of quality and maintainability issues on your project. We provide some helpers to avoid it.
The third one is KISS, for Keep It Simple. That said, most of current nice frameworks like Grails or Play are based on the same principles. So why a new framework and what make RESThub different?
If we share most of the goals with these frameworks, we have chosen to reuse well known technologies and standards to build, from our point of view, the best framework we could. Only missing features have been developed.
So let's take a deeper look at RESThub features. It offers modular sets of functionalities :
- A plugin architecture
- A generic MIDDLE stack
- A generic REST webservice stack
- And 2 kinds of View frameworks
- A HTML5/Javascript stack for building RIA
- A Tapestry 5 integration for classical MVC framework server based architecture
- Some documentation and tooling
We are now going to detail what technologies are in RESThub, and what new features, identified by the RESThub icon, we have developed. RESThub provides a plugin system based on Spring 3 used with naming conventions and Maven multi modules. Spring expression language and properties placeholder allow runtime configuration resolution.
The goal is to allow quick bootstrap of your project, but also scale for big projects that require more complexity. So we do not try to hide things in a black box, we just provide conventions or default configuration based on well known agile frameworks like Spring 3, and it works !
Hibernate is our choice for JPA2 persistence provider and bean validation implementation. Generic Data Access Objects are based on Hades framework, and we have applied the same concept to create Generic CRUD services and generic unit tests designed to test automatically CRUD operations on you domain model POJOs. The entity scanner allows you to dispatch your JPA entities in different modules and using them in the same persistence unit, which is not possible with Hibernate by default.
@Named("bookingDao") public class JpaBookingDao extends GenericJpaResourceDao<Booking>
implements BookingDao { ...
}
@Named("bookingService") public class BookingServiceImpl extends
GenericResourceServiceImpl<Booking, BookingDao>
implements BookingService { ...
}
public class TestBookingDao extends
AbstractResourceDaoTest<Booking, BookingDao> { ...
}
On this slide, you can have an overview of the usage of generic classes provided by RESThub, for your Data Access Object, CRUD service and unit test.
The webservice stack is based on Jersey, which is the JAX-RS 1.1 reference implementation. Some generic test classes allow you to easily test your webservices. These classes are based on Jetty embedded server and Jersey client library. WADL descriptions, automatically published by Jersey, are similar to SOAP WSDL descriptions. We have built a jQuery plugin that uses this description to generate a web interface that allows you to test your REST webservices. OAuth 2 is an open standard for authorization, usable for any kind of applications: web, desktop, mobile phone... It allows users to share their private resources, like photos, or videos, stored on one site with another site without having to hand out their credentials, typically username and password. RESThub provides a first java implementation of the OAuth 2 protocol.
Let's now detail the 2 main use cases for RESThub web application development. The first use case is to use RESThub with your favorite MVC framework (Tapestry 5, Wicket...) In this case, RESThub will help you build your application faster, with a software design close to what you usually do. Session, MVC framework and template processing are obviously on server side.
The second use case is quite different. Server side becomes stateless. Session, MVC framework and template processing are moved to the client side. This proposed software design is in fact very close to Flex application with a Java backend, but implemented with HTML5 and Javascript instead of Flex.
No restart is needed after a change on the view stack, so productivity is greatly improved.
This slide details the Javascript stack used to implement use case 2 software design. It is based on jQuery for DOM selectors and browser compatibility. MVC pattern is implemented on the client side, using widgets from jQuery UI and route management from Sammy.JS framework. Its main purpose is to manage routes in a one page web application "a la" Gmail. Dominoes is an extremely well done script loader that let you define synchronous or asynchronous script loading order. Client side templates are processed by Embedded JS.
The client side MVC is one of the key point of this architecture. It is quite close to Flex GUI built on top of Java remote services. Basically, the application is composed of a few html files, where we define thanks to Sammy different routes. Each route is accesssible thanks to URL fragments #route1, #route2, #route3 in this example. When a route is reached, a Javascript controller takes care of retrieving data from JAX-RS webservices and process the HTML template. All of this, of course, is component based, so you can build reusable Rich Internet Applications.
<table> <% var hotels = result.elements %> <% for (index in hotels) { %> <tr class="hotel-item" id="hotel-<%= hotels[index].id %>"> <td><%= hotels[index].name %></td> <td><a href="#/hotel/<%= hotels[index].id %>">View Hotel</a></td> </tr> <% } %> </table>
{"elements":[ {"id":1,"name":"Marriott Courtyard","address":"Tower Place,Buckhead","city":"Atlanta","state":"GA","zip":"30305","country":"USA","stars":3,"price":129.00}, {"id":2,"name":"Doubletree Atlanta-Buckhead","address":"3342 Peachtree Road NE","city":"Atlanta","state":"GA","zip":"30326","country":"USA","stars":4,"price":84.00}, }
<table> <tr class="hotel-item" id="hotel-1"> <td>Marriott Courtyard</td> <td><a href="#/hotel/1">View Hotel</a></td> </tr> <tr class="hotel-item" id="hotel-2"> <td>Doubletree Atlanta-Buckhead</td> <td><a href="#/hotel/2">View Hotel</a></td> </tr> </table>
This first code sample is a JSON object, retrieved for a REST webservice.
The second one is a static HTML template with dynamic elements written in Javascript thanks to Embedded JS.
The last one is the HTML code produced by Embedded JS after processing. All this work is done on client side,
which has 2 significant advantages :
- It saves your server processing time
- It allows you to heavily cache your files even with per-user customized pages
With recent browsers, processing time is low even with large chunk of data.
In addition to the reference documentation and tutorial, we bundle 2 applications examples based on RESThub, useful for building your own ones : - Roundtable, a Doodle clone, developed with RESThub HTML5/Javascript stack - Booking, a well known example application, already implemented with JBoss Seam, Spring Webflow and Play Framework. We provide 2 implementations: one based on HTML5/Javascript stack, and the other one based on Tapestry 5 integration. It makes both approaches easier to compare.
3 Maven archetypes to quickly bootstrap your project :
RESThub also provides 3 Maven archetypes to quickly bootstrap your projects :
- Tapestry 5 web application
- Javascript/HTML5 RIA
- JAR module
RESThub 1.0 has just been released !
RESThub 1.1 roadmap :
Features described in previous slides are all in RESThub 1.0, that has just been released. RESThub 1.1 will improve HTML5/Javascript RIA, add CouchDB integration, provides some scaffolding capabilities based on Maven 3 Shell and will support all OAuth 2 profiles.
Get it and fork it http://resthub.org
Follow me @sdeleuze
You can get RESThub on its website resthub.org. Source code is hosted on Bitbucket forge, like GitHub but with Mercurial source repositories, so feel free to fork the project and improve it. I and other RESThub developers present here (Baptiste, Damien and Nicolas) will be available to discuss with you and answer your questions. Thanks for your attention.
Table of Contents | t |
---|---|
Exposé | ESC |
Source Files | s |
Slide Numbers | n |
Notes | 2 |
Help | h |