REST based web applications with Spring 3
-
Upload
oliver-gierke -
Category
Technology
-
view
13.119 -
download
1
description
Transcript of REST based web applications with Spring 3
© 2010 SpringSource, A division of VMware. All rights reserved
REST based web applications with Spring 3
Oliver Gierke - Senior Consultant
Agenda
2
Intro
What is REST all about?
Recap: @Controller
What‘s new in Spring MVC 3.0?
What‘s beyond Spring MVC
Demo
About
Oliver Gierke - Senior Consultant
OpenSource enthusiast
(OR)Persistence, Web, Integration
http://www.olivergierke.de / olivergierke
3
Hi! My name is...
SpringSource - a division of VMware
Spring Framework• exhaustive ecosystem
Roo
Groovy / Grails
Tomcat / tc Server / Hyperic
4
REST
5
The architecture of the web
6
Resources
7
IdentifiersVerbs
RepresentationsHypermedia
Spring MVC
8
Spring MVC
9
Model View Controller
Recap: Spring MVC 2.5
10
@Controller@Controller@RequestMapping(„/addresses“)public class AddressController {
@RequestMapping(value=“/address“, method = GET) public String showAddress( @RequestParam Long id, Model model) {…}
}
11
Other special types
Strongly typed request parameterView name
Strongly typed methods
@RequestMapping(value=“/address“, method = GET)public String showAddress( @RequestParam Long id, Model model) {…}
12
What‘s new in Spring MVC 3.0
@PathVariable
Content negotiation
ResponseBody / RequestBody / ResponseStatus
Declarative validation (JSR-303)
13
@PathVariable
@RequestMapping(value=“/addresses/{id}“, method = GET)public String showAddress( @PathVariable Long id, Model model) {…}
14
Content negotiation
http://myapp.com/addresses/1.xmlhttp://myapp.com/addresses/1.jsonhttp://myapp.com/addresses/1.html
Accept: application/xmlAccept: application/jsonAccept: application/html
15
@ResposeBody
@RequestMapping(value=“/addresses/{id}“, method = GET)@ResponseBodypublic Address showAddress( @PathVariable Long id, Model model) {…}
16
@ResponseStatus
@ResponseStatus(NOT_FOUND)public class MyException extends RuntimeException {…}
17
@ResponseStatus
@RequestMapping(value=“/addresses/{id}“, method = GET)public String showAddress( @PathVariable Long id, Model model) {
if (id == null) throw new MyException(); …}
18
@RequestBody
@RequestMapping(value=“/addresses“, method = POST)@ResponseStatus(CREATED)public void createAddress( @RequestBody Address address) {…}
19
Declarative Validation
@RequestMapping(value=“/addresses“, method = POST)@ResponseStatus(CREATED)public void createAddress( @RequestBody @Valid Address address) {…}
20
What‘s new in Spring MVC 3.0
New data binding and type conversion service
Object-XML-Mapping
HiddenHttpMethodFilter
XML namespace
21
Demo
22
23
Where do wego from here?
24
Spring Ecosystem
Spring WebFlowSpring Integration
Spring BatchSpring Roo
Spring Security
Spring WebServices
Demo
25
Questions
26
Resources
Sample: http://github.com/olivergierke/spring-rest
Petcare: http://src.springsource.org/svn/spring-samples/petcare/trunk
Photos: http://www.sxc.hu/
27