SlideShare a Scribd company logo
Spring 4 Web Applications
Rossen Stoyanchev
Pivotal Inc
About the speaker
● Spring Framework committer
● Spring MVC
● Spring WebSocket and Messaging
Spring MVC
● Since 2003 (circa JDK 1.4)
● Before Java annotations, REST, SPAs, ...
● Continued success, evolution
● Most popular status today
Programming Model Evolution
● @Controller ………...………... 2.5 (2007)
● REST …………………………….. 3.0 (2009)
● Async requests ……………….. 3.2 (2012)
● WebSocket messaging …….. 4.0 (2013)
● Simple, clean design at the core
● Friendly to extension
● Embraces HTTP and REST
● Community requests
Keys to Success
Always Evolving
● One of most actively developed parts of
Spring Framework
● Continuous flow of ideas and requests from
the community
● Improvements, new features, even modules
with each new version
@MVC
@Controller
@InitBinder
@ModelAttribute
@RequestMapping
@ExceptionHandler
@RestController
@RestController
public class MyController {
@RequestMapping @ResponseBody
public Foo handle() { … }
@RequestMapping @ResponseBody
public Bar handle() { … }
}
Beyond Class Hierarchy
@ControllerAdvice
@InitBinder
@ModelAttribute
@ExceptionHandler
Selectors
@ControllerAdvice => “Apply to every @Controller”
@ControllerAdvice(basePackages = "org.app.module")
@ControllerAdvice(annotations = RestController.class)
@ControllerAdvice(assignableTypes =
{BaseController1.class, BaseController2.class})
ResponseEntityExceptionHandler
● Base class for use with @ControllerAdvice
● Handle Spring MVC exceptions
● REST API error details in response body
ResponseBodyAdvice
● Interface for use with @ControllerAdvice
● Customize response before @ResponseBody &
ResponseEntity are written
● Built-in usages
○ @JsonView on @RequestMapping methods
○ JSONP
Further Jackson Support
● Use Jackson for both JSON and XML
● ObjectMapper builder
● Highly recommended read:
https://spring.io/blog/2014/12/02/
latest-jackson-integration-
improvements-in-spring
@RequestMapping methods
● java.util.Optional (JDK 1.8) support
● ListenableFuture return value
● ResponseEntity/RequestEntity builders
● Links to @MVC methods
● @ModelAttribute method ordering
ResponseEntityBuilder
String body = "Hello";
HttpHeaders hdrs = new HttpHeaders()
headers.setLocation(location);
new ResponseEntity<String>(body, hdrs, CREATED);
vs
ResponseEntity.created(location).body("Hello");
RequestEntityBuilder
HttpHeaders headers = new HttpHeaders();
headers.setAccept(MediaType.APPLICATION_JSON);
new HttpEntity("Hello", headers);
vs
RequestEntity.post(uri)
.accept(MediaType.APPLICATION_JSON)
.body("Hello");
Link to @RequestMapping
● Simulate controller method invocation
fromMethodCall(on(MyController.class).getAddress("US"))
.buildAndExpand(1).toUri();
● Uses proxy, similar to testing w/ mocks
● See section on Building URIs
How to link from views?
● Refer to @RequestMapping by name
● Default name assigned to every mapping
○ or use @RequestMapping(name=”..”)
● See subsection in Building URIs
@ModelAttribute Ordering
<- Call this 1st
@ModelAttribute("foo")
public Object getFoo() {
}
@ModelAttribute("bar")
public Object getBar(@ModelAttribute("foo") Object foo) {
}
Uses “foo”
Creates “foo”
Static Resources
● Key topic for web applications today
○ Optimize .. minify, concatenate
○ Transform .. sass, less
○ HTTP caching .. versioned URLs
○ CDN
○ Prod vs dev
Static Resources in 4.1
● Build on existing
ResourceHttpRequestHandler
● Add abstractions to resolve and transform
resources in a chain
● Prepare “public” resource URL
URL “Fingerprinting”
● HTTP “cache busting”
● Version URL with content-based hash
● Add aggressive cache headers (e.g. +1 year)
Example URL:
“/css/font-awesome.min-7fbe76cdac.css”
Static Resources Continued
See Resource Handling talk on Youtube,
browse the slides,
or check the source code.
Groovy Markup Templating
● DRY markup based on Groovy 2.3
● Like HAML in Ruby on Rails
yieldUnescaped '<!DOCTYPE html>'
html(lang:'en') {
head {
title('My page')
}
body {
p('This is an example of HTML contents')
}
}
MVC Config
● We now have ViewResolver registry
● ViewController can do more
○ redirects, 404s, etc.
● Patch matching by popular demand
○ suffix patterns, trailing slashes, etc.
Servlet 3 Async Requests
● Since v3.2
○ Long polling, HTTP streaming
● Server can push events to client
○ chat, tweet stream
● Relatively simple, close to what we know
● Not easy for more advanced uses
○ games, finance, collaboration
Web Messaging
● WebSocket protocol
○ bi-directional messaging between client & server
● SockJS fallback
○ WebSocket emulation (IE < 10, proxy issues, etc.)
● STOMP
○ Simple messaging sub-protocol
○ Like HTTP over TCP
Why not just WebSocket?
● Too low level
● Practically a TCP socket
● Just like HTTP enables RESTful
architecture, STOMP enables messaging
● In the absence of a protocol, a custom
protocol will have to be used
Example STOMP Frame
SEND
destination:/app/greetings
content-type:text/plain
Hello world!
Handle a Message
@Controller
public class PortfolioController {
@MessageMapping("/greetings")
public void add(String payload) { … }
}
Messaging + REST
@Controller
public class PortfolioController {
@MessageMapping("/greetings")
public void add(String payload) { … }
@RequestMapping("/greetings", method=GET)
public String get() { … }
}
SockJS
● Exact same WebSocket API
● Different transports underneath
○ long polling, HTTP streaming
● Wide range of browsers and versions
● WebSocket alone not practically usable
without fallback options today
WebSocket Continued
See presentation:
https://github.com/rstoyanchev/
springx2013-websocket
There is also a video available.
Spring Boot
● You are an expert but how long would it take
you to start a new web application?
● Lot of choices to be made
● Boot makes reasonable default choices
● So you can be up and running in minutes
Spring Boot Web App
@RestController
@EnableAutoConfiguration
public class Example {
public static void main(String[] args) {
SpringApplication.run(Example.class, args);
}
@RequestMapping("/")
public String home() {
return "Hello World!";
}
}
REST API Docs
● Good REST API documentation can not be
fully generated
● Every good API guide has some stories and
use cases with example usage
● Yet manually writing it all is too much
Spring REST Docs
● What if you could write real tests that
demonstrate your REST API?
● Using Spring MVC Test...
● Then insert the code w/ actual output in your
Asciidoctor documentation
Spring REST Docs Continued
Check out this webinar by Andy Wilkinson
Server-Sent Events v4.2
@RequestMapping
public ResponseEntity<SseEmitter> handle() {
SseEmitter emitter = new SseEmitter();
// ...
return emitter;
}
// Later from another thread
emitter.send(event().name("foo").data(foo));
…
emitter.complete();
Server-Sent Events v4.2
@RequestMapping
public ResponseEntity<SseEmitter> handle() {
if ( … ) {
return ResponseEntity.status(204).body(null);
}
else {
// …
ResponseEntity.ok(sseEmitter);
}
}
SPR-12672
HTTP Caching v4.2
● Comprehensive update according to the
most recent HTTP 1.1. spec updates
● Central and per-request support for all
Cache-Control directives
● A deep eTag strategy
SPR-11792
CORS v4.2
● Built-in support within Spring MVC
● Both central and fine-grained
● @CrossOrigin
● CorsConfigurationSource
SPR-9278
Custom @RequestMapping v4.2
@RequestMapping(
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE
consumes = MediaType.APPLICATION_JSON_VALUE)
public @interface PostJson {
String value() default "";
}
@PostJson("/input")
public Output myMethod(Input input) {
}
SPR-12296
JavaScript Templating v4.2
● Server-side JavaScript templates
● See very long SPR-12266
● Current plan is to plug Nashorn (JDK 1.8)
behind the ViewResolver/View contracts
● Much like we did for Groovy in 4.1
STOMP Client v4.2
● There aren’t any good Java clients
● So we’ve decided to write one
● Good for testing at least
● Like we added SockJS Java client in 4.1
SPR-11588
Topical Guides
● Part of effort to overhaul Spring Framework
reference documentation
● Separate “conceptual” information from
pure reference
● Example guides
○ “What is Spring”, “Intro to Spring Config”, etc.
● Track topical-guides repo
Questions
http://twitter.com/rstoya05
http://pivotal.io

More Related Content

What's hot (19)

PPT
Spring MVC
yuvalb
 
PPTX
The Past Year in Spring for Apache Geode
VMware Tanzu
 
PPT
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
PPTX
Spring MVC
Emprovise
 
PPT
Java Server Faces (JSF) - Basics
BG Java EE Course
 
PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PPTX
Spring Web MVC
zeeshanhanif
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
ODP
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
ODP
Spring 4 advanced final_xtr_presentation
sourabh aggarwal
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PDF
Spring Framework - AOP
Dzmitry Naskou
 
PDF
Spring MVC
Aaron Schram
 
PDF
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Sam Brannen
 
PPT
Struts,Jsp,Servlet
dasguptahirak
 
PDF
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
PDF
the Spring 4 update
Joshua Long
 
PDF
Introduction to Spring Framework
Rajind Ruparathna
 
PDF
Lecture 3: Servlets - Session Management
Fahad Golra
 
Spring MVC
yuvalb
 
The Past Year in Spring for Apache Geode
VMware Tanzu
 
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
Spring MVC
Emprovise
 
Java Server Faces (JSF) - Basics
BG Java EE Course
 
Java servlet life cycle - methods ppt
kamal kotecha
 
Spring Web MVC
zeeshanhanif
 
Spring Framework - Core
Dzmitry Naskou
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Spring 4 advanced final_xtr_presentation
sourabh aggarwal
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Spring Framework - AOP
Dzmitry Naskou
 
Spring MVC
Aaron Schram
 
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Sam Brannen
 
Struts,Jsp,Servlet
dasguptahirak
 
Lecture 7 Web Services JAX-WS & JAX-RS
Fahad Golra
 
the Spring 4 update
Joshua Long
 
Introduction to Spring Framework
Rajind Ruparathna
 
Lecture 3: Servlets - Session Management
Fahad Golra
 

Viewers also liked (11)

PDF
Spring MVC Annotations
Jordan Silva
 
DOCX
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
PDF
Spring 4 - A&BP CC
JWORKS powered by Ordina
 
PDF
Spring MVC - The Basics
Ilio Catallo
 
PPTX
Introduction to Spring Framework
Dineesha Suraweera
 
PDF
Ajug - The Spring Update
Gunnar Hillert
 
PDF
Spring4 whats up doc?
David Gómez García
 
PPTX
The Spring Framework: A brief introduction to Inversion of Control
VisualBee.com
 
PDF
Spring mvc my Faviourite Slide
Daniel Adenew
 
PDF
Spring 3 Annotated Development
kensipe
 
PDF
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Raghavan Mohan
 
Spring MVC Annotations
Jordan Silva
 
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
Spring 4 - A&BP CC
JWORKS powered by Ordina
 
Spring MVC - The Basics
Ilio Catallo
 
Introduction to Spring Framework
Dineesha Suraweera
 
Ajug - The Spring Update
Gunnar Hillert
 
Spring4 whats up doc?
David Gómez García
 
The Spring Framework: A brief introduction to Inversion of Control
VisualBee.com
 
Spring mvc my Faviourite Slide
Daniel Adenew
 
Spring 3 Annotated Development
kensipe
 
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Raghavan Mohan
 
Ad

Similar to Spring 4 Web App (20)

PDF
RESTEasy
Massimiliano Dessì
 
PDF
May 2010 - RestEasy
JBug Italy
 
PDF
Spring Web Services: SOAP vs. REST
Sam Brannen
 
PDF
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
PDF
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
Serdar Basegmez
 
PDF
Nodejs and WebSockets
Gonzalo Ayuso
 
PDF
05 status-codes
snopteck
 
PPT
CTS Conference Web 2.0 Tutorial Part 2
Geoffrey Fox
 
PPTX
Mail OnLine Android Application at DroidCon - Turin - Italy
Yahoo
 
PDF
5.node js
Geunhyung Kim
 
PDF
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
PPTX
Understanding ASP.NET Under The Cover - Miguel A. Castro
Mohammad Tayseer
 
PPT
Using Ajax In Domino Web Applications
dominion
 
ODP
Oredev 2009 JAX-RS
Niklas Gustavsson
 
PPT
Ajax
rahmed_sct
 
PDF
Hexagonal architecture in PHP
Paulo Victor Gomes
 
PPTX
Module design pattern i.e. express js
Ahmed Assaf
 
PDF
An approach to responsive, realtime with Backbone.js and WebSockets
Andrei Sebastian Cîmpean
 
PPT
Building+restful+webservice
lonegunman
 
May 2010 - RestEasy
JBug Italy
 
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
Serdar Basegmez
 
Nodejs and WebSockets
Gonzalo Ayuso
 
05 status-codes
snopteck
 
CTS Conference Web 2.0 Tutorial Part 2
Geoffrey Fox
 
Mail OnLine Android Application at DroidCon - Turin - Italy
Yahoo
 
5.node js
Geunhyung Kim
 
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Mohammad Tayseer
 
Using Ajax In Domino Web Applications
dominion
 
Oredev 2009 JAX-RS
Niklas Gustavsson
 
Hexagonal architecture in PHP
Paulo Victor Gomes
 
Module design pattern i.e. express js
Ahmed Assaf
 
An approach to responsive, realtime with Backbone.js and WebSockets
Andrei Sebastian Cîmpean
 
Building+restful+webservice
lonegunman
 
Ad

More from Rossen Stoyanchev (6)

PDF
Reactive Web Applications
Rossen Stoyanchev
 
PDF
Spring MVC 4.2: New and Noteworthy
Rossen Stoyanchev
 
PDF
Intro To Reactive Programming
Rossen Stoyanchev
 
PDF
Resource Handling in Spring MVC 4.1
Rossen Stoyanchev
 
PDF
Testing Web Apps with Spring Framework 3.2
Rossen Stoyanchev
 
PDF
Spring 3.1 Features Worth Knowing About
Rossen Stoyanchev
 
Reactive Web Applications
Rossen Stoyanchev
 
Spring MVC 4.2: New and Noteworthy
Rossen Stoyanchev
 
Intro To Reactive Programming
Rossen Stoyanchev
 
Resource Handling in Spring MVC 4.1
Rossen Stoyanchev
 
Testing Web Apps with Spring Framework 3.2
Rossen Stoyanchev
 
Spring 3.1 Features Worth Knowing About
Rossen Stoyanchev
 

Recently uploaded (20)

PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Tally software_Introduction_Presentation
AditiBansal54083
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 

Spring 4 Web App

  • 1. Spring 4 Web Applications Rossen Stoyanchev Pivotal Inc
  • 2. About the speaker ● Spring Framework committer ● Spring MVC ● Spring WebSocket and Messaging
  • 3. Spring MVC ● Since 2003 (circa JDK 1.4) ● Before Java annotations, REST, SPAs, ... ● Continued success, evolution ● Most popular status today
  • 4. Programming Model Evolution ● @Controller ………...………... 2.5 (2007) ● REST …………………………….. 3.0 (2009) ● Async requests ……………….. 3.2 (2012) ● WebSocket messaging …….. 4.0 (2013)
  • 5. ● Simple, clean design at the core ● Friendly to extension ● Embraces HTTP and REST ● Community requests Keys to Success
  • 6. Always Evolving ● One of most actively developed parts of Spring Framework ● Continuous flow of ideas and requests from the community ● Improvements, new features, even modules with each new version
  • 8. @RestController @RestController public class MyController { @RequestMapping @ResponseBody public Foo handle() { … } @RequestMapping @ResponseBody public Bar handle() { … } }
  • 10. Selectors @ControllerAdvice => “Apply to every @Controller” @ControllerAdvice(basePackages = "org.app.module") @ControllerAdvice(annotations = RestController.class) @ControllerAdvice(assignableTypes = {BaseController1.class, BaseController2.class})
  • 11. ResponseEntityExceptionHandler ● Base class for use with @ControllerAdvice ● Handle Spring MVC exceptions ● REST API error details in response body
  • 12. ResponseBodyAdvice ● Interface for use with @ControllerAdvice ● Customize response before @ResponseBody & ResponseEntity are written ● Built-in usages ○ @JsonView on @RequestMapping methods ○ JSONP
  • 13. Further Jackson Support ● Use Jackson for both JSON and XML ● ObjectMapper builder ● Highly recommended read: https://spring.io/blog/2014/12/02/ latest-jackson-integration- improvements-in-spring
  • 14. @RequestMapping methods ● java.util.Optional (JDK 1.8) support ● ListenableFuture return value ● ResponseEntity/RequestEntity builders ● Links to @MVC methods ● @ModelAttribute method ordering
  • 15. ResponseEntityBuilder String body = "Hello"; HttpHeaders hdrs = new HttpHeaders() headers.setLocation(location); new ResponseEntity<String>(body, hdrs, CREATED); vs ResponseEntity.created(location).body("Hello");
  • 16. RequestEntityBuilder HttpHeaders headers = new HttpHeaders(); headers.setAccept(MediaType.APPLICATION_JSON); new HttpEntity("Hello", headers); vs RequestEntity.post(uri) .accept(MediaType.APPLICATION_JSON) .body("Hello");
  • 17. Link to @RequestMapping ● Simulate controller method invocation fromMethodCall(on(MyController.class).getAddress("US")) .buildAndExpand(1).toUri(); ● Uses proxy, similar to testing w/ mocks ● See section on Building URIs
  • 18. How to link from views? ● Refer to @RequestMapping by name ● Default name assigned to every mapping ○ or use @RequestMapping(name=”..”) ● See subsection in Building URIs
  • 19. @ModelAttribute Ordering <- Call this 1st @ModelAttribute("foo") public Object getFoo() { } @ModelAttribute("bar") public Object getBar(@ModelAttribute("foo") Object foo) { } Uses “foo” Creates “foo”
  • 20. Static Resources ● Key topic for web applications today ○ Optimize .. minify, concatenate ○ Transform .. sass, less ○ HTTP caching .. versioned URLs ○ CDN ○ Prod vs dev
  • 21. Static Resources in 4.1 ● Build on existing ResourceHttpRequestHandler ● Add abstractions to resolve and transform resources in a chain ● Prepare “public” resource URL
  • 22. URL “Fingerprinting” ● HTTP “cache busting” ● Version URL with content-based hash ● Add aggressive cache headers (e.g. +1 year) Example URL: “/css/font-awesome.min-7fbe76cdac.css”
  • 23. Static Resources Continued See Resource Handling talk on Youtube, browse the slides, or check the source code.
  • 24. Groovy Markup Templating ● DRY markup based on Groovy 2.3 ● Like HAML in Ruby on Rails yieldUnescaped '<!DOCTYPE html>' html(lang:'en') { head { title('My page') } body { p('This is an example of HTML contents') } }
  • 25. MVC Config ● We now have ViewResolver registry ● ViewController can do more ○ redirects, 404s, etc. ● Patch matching by popular demand ○ suffix patterns, trailing slashes, etc.
  • 26. Servlet 3 Async Requests ● Since v3.2 ○ Long polling, HTTP streaming ● Server can push events to client ○ chat, tweet stream ● Relatively simple, close to what we know ● Not easy for more advanced uses ○ games, finance, collaboration
  • 27. Web Messaging ● WebSocket protocol ○ bi-directional messaging between client & server ● SockJS fallback ○ WebSocket emulation (IE < 10, proxy issues, etc.) ● STOMP ○ Simple messaging sub-protocol ○ Like HTTP over TCP
  • 28. Why not just WebSocket? ● Too low level ● Practically a TCP socket ● Just like HTTP enables RESTful architecture, STOMP enables messaging ● In the absence of a protocol, a custom protocol will have to be used
  • 30. Handle a Message @Controller public class PortfolioController { @MessageMapping("/greetings") public void add(String payload) { … } }
  • 31. Messaging + REST @Controller public class PortfolioController { @MessageMapping("/greetings") public void add(String payload) { … } @RequestMapping("/greetings", method=GET) public String get() { … } }
  • 32. SockJS ● Exact same WebSocket API ● Different transports underneath ○ long polling, HTTP streaming ● Wide range of browsers and versions ● WebSocket alone not practically usable without fallback options today
  • 34. Spring Boot ● You are an expert but how long would it take you to start a new web application? ● Lot of choices to be made ● Boot makes reasonable default choices ● So you can be up and running in minutes
  • 35. Spring Boot Web App @RestController @EnableAutoConfiguration public class Example { public static void main(String[] args) { SpringApplication.run(Example.class, args); } @RequestMapping("/") public String home() { return "Hello World!"; } }
  • 36. REST API Docs ● Good REST API documentation can not be fully generated ● Every good API guide has some stories and use cases with example usage ● Yet manually writing it all is too much
  • 37. Spring REST Docs ● What if you could write real tests that demonstrate your REST API? ● Using Spring MVC Test... ● Then insert the code w/ actual output in your Asciidoctor documentation
  • 38. Spring REST Docs Continued Check out this webinar by Andy Wilkinson
  • 39. Server-Sent Events v4.2 @RequestMapping public ResponseEntity<SseEmitter> handle() { SseEmitter emitter = new SseEmitter(); // ... return emitter; } // Later from another thread emitter.send(event().name("foo").data(foo)); … emitter.complete();
  • 40. Server-Sent Events v4.2 @RequestMapping public ResponseEntity<SseEmitter> handle() { if ( … ) { return ResponseEntity.status(204).body(null); } else { // … ResponseEntity.ok(sseEmitter); } } SPR-12672
  • 41. HTTP Caching v4.2 ● Comprehensive update according to the most recent HTTP 1.1. spec updates ● Central and per-request support for all Cache-Control directives ● A deep eTag strategy SPR-11792
  • 42. CORS v4.2 ● Built-in support within Spring MVC ● Both central and fine-grained ● @CrossOrigin ● CorsConfigurationSource SPR-9278
  • 43. Custom @RequestMapping v4.2 @RequestMapping( method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE consumes = MediaType.APPLICATION_JSON_VALUE) public @interface PostJson { String value() default ""; } @PostJson("/input") public Output myMethod(Input input) { } SPR-12296
  • 44. JavaScript Templating v4.2 ● Server-side JavaScript templates ● See very long SPR-12266 ● Current plan is to plug Nashorn (JDK 1.8) behind the ViewResolver/View contracts ● Much like we did for Groovy in 4.1
  • 45. STOMP Client v4.2 ● There aren’t any good Java clients ● So we’ve decided to write one ● Good for testing at least ● Like we added SockJS Java client in 4.1 SPR-11588
  • 46. Topical Guides ● Part of effort to overhaul Spring Framework reference documentation ● Separate “conceptual” information from pure reference ● Example guides ○ “What is Spring”, “Intro to Spring Config”, etc. ● Track topical-guides repo