Download - Resthub lyonjug
Full stack framework
What is RESThub ?
Java Stack Javascript Stack
Don't Repeat Yourself
Keep It Simple, Stupid
Some rights reserved by vrogy
Not reinventing the wheel !
Java Stack
Java stack modules
Generic Middle classes
GenericREST
Webservice
Plu
gin
Arc
hite
ctur
e
Tooling - TestingDocumentation
Tapestry 5Integration
Software design
• Plugin based architecture– Spring + naming convention– classpath*: scanning– Maven multi modules– Runtime configuration
with SpEL
• Multilayered software design– Interface - Implementation– DAO - Service - View
> Focus on business
Enable progressive complexity
Java Middle stack
Embedded database
Cross modules scanningfor JPA entities
JSR 303 Bean validation
Generic Services and tests Generic DAO
Hades 2
Validator
1.3
JPA2 Persistence engine
3.5
Spring DBUnit integration
@Named("bookingDao") public class JpaBookingDao
extends GenericJpaResourceDao<Booking> implements BookingDao { ...
}
@Named("bookingService") public class BookingServiceImpl
extends GenericResourceServiceImpl<Booking, BookingDao> implements BookingService { ...
}
Generic classes
Generic testsDefault Spring behaviour (Rollback=true) is disabled !In memory H2 database configuration
• AbstractResthubTest : Spring configuration aware• AbstractResthubTransactionalTest : your test is transactional• AbstractResthubTransactionAwareTest : designed to test your
service layer
• AbstractResthubWebTest : embedded preconfigured Jetty
• AbstractDaoTest, AbstractServiceTest, AbstractControlerTest :generic CRUD unit tests
Spring DBUnit integration@Named("sampleDataSet")public class SampleDataSetInitializer implements DataSetInitializer { @Override
public void createData() throws Exception { ...
}}
@InjectDataSet(value = "sampleDataSet", onceForClass=false)public class SampleDaoTest {
@Testpublic void sampleTest() {
...}}
REST webservices
JAX-RS REST Webservices
Generic webservices Generic tests
Jersey 1.6
JSON SerializationJackson 1.7
WADL explorer jQuery pluginRun/Debug web application
7.3
OAuth2 based security
@GET@Path("/{ref}")@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})public Response getResource(@PathParam("ref") String ref)
{T entity = this.service.findByRef(ref);if (entity == null) {
return Response.status(Status.NOT_FOUND).build();}return Response.ok(entity).build();
}
How to… retrieve a persisted object in database ?
Generic REST Services
OAuth2
Serialization
• XML serialization thanks to JAXB annotation• JSON serialization
• Not so simple to manage (cyclic object graphs)• « BadgerFish » or « Mapped » strategy are not easy
to use• We have chosen Jackson POJO serialization• Interesting features like parent/children bi–directional
link support• Missing reference support
Javascript Stack
Use case 1 : server based MVC Framework
Middle
MVC Framework
Ser
ver
side Webservices
(optional)
Session
Templateprocessing
MVCframework
Browser
Clie
ntsi
de Stateless
Dynamicpages
Use case 2 : client MVC with RESThub JS
Middle
RESTWebservices
Ser
ver
side
Clie
nt s
ide
HTML5/JavaScript RIA
Session
Templateprocessing
MVCframework
Stateless
Static file(JS, HTML, CSS)
Browser
Dynamicdata
Staticfiles
Context loss, and no classesScopes and closuresNo strong typingCross browser compatibility
Why Java developpers hate JS ?
Damn it, it’s Web developpement !
But Web techno Rocks !Concerns separationHighly dynamicProductive and quickApps are trendy and sexy
No restart needed !
• But why ?– RIA vs Server side presentation framework– So much unused power on our desktop !– Competitors already provide framework
• Allows…– Use the latest web technologies consistently– Reduce traffic and server load– Reuse server-programming good practices
Javascript stack for RIA Webapps
Widgets
Script loader andOptimizer
ui 1.8JavaScript core library
1.4
RESThub JS MVC
Javascript stack
Class support
I want my imports !
Script loading
define(['lib/resthub', 'routes', 'controllers/home'
], function() { ...
});
RoutingOnly one
« real » page
Using the hash > no reload
$.route('#/home', function() { ...
});
$.route('#/home');
ClassesWe’re used to OOP, not prototype
define(['lib/class'], function(Class) { return Class.extend('MyClass', { attribute: 'some value', method: function() { } });});
Static, instance, single inheritance
Controller: presentation logic
Controllers & templates
Template: readable DOM fragment<p>Hello ${user.name} !</p>
define(['lib/controller'], function(Controller) { return Controller.extend('HomeController', { template : 'views/home.html', init : function() { this.render({user:{name:'Tyler'}}); } });});
WidgetsInteractive enhanced GUI
Build your GUI, as in Swing/SWT
init: function() { this.render(); $('a.confirm', this.element) .click($.proxy(this, '_confirmHandler') .button({ label: i18n.buttons.confirm });}
Repositories
Connection to REST servers
define(['lib/repository'], function(Repository) { return Repository.extend('UserRepository', { root: 'api/users/', findByName: function(name, callback) { this._get(this.root + name, callback); } });});
Local storage > client sessionEvent bus > between controllersI18n > like in JavaSecurity > OAuth2JSON > effective communicationConsole > like log4j…
Bonus
Application server
Web browser
View
DA
O
Bus
ines
s S
ervi
ces
RE
ST
Web
Ser
vice
s
Ro
ute
s
View
View
Controller
Controller
Controller
Repository
Repository
Tools
Global view
Demo
RESThub examples
Javascript Javascript & Tapestry 5
RESThub examples
Status & Roadmap
• RESThub 1.1-RC1 has just been released !• RESThub 1.2 roadmap :
– Spring Data integration (CouchDB, Redis)– OAuth 2 final version support– AsyncHttpClient for scalable architecture– PushState support on routing– Client side bean validation based on JSR-303
annotations– Websocket support– NodeJS based server side template processing
Status and Roadmap