Service-oriented webapp construction using a web metaframework
-
Upload
juanma-dodero -
Category
Internet
-
view
116 -
download
1
Transcript of Service-oriented webapp construction using a web metaframework
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
seminar
service-oriented webapp construction
using a metaframework
Juan Manuel Dodero [email protected]
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
agenda issue webapp construction
context web of data service-oriented web frameworks
techniques ReST services JSON data
tooling spring ROO framework
practice
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
issue
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
modern webapp construction
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
goal
[easily] implement service-oriented web apps
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
context
Licensed under Creative Commons Attribution-Share Alike 3.0
service-oriented
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
webofdata
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
web app architecture
© 2013-2014 Juan M. Dodero
architectural abstraction MVC pattern data access tier abstraction ORM pattern
Licensed under Creative Commons Attribution-Share Alike 3.0
constructing with web frameworks
© 2013-2014 Juan M. Dodero
spring framework
client code
abstraction e.g. MVC pattern inversion of control e.g. Spring DI & AOP
Licensed under Creative Commons Attribution-Share Alike 3.0
constructing with frameworks
© 2013-2014 Juan M. Dodero
framework
control flow
client code
class MyObject extends Object { myMethod() {...} }
o.myMethod();
abstraction design patterns inversion of control dependency injection
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
framework trends
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
framework trends
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
techniques
Licensed under Creative Commons Attribution-Share Alike 3.0
example
Requirements
PizzaShop must build and deploy a set of web services to enable clients:
! get a list of pizzas
! get info on a specific pizza
! submit a pizza purchase order
! etc
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
Request [XML doc]
Response [XML doc]
web
ser
ver
SOAP envelope
HTTP POST aURL
HTTP Response
getPizzaList()
Request [XML doc]
Response [XML doc]
HTTP POST aURL
HTTP Response
getPizza(id) SOAP server
Request [XML doc]
HTTP POST aURL
submit(PizzaOrder) Response [XML doc]
HTTP Response
SOAP implementation
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
web
ser
ver
HTTP GET request /pizzas
HTTP response
Response (HTML/XML/JSON doc)
HTTP GET request
HTTP response
HTTP POST /pizzaorder/id
HTTP response URL to submitted Order
Request (HTML/XML/JSON)
Pizza List
Pizza
Pizza Order
ReST implementation
© 2013-2014 Juan M. Dodero
/pizza/id
Response (HTML/XML/JSON doc)
Licensed under Creative Commons Attribution-Share Alike 3.0
ReST design
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
JSON data serialization
© 2013-2014 Juan M. Dodero
$ curl -s -H "Accept: application/json" http://localhost:8080/pizzashop/pizzas | jq . [ { "version": 1, "toppings": [ { "version": 1, "name": "Mozzarella", "id": 9 }, { "version": 1, "name": "Anchovy fillets", "id": 10 } ], "price": 7.5, "name": "Napolitana", "id": 8, "base": { "version": 1, "name": "Thin Crust", "id": 1 } } ]
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
tooling
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
“fundamentally improve Java developer productivity without compromising engineering integrity or flexibility"!
Licensed under Creative Commons Attribution-Share Alike 3.0
spring ROO features
! 100% java: based on other solid, well-known frameworks
(spring, hibernate, apache tiles, aspectj, flexJSON, dojoToolkit, etc.)
! convention over configuration
! meta-framework (generates source code)
! generated/manual code keep in sync
! works in build-time (not run-time)
! command console
! extensible by add-ons
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
roo architecture
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
ReST URI pattern
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
demo roo console
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
demo web app
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
demo domain model
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
demo roo script // Create a new project project --topLevelPackage com.springsource.pizzashop // Setup JPA persistence using EclipseLink and H2 jpa setup --provider ECLIPSELINK --database H2_IN_MEMORY // Create domain entities entity jpa --class ~.domain.Base --activeRecord false --testAutomatically field string --fieldName name --sizeMin 2 –notNull entity jpa --class ~.domain.Topping --activeRecord false --testAutomatically field string --fieldName name --sizeMin 2 –notNull entity jpa --class ~.domain.Pizza --activeRecord false --testAutomatically field string --fieldName name --notNull --sizeMin 2 field number --fieldName price --type java.math.BigDecimal field set --fieldName toppings --type ~.domain.Topping field reference --fieldName base --type ~.domain.Base entity jpa --class ~.domain.PizzaOrder --testAutomatically --activeRecord false --identifierType ~.domain.PizzaOrderPk field string --fieldName name --notNull --sizeMin 2 field string --fieldName address --sizeMax 30 field number --fieldName total --type java.math.BigDecimal field date --fieldName deliveryDate --type java.util.Date field set --fieldName pizzas --type ~.domain.Pizza field string --fieldName shopCountry --class ~.domain.PizzaOrderPk field string --fieldName shopCity field string --fieldName shopName
// Define a repository layer for persistence repository jpa --interface ~.repository.ToppingRepository --entity ~.domain.Topping repository jpa --interface ~.repository.BaseRepository --entity ~.domain.Base repository jpa --interface ~.repository.PizzaRepository --entity ~.domain.Pizza repository jpa --interface ~.repository.PizzaOrderRepository --entity ~.domain.PizzaOrder
// Define a service/façade layer service type --interface ~.service.ToppingService --entity ~.domain.Topping service type --interface ~.service.BaseService --entity ~.domain.Base service type --interface ~.service.PizzaService --entity ~.domain.Pizza service type --interface ~.service.PizzaOrderService --entity ~.domain.PizzaOrder
// Offer JSON remoting for all domain types through Spring MVC json all --deepSerialize web mvc json setup web mvc json all --package ~.web web mvc setup web mvc all --package ~.web
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
demo json data
© 2013-2014 Juan M. Dodero
$ curl -s -H "Accept: application/json" http://localhost:8080/pizzashop/pizzas | jq . [ { "version": 1, "toppings": [ { "version": 1, "name": "Mozzarella", "id": 9 }, { "version": 1, "name": "Anchovy fillets", "id": 10 } ], "price": 7.5, "name": "Napolitana", "id": 8, "base": { "version": 1, "name": "Thin Crust", "id": 1 } } ]
Licensed under Creative Commons Attribution-Share Alike 3.0
~.dom
ain.Pizza
© 2013-2014 Juan M. Dodero
@RooJavaBean @RooToString @RooJpaEntity @RooJson(deepSerialize = true) public class Pizza {
@NotNull @Size(min = 2) private String name;
private BigDecimal price;
@ManyToMany(cascade = CascadeType.ALL) private Set<Topping> toppings = new HashSet<Topping>();
@ManyToOne private Base base; }
Licensed under Creative Commons Attribution-Share Alike 3.0
Pizza_Roo_JavaBean.aj
© 2013-2014 Juan M. Dodero
privileged aspect Pizza_Roo_JavaBean {
public String Pizza.getName() { return this.name; }
public void Pizza.setName(String name) { this.name = name; }
...
public Set<Topping> Pizza.getToppings() { return this.toppings; }
public void Pizza.setToppings(Set<Topping> toppings) { this.toppings = toppings; }
public Base Pizza.getBase() { return this.base; }
public void Pizza.setBase(Base base) { this.base = base; }
}
Licensed under Creative Commons Attribution-Share Alike 3.0
Pizza_Roo_Json.aj
© 2013-2014 Juan M. Dodero
privileged aspect Pizza_Roo_Json {
...
public String Pizza.toJson(String[] fields) { return new JSONSerializer() .include(fields).exclude("*.class").deepSerialize(this); }
public static Pizza Pizza.fromJsonToPizza(String json) { return new JSONDeserializer<Pizza>() .use(null, Pizza.class).deserialize(json); }
public static String Pizza.toJsonArray(Collection<Pizza> collection) { return new JSONSerializer() .exclude("*.class").deepSerialize(collection); }
...
public static Collection<Pizza> Pizza.fromJsonArrayToPizzas(String json) { return new JSONDeserializer<List<Pizza>>() .use("values", Pizza.class).deserialize(json); }
}
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
http://dodero.github.io/sosc-wmf/
practice
Licensed under Creative Commons Attribution-Share Alike 3.0
references
© 2013-2014 Juan M. Dodero
Licensed under Creative Commons Attribution-Share Alike 3.0
© 2013-2014 Juan M. Dodero
Attribution-Share Alike 3.0