40

Resthub lyonjug

Embed Size (px)

DESCRIPTION

RESThub 1.1 presentation

Citation preview

Page 1: Resthub lyonjug
Page 2: Resthub lyonjug

Full stack framework

Page 3: Resthub lyonjug

What is RESThub ?

Java Stack Javascript Stack

Page 4: Resthub lyonjug

Don't Repeat Yourself

Page 5: Resthub lyonjug

Keep It Simple, Stupid

Page 6: Resthub lyonjug

Some rights reserved by vrogy

Not reinventing the wheel !

Page 7: Resthub lyonjug

Java Stack

Page 8: Resthub lyonjug

Java stack modules

Generic Middle classes

GenericREST

Webservice

Plu

gin

Arc

hite

ctur

e

Tooling - TestingDocumentation

Tapestry 5Integration

Page 9: Resthub lyonjug

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

Page 10: Resthub lyonjug

Enable progressive complexity

Page 11: Resthub lyonjug

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

Page 12: Resthub lyonjug

@Named("bookingDao") public class JpaBookingDao

extends GenericJpaResourceDao<Booking> implements BookingDao {     ...

}

@Named("bookingService") public class BookingServiceImpl

extends GenericResourceServiceImpl<Booking, BookingDao> implements BookingService {     ...

}

Generic classes

Page 13: Resthub lyonjug

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

Page 14: Resthub lyonjug

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() {

...}}

Page 15: Resthub lyonjug

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

Page 16: Resthub lyonjug

@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

Page 17: Resthub lyonjug

OAuth2

Page 18: Resthub lyonjug

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

Page 19: Resthub lyonjug

Javascript Stack

Page 20: Resthub lyonjug

Use case 1 : server based MVC Framework

Middle

MVC Framework

Ser

ver

side Webservices

(optional)

Session

Templateprocessing

MVCframework

Browser

Clie

ntsi

de Stateless

Dynamicpages

Page 21: Resthub lyonjug

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

Page 22: Resthub lyonjug

Context loss, and no classesScopes and closuresNo strong typingCross browser compatibility

Why Java developpers hate JS ?

Damn it, it’s Web developpement !

Page 23: Resthub lyonjug

But Web techno Rocks !Concerns separationHighly dynamicProductive and quickApps are trendy and sexy

Page 24: Resthub lyonjug

No restart needed !

Page 25: Resthub lyonjug

• 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

Page 26: Resthub lyonjug

Widgets

Script loader andOptimizer

ui 1.8JavaScript core library

1.4

RESThub JS MVC

Javascript stack

Class support

Page 27: Resthub lyonjug

I want my imports !

Script loading

define(['lib/resthub', 'routes', 'controllers/home'

], function() { ...

});

Page 28: Resthub lyonjug

RoutingOnly one

« real » page

Using the hash > no reload

$.route('#/home', function() { ...

});

$.route('#/home');

Page 29: Resthub lyonjug

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

Page 30: Resthub lyonjug

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'}}); } });});

Page 31: Resthub lyonjug

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 });}

Page 32: Resthub lyonjug

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); } });});

Page 33: Resthub lyonjug

Local storage > client sessionEvent bus > between controllersI18n > like in JavaSecurity > OAuth2JSON > effective communicationConsole > like log4j…

Bonus

Page 34: Resthub lyonjug

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

Page 35: Resthub lyonjug

Demo

Page 36: Resthub lyonjug

RESThub examples

Javascript Javascript & Tapestry 5

Page 37: Resthub lyonjug

RESThub examples

Page 38: Resthub lyonjug

Status & Roadmap

Page 39: Resthub lyonjug

• 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

Page 40: Resthub lyonjug

http://resthub.orghttp://pullrequest.org

Questions ?