SlideShare a Scribd company logo
1 of 64
Download to read offline
SPRINGONE2GX
WASHINGTON, DC
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring MVC 4.2:
New and Noteworthy
Rossen Stoyanchev
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
About Me
• Spring Framework committer
• Spring MVC
• Spring WebSocket
2
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo Source
3
https://github.com/rstoyanchev/
s2gx2015-spring-mvc-42
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
HTTP Streaming
4
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring 3.2: Async Request Handling
• The ability to get off the Servlet container thread
• Take any controller method
• replace return value T with DeferredResult<T>
• Range of use cases
• long polling -- chat, live events
• processing with latency -- scatter-gather, microservices
• Easy to introduce into existing apps
5
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring 4.0: WebSocket Messaging
• Full duplex messaging with SockJS emulation
• STOMP for application messaging
• simple or external broker
• @MessagingMapping methods for application work
• More advanced messaging needs
• collaboration, games
• Very different from REST -- messaging architecture
6
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• Return ResponseBodyEmitter rather than @ResponseBody
• Or ResponseEntity<ResponseBodyEmitter>
• Stream of serialized Objects, emitted from any thread
• Objects serialized with HttpMessageConverter
Spring 4.2: HTTP Streaming
7
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Example
@RequestMapping(path = "/stream", method = GET)
public ResponseBodyEmitter startStream() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
...
return emitter;
}
// Later on
emitter.send(foo, MediaType.APPLICATION_JSON);
...
emitter.send(bar, MediaType.APPLICATION_JSON);
...
emitter.complete();
8
MediaType used
to select a
converter
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• Store ResponseBodyEmitter instances
• in controller
• in another component where events received
• Use onCompletion callback (on emitter) to remove instance
• Manual pub-sub to connected users
• Compare to STOMP + WebSocket
• messaging protocol with built-in pub-sub
Pub-Sub
9
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• Return SseEmitter, an extension of ResponseBodyEmitter
• HTTP streaming with event markup
Spring 4.2: Server-Sent Events
10
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Example
@RequestMapping(path = "/stream", method = GET)
public SseEmitter startStream() {
SseEmitter emitter = new SseEmitter();
...
return emitter;
}
// Later on
emitter.send(event().event().id("id").name("type").data(foo));
...
emitter.complete();
11
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring 4.2: Direct Streaming
• No serialization with HttpMessageConverter
• Stream directly to the response
• Return StreamingResponseBody instead of @ResponseBody
• ResponseEntity<StreamingResponseBody>
12
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Example
@RequestMapping(path = "/stream", method = GET)
public StreamingResponseBody handle() {
return new StreamingResponseBody() {
@Override
public void writeTo(OutputStream os) throws IOException {
os.write(...);
os.flush();
}
};
}
13
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
HTTP Streaming vs WebSocket Messaging
• HTTP Streaming / SSE -- suited for simple streaming needs
• metrics, feeds
• STOMP / WebSocket scales to more advanced needs
• finance, collaboration, games
• SockJS has lots of built-in smarts
• fallback to polling if network/proxy prevents streaming
• the extra mile for extra range of browsers
14
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CORS
15
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CORS Overview
• Browsers prohibit requests to a different domain
• e.g. evil.com → bank.com
• CORS is a W3C specification for cross-domain requests
• For “simple” methods (GET, HEAD, POST)
• browser sets Origin header
• Otherwise “preflight” request to obtain permission
• HTTP OPTIONS
• Origin and Access-Control-Request-Method headers
16
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CORS Support in Spring?
• Tomcat, Jetty, others provide CORS Filter implementations
• First-class support within Spring however still beneficial
• More fine-grained control (based on request mappings)
• Layer central + local configuration
17
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Local Configuration for @Controller
• New @CrossOrigin annotation
• Supported on individual @RequestMapping methods
• Inherited from the class level
• Easy to configure one method or entire controller class hierarchy
18
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Local Configuration for Simple Handlers
• Implement CorsConfigurationSource
• Two built-in handlers that make use this contract
• ResourceHttpRequestHandler
• SockJsHttpRequestHandler
public interface CorsConfigurationSource {
CorsConfiguration getCorsConfiguration(HttpServletRequest req);
}
19
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Central Configuration
• The MVC Java config and MVC namespace expose CORS configuration
• Centralized configuration alternative
• URL patterns based
• Layer central + local configuration
• e.g. define general policy (e.g. allow csrf-token header)
• refine locally
20
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
More on CORS Configuration
• AbstractHandlerMapping drives overall CORS handling
• It’s an internal feature that’s always on
• cross-domain not allowed by default (as before)
• DispatcherServlet allows preflight requests in for handling
• no need to set dispatchOptionsRequest
21
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring MVC CORS and Spring Security
• DispatcherServlet now provides CORS handling
• Spring Security needs to open HTTP OPTIONS (for preflight requests)
• There is work planned to improve this
• only allow preflight requests with Spring MVC
22
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CorsFilter
• Filter-based approach to CORS configuration
• Comparable to Tomcat, Jetty filters
• CORS handling strictly before DispatcherServlet
• CorsFilter can/should be ordered before Spring Security Filter chain
23
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
HTTP Caching
24
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Goals
• Update default settings in line with current browsers/proxies
• Improve options local to @MVC controllers
• Provide use-case oriented + advanced config
• Various other improvements
• Cache-Control directives, eTag/LastModified support
25
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CacheControl
• Convenient “Cache-Control” response header value builder
• Covers the common use cases
• CacheControl.maxAge(...)# cache for...
• CacheControl.noStore() # prevent cache
• CacheControl.noCache() # conditional cache + eTag/lastModified
• And the advanced
• CacheControl.maxAge(...).noTransform().cachePublic()
26
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
WebContentGenerator
• Central HTTP cache configuration class
• WebContentInterceptor, ResourceHttpRequestHandler
• Defaults settings revised
• no more HTTP 1.0 headers (“Expires” and “Pragma”)
• cacheSeconds shortcut relies CacheControl
• Accepts CacheControl builder for its configuration
• Plus existing cacheSeconds shortcut (becomes CacheControl)
27
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@MVC
• ResponseEntity supports HTTP cache settings
ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS))
.eTag(version) // lastModified also available
.body(book);
• Sets response headers + checks client conditional headers
• Sends 304 (“not modified”) if eTag matches
28
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@MVC Continued
• Explicit eTag / lastModified checks also possible
@RequestMapping
public Object handle(WebRequest request) {
long lastModified = ...
if (request.checkNotModified(lastModified)) {
return null;
}
// ...
}
• Possible to check both eTag + lastModified (per recommendation)
• request.checkNotModified(eTag,lastModified)
29
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Resource Handling
• Extended HTTP cache control for serving static resources
• MVC Java config
• ResourceHandlerRegistry accepts CacheControl
• MVC XML namespace
• <mvc:cache-control> element within <mvc:resources>
• eTag added when VersionResourceResolver is configured
30
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Additional Reading
• HTTP Caching Tutorial by Mark Nottingham
• Reference documentation HTTP Caching Support
• Notes in Migration from earlier versions wiki page
31
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Composable
@RequestMapping
32
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Custom @RequestMapping
• For example:
@PostJson("/input")
public Object handle() {
return … ;
}
• Given custom annotation:
@RequestMapping(method=GET, produces="application/json")
public @interface PostJson {
String value() default "";
}
33
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Shortcut Annotations?
• Proposal to provide built-in shortcut annotations
• The challenge is finding the right mix
• Feedback based on specific use cases would help greatly
• SPR-13442 and spring-composed project
34
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Jackson
35
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Selective Serialization with @JsonView
• Supported on @RequestMapping methods (since 4.1)
@RequestMapping
@JsonView(SummaryView.class)
public ResponseEntity<Foo> handle() {
// …
}
• Now also with @RequestBody
@RequestMapping (method = POST)
public void handle(@JsonView(SummaryView.class) @RequestBody Foo foo) {
// ...
}
36
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Jackson Modules
• Jackson2ObjectMapperBuilder auto-registers Jackson modules
• jdk7, joda, jsr310, jdk8
• Conditional on classpath detection of target dependencies
• Both MVC Java config and XML namespace use
Jackson2ObjectMapperBuilder
37
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@MVC
38
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Programming Model
• HandlerMethod argument for @ExceptionHandler methods
• could be handy with @ControllerAdvice
• CharSequence as controller method return value (alternative to String)
• groovy.lang.GString, StringBuilder, StringBuffer
• @InitBinder methods can register Formatter for specific field(s)
• otherwise typically global in ConversionService
39
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Async Return Value Types
• Built-in support for
• org.springframework.util.concurrent.ListenableFuture (4.1)
• java.util.concurrent.CompletionStage (4.2)
• Both adapted to DeferredResult
• Easy to adapt others
• RxJava Observable, Reactor Stream, …
• Follow example of built-in types
40
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
JavaScript Templating
41
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Why?
• Traditionally HTML served then enhanced with JavaScript
• Trend towards generating the UI with JavaScript
• Address challenges for single-page apps
• As well as mobile devices
42
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
React JavaScript Library
• Developed at Facebook and Instagram
• Virtual DOM with automatic DOM updates, fast, efficient
• Supports server-side rendering (outside of DOM)
• Fast adoption by major Internet players
• Facebook/Instagram, Yahoo!, Netflix, Airbnb, etc.
43
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Server-Side Rendering
• For React adopters, server-side rendering has significant benefits
• Faster load time, pre-generated HTML for web apps
• Search-engine friendly
• Client-centric UI still possible (e.g. Phonegap)
44
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring 4.2 and React
• New view templating choice for JSR-223 scripting engines
• ScriptTemplateView , ViewResolver, and Configurer
• Configuration very similar to the alternatives (e.g. FreeMarker)
• Use with Nashorn JavaScript engine from JDK 8
45
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Additional Talks
Isomorphic Templating With Spring Boot, Nashorn and React
by Sebastien Deleuze
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js
by Matt Raible
46
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
HTTP Byte Ranges
47
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Byte Ranges
• HTTP 1.1 supports ability to download partial content
• RFC 7233
• Server advertises willingness via Accept-Ranges response header
• Client can then send a Range request header
• e.g. Range: bytes=500-999
• Large media files, request any part / resume …
48
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Byte Range Support in Spring 4.2
• HttpRange to create and parse ranges
• Accept-Range and Range exposed in HttpHeaders
• ResourceHttpRequestHandler supports byte ranges
• e.g. server video files to iOS devices
49
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
$ curl -v --range 0-99 
http://localhost:8080/assets/jquery-2.1.4.js
> GET /assets/jquery-2.1.4.js HTTP/1.1
> Range: bytes=0-99
...
< HTTP/1.1 206 Partial Content
< ...
< Accept-Ranges: bytes
< Content-Range: bytes 0-99/247597
< Content-Length: 100
< ...
50
Example
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Client Side
51
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
RestTemplate with OkHttp
• RestTemplate + AsyncRestTemplate can be used with OkHttp
• lightweight HTTP library
• HTTP library support
• JDK
• Apache HttpComponents
• Netty
• OkHttp
52
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Flexible URI Template Handling
• UriTemplateHandler for use with RestTemplate
• Default implementation delegates to UriComponentsBuilder
• Can be configured to
• insert prefix in all URI templates
• switch from path to path segment encoding by default
• Potential to plug in 3rd party URI template library
• e.g. full RFC 6570 syntax
53
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
WebSocket Messaging
54
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Simple Broker: Heartbeats
@Configuration
@EnableWebSocketMessageBroker
static class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
// …
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic").setTaskScheduler(scheduler());
}
@Bean @Primary
public TaskScheduler scheduler() {
return new ThreadPoolTaskScheduler();
}
}
55
Enable
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Simple Broker: Selector Expression
56
• Add selector header on subscribe
client.subscribe("/topic/interval",
function(message) {
// ...
},
{'selector' : 'headers.parity == 'even''});
• SpEL expression evaluated against messages
• Only matching messages received
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Multi-Server User Destinations
57
• Spring supported special STOMP destination
• /user/{username}/…
• User receives message if connected
• User can be connected to any application server (since 4.2)
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Multi-Server User Destinations
58
Spring App
RabbitMQ
Browser
Sergi
/user/sergi/…
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Connected User Information
• SimpUserRegistry bean
• Expose information about connected users and subscriptions
• Supported in multi-server scenarios
• via UserRegistryMessageHandler
• Broadcast local user registry to other servers (via broker relay)
• every 10 seconds
• remote registry info expires after 20 seconds
59
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
STOMP Client
• Supported over WebSocket + over TCP
• Plug in any Spring WebSocketClient implementation
• SockJsClient allows using STOMP over WebSocket/SockJS
• Support for heartbeats, receipts
60
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Programming Model
• Property placeholders for @MessageMapping methods
• @JsonView on @Payload arguments
• Destination template variables in @SendTo annotation
• Async return value types
• org.springframework.util.concurrent.ListenableFuture
• CompletableFuture/CompletionStage (JDK 8)
61
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Programming Model
• @ControllerAdvice + @MessageExceptionHandler methods
• HandlerMethod arguments for @MessageExceptionHandler
• Spring OXM Marshaller based MessageConverter
62
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Related Talk
From Zero to Hero with Spring WebSocket
by Sergi Almar
63
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 64
Thank You for Listening!
@rstoya05
Learn More. Stay Connected.
@springcentral Spring.io/video

More Related Content

What's hot

Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)VMware Tanzu
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishArun Gupta
 
JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?Edward Burns
 
Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)VMware Tanzu
 
How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?Ksenia Peguero
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reza Rahman
 
Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...Codemotion
 
Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Edward Burns
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsArun Gupta
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming PrimerIvano Malavolta
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web APIDamir Dobric
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015Edward Burns
 
Survey of restful web services frameworks
Survey of restful web services frameworksSurvey of restful web services frameworks
Survey of restful web services frameworksVijay Prasad Gupta
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009kensipe
 
Enterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQEnterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQRob Davies
 

What's hot (18)

Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
 
JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?JavaOne 2014 BOF4241 What's Next for JSF?
JavaOne 2014 BOF4241 What's Next for JSF?
 
Docker meetup-nyc-v1
Docker meetup-nyc-v1Docker meetup-nyc-v1
Docker meetup-nyc-v1
 
Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)
 
How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?
 
Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!Reactive Java EE - Let Me Count the Ways!
Reactive Java EE - Let Me Count the Ways!
 
Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...Refactor your Java EE application using Microservices and Containers - Arun G...
Refactor your Java EE application using Microservices and Containers - Arun G...
 
Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015Servlet 4.0 at GeekOut 2015
Servlet 4.0 at GeekOut 2015
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web API
 
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015HTTP/2 comes to Java.  What Servlet 4.0 means to you. DevNexus 2015
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
 
Survey of restful web services frameworks
Survey of restful web services frameworksSurvey of restful web services frameworks
Survey of restful web services frameworks
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Enterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQEnterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQ
 

Viewers also liked

Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Rossen Stoyanchev
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Chris Richardson
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkDmytro Chyzhykov
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the RESTRoy Clarkson
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC frameworkMohit Gupta
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 updateJoshua Long
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC AnnotationsJordan Silva
 
Leadership howard county 03 28 12 jenn lim delivering happiness
Leadership howard county 03 28 12 jenn lim delivering happinessLeadership howard county 03 28 12 jenn lim delivering happiness
Leadership howard county 03 28 12 jenn lim delivering happinessDelivering Happiness
 
Actividades de reflexion incial la ofimatica
Actividades de reflexion incial la ofimaticaActividades de reflexion incial la ofimatica
Actividades de reflexion incial la ofimaticaNeiver Ramirez Perez
 

Viewers also liked (17)

Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2Testing Web Apps with Spring Framework 3.2
Testing Web Apps with Spring Framework 3.2
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the REST
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Get ready for spring 4
Get ready for spring 4Get ready for spring 4
Get ready for spring 4
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
Leadership howard county 03 28 12 jenn lim delivering happiness
Leadership howard county 03 28 12 jenn lim delivering happinessLeadership howard county 03 28 12 jenn lim delivering happiness
Leadership howard county 03 28 12 jenn lim delivering happiness
 
Actividades de reflexion incial la ofimatica
Actividades de reflexion incial la ofimaticaActividades de reflexion incial la ofimatica
Actividades de reflexion incial la ofimatica
 

Similar to Spring MVC 4.2: New and Noteworthy

Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET MicroservicesVMware Tanzu
 
Running Java Applications on Cloud Foundry
Running Java Applications on Cloud FoundryRunning Java Applications on Cloud Foundry
Running Java Applications on Cloud FoundryVMware Tanzu
 
Spring Integration Done Bootifully
Spring Integration Done BootifullySpring Integration Done Bootifully
Spring Integration Done BootifullyGlenn Renfro
 
Building a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / SpringBuilding a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / Springsdeeg
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive ProgrammingStéphane Maldini
 
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...VMware Tanzu
 
Designing, Implementing, and Using Reactive APIs
Designing, Implementing, and Using Reactive APIsDesigning, Implementing, and Using Reactive APIs
Designing, Implementing, and Using Reactive APIsVMware Tanzu
 
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...VMware Tanzu
 
What's new in Spring Boot 2.0
What's new in Spring Boot 2.0What's new in Spring Boot 2.0
What's new in Spring Boot 2.0VMware Tanzu
 
Cloud-Native Streaming and Event-Driven Microservices
Cloud-Native Streaming and Event-Driven MicroservicesCloud-Native Streaming and Event-Driven Microservices
Cloud-Native Streaming and Event-Driven MicroservicesVMware Tanzu
 
Federated Queries with HAWQ - SQL on Hadoop and Beyond
Federated Queries with HAWQ - SQL on Hadoop and BeyondFederated Queries with HAWQ - SQL on Hadoop and Beyond
Federated Queries with HAWQ - SQL on Hadoop and BeyondChristian Tzolov
 
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...VMware Tanzu
 
Building Highly Scalable Spring Applications using In-Memory Data Grids
Building Highly Scalable Spring Applications using In-Memory Data GridsBuilding Highly Scalable Spring Applications using In-Memory Data Grids
Building Highly Scalable Spring Applications using In-Memory Data GridsJohn Blum
 
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...VMware Tanzu
 
Deploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on KubernetesDeploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on KubernetesVMware Tanzu
 
Connecting All Abstractions with Istio
Connecting All Abstractions with IstioConnecting All Abstractions with Istio
Connecting All Abstractions with IstioVMware Tanzu
 
Cloud Foundry UAA as an Identity Gateway
Cloud Foundry UAA as an Identity GatewayCloud Foundry UAA as an Identity Gateway
Cloud Foundry UAA as an Identity GatewayVMware Tanzu
 
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...confluent
 
It’s a Multi-Cloud World, But What About The Data?
It’s a Multi-Cloud World, But What About The Data?It’s a Multi-Cloud World, But What About The Data?
It’s a Multi-Cloud World, But What About The Data?VMware Tanzu
 

Similar to Spring MVC 4.2: New and Noteworthy (20)

Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET Microservices
 
Extreme Pipelines
Extreme PipelinesExtreme Pipelines
Extreme Pipelines
 
Running Java Applications on Cloud Foundry
Running Java Applications on Cloud FoundryRunning Java Applications on Cloud Foundry
Running Java Applications on Cloud Foundry
 
Spring Integration Done Bootifully
Spring Integration Done BootifullySpring Integration Done Bootifully
Spring Integration Done Bootifully
 
Building a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / SpringBuilding a Secure App with Google Polymer and Java / Spring
Building a Secure App with Google Polymer and Java / Spring
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive Programming
 
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
 
Designing, Implementing, and Using Reactive APIs
Designing, Implementing, and Using Reactive APIsDesigning, Implementing, and Using Reactive APIs
Designing, Implementing, and Using Reactive APIs
 
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
 
What's new in Spring Boot 2.0
What's new in Spring Boot 2.0What's new in Spring Boot 2.0
What's new in Spring Boot 2.0
 
Cloud-Native Streaming and Event-Driven Microservices
Cloud-Native Streaming and Event-Driven MicroservicesCloud-Native Streaming and Event-Driven Microservices
Cloud-Native Streaming and Event-Driven Microservices
 
Federated Queries with HAWQ - SQL on Hadoop and Beyond
Federated Queries with HAWQ - SQL on Hadoop and BeyondFederated Queries with HAWQ - SQL on Hadoop and Beyond
Federated Queries with HAWQ - SQL on Hadoop and Beyond
 
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...
Simple Data Movement Patterns: Legacy Application to Cloud-Native Environment...
 
Building Highly Scalable Spring Applications using In-Memory Data Grids
Building Highly Scalable Spring Applications using In-Memory Data GridsBuilding Highly Scalable Spring Applications using In-Memory Data Grids
Building Highly Scalable Spring Applications using In-Memory Data Grids
 
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
 
Deploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on KubernetesDeploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on Kubernetes
 
Connecting All Abstractions with Istio
Connecting All Abstractions with IstioConnecting All Abstractions with Istio
Connecting All Abstractions with Istio
 
Cloud Foundry UAA as an Identity Gateway
Cloud Foundry UAA as an Identity GatewayCloud Foundry UAA as an Identity Gateway
Cloud Foundry UAA as an Identity Gateway
 
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
 
It’s a Multi-Cloud World, But What About The Data?
It’s a Multi-Cloud World, But What About The Data?It’s a Multi-Cloud World, But What About The Data?
It’s a Multi-Cloud World, But What About The Data?
 

Recently uploaded

Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 

Recently uploaded (20)

Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 

Spring MVC 4.2: New and Noteworthy

  • 1. SPRINGONE2GX WASHINGTON, DC Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring MVC 4.2: New and Noteworthy Rossen Stoyanchev
  • 2. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About Me • Spring Framework committer • Spring MVC • Spring WebSocket 2
  • 3. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo Source 3 https://github.com/rstoyanchev/ s2gx2015-spring-mvc-42
  • 4. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Streaming 4
  • 5. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 3.2: Async Request Handling • The ability to get off the Servlet container thread • Take any controller method • replace return value T with DeferredResult<T> • Range of use cases • long polling -- chat, live events • processing with latency -- scatter-gather, microservices • Easy to introduce into existing apps 5
  • 6. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.0: WebSocket Messaging • Full duplex messaging with SockJS emulation • STOMP for application messaging • simple or external broker • @MessagingMapping methods for application work • More advanced messaging needs • collaboration, games • Very different from REST -- messaging architecture 6
  • 7. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Return ResponseBodyEmitter rather than @ResponseBody • Or ResponseEntity<ResponseBodyEmitter> • Stream of serialized Objects, emitted from any thread • Objects serialized with HttpMessageConverter Spring 4.2: HTTP Streaming 7
  • 8. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public ResponseBodyEmitter startStream() { ResponseBodyEmitter emitter = new ResponseBodyEmitter(); ... return emitter; } // Later on emitter.send(foo, MediaType.APPLICATION_JSON); ... emitter.send(bar, MediaType.APPLICATION_JSON); ... emitter.complete(); 8 MediaType used to select a converter
  • 9. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Store ResponseBodyEmitter instances • in controller • in another component where events received • Use onCompletion callback (on emitter) to remove instance • Manual pub-sub to connected users • Compare to STOMP + WebSocket • messaging protocol with built-in pub-sub Pub-Sub 9
  • 10. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Return SseEmitter, an extension of ResponseBodyEmitter • HTTP streaming with event markup Spring 4.2: Server-Sent Events 10
  • 11. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public SseEmitter startStream() { SseEmitter emitter = new SseEmitter(); ... return emitter; } // Later on emitter.send(event().event().id("id").name("type").data(foo)); ... emitter.complete(); 11
  • 12. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.2: Direct Streaming • No serialization with HttpMessageConverter • Stream directly to the response • Return StreamingResponseBody instead of @ResponseBody • ResponseEntity<StreamingResponseBody> 12
  • 13. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public StreamingResponseBody handle() { return new StreamingResponseBody() { @Override public void writeTo(OutputStream os) throws IOException { os.write(...); os.flush(); } }; } 13
  • 14. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Streaming vs WebSocket Messaging • HTTP Streaming / SSE -- suited for simple streaming needs • metrics, feeds • STOMP / WebSocket scales to more advanced needs • finance, collaboration, games • SockJS has lots of built-in smarts • fallback to polling if network/proxy prevents streaming • the extra mile for extra range of browsers 14
  • 15. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS 15
  • 16. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS Overview • Browsers prohibit requests to a different domain • e.g. evil.com → bank.com • CORS is a W3C specification for cross-domain requests • For “simple” methods (GET, HEAD, POST) • browser sets Origin header • Otherwise “preflight” request to obtain permission • HTTP OPTIONS • Origin and Access-Control-Request-Method headers 16
  • 17. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS Support in Spring? • Tomcat, Jetty, others provide CORS Filter implementations • First-class support within Spring however still beneficial • More fine-grained control (based on request mappings) • Layer central + local configuration 17
  • 18. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Local Configuration for @Controller • New @CrossOrigin annotation • Supported on individual @RequestMapping methods • Inherited from the class level • Easy to configure one method or entire controller class hierarchy 18
  • 19. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Local Configuration for Simple Handlers • Implement CorsConfigurationSource • Two built-in handlers that make use this contract • ResourceHttpRequestHandler • SockJsHttpRequestHandler public interface CorsConfigurationSource { CorsConfiguration getCorsConfiguration(HttpServletRequest req); } 19
  • 20. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Central Configuration • The MVC Java config and MVC namespace expose CORS configuration • Centralized configuration alternative • URL patterns based • Layer central + local configuration • e.g. define general policy (e.g. allow csrf-token header) • refine locally 20
  • 21. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ More on CORS Configuration • AbstractHandlerMapping drives overall CORS handling • It’s an internal feature that’s always on • cross-domain not allowed by default (as before) • DispatcherServlet allows preflight requests in for handling • no need to set dispatchOptionsRequest 21
  • 22. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring MVC CORS and Spring Security • DispatcherServlet now provides CORS handling • Spring Security needs to open HTTP OPTIONS (for preflight requests) • There is work planned to improve this • only allow preflight requests with Spring MVC 22
  • 23. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CorsFilter • Filter-based approach to CORS configuration • Comparable to Tomcat, Jetty filters • CORS handling strictly before DispatcherServlet • CorsFilter can/should be ordered before Spring Security Filter chain 23
  • 24. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Caching 24
  • 25. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Goals • Update default settings in line with current browsers/proxies • Improve options local to @MVC controllers • Provide use-case oriented + advanced config • Various other improvements • Cache-Control directives, eTag/LastModified support 25
  • 26. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CacheControl • Convenient “Cache-Control” response header value builder • Covers the common use cases • CacheControl.maxAge(...)# cache for... • CacheControl.noStore() # prevent cache • CacheControl.noCache() # conditional cache + eTag/lastModified • And the advanced • CacheControl.maxAge(...).noTransform().cachePublic() 26
  • 27. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WebContentGenerator • Central HTTP cache configuration class • WebContentInterceptor, ResourceHttpRequestHandler • Defaults settings revised • no more HTTP 1.0 headers (“Expires” and “Pragma”) • cacheSeconds shortcut relies CacheControl • Accepts CacheControl builder for its configuration • Plus existing cacheSeconds shortcut (becomes CacheControl) 27
  • 28. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC • ResponseEntity supports HTTP cache settings ResponseEntity.ok() .cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)) .eTag(version) // lastModified also available .body(book); • Sets response headers + checks client conditional headers • Sends 304 (“not modified”) if eTag matches 28
  • 29. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC Continued • Explicit eTag / lastModified checks also possible @RequestMapping public Object handle(WebRequest request) { long lastModified = ... if (request.checkNotModified(lastModified)) { return null; } // ... } • Possible to check both eTag + lastModified (per recommendation) • request.checkNotModified(eTag,lastModified) 29
  • 30. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resource Handling • Extended HTTP cache control for serving static resources • MVC Java config • ResourceHandlerRegistry accepts CacheControl • MVC XML namespace • <mvc:cache-control> element within <mvc:resources> • eTag added when VersionResourceResolver is configured 30
  • 31. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Reading • HTTP Caching Tutorial by Mark Nottingham • Reference documentation HTTP Caching Support • Notes in Migration from earlier versions wiki page 31
  • 32. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Composable @RequestMapping 32
  • 33. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Custom @RequestMapping • For example: @PostJson("/input") public Object handle() { return … ; } • Given custom annotation: @RequestMapping(method=GET, produces="application/json") public @interface PostJson { String value() default ""; } 33
  • 34. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Shortcut Annotations? • Proposal to provide built-in shortcut annotations • The challenge is finding the right mix • Feedback based on specific use cases would help greatly • SPR-13442 and spring-composed project 34
  • 35. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Jackson 35
  • 36. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Selective Serialization with @JsonView • Supported on @RequestMapping methods (since 4.1) @RequestMapping @JsonView(SummaryView.class) public ResponseEntity<Foo> handle() { // … } • Now also with @RequestBody @RequestMapping (method = POST) public void handle(@JsonView(SummaryView.class) @RequestBody Foo foo) { // ... } 36
  • 37. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Jackson Modules • Jackson2ObjectMapperBuilder auto-registers Jackson modules • jdk7, joda, jsr310, jdk8 • Conditional on classpath detection of target dependencies • Both MVC Java config and XML namespace use Jackson2ObjectMapperBuilder 37
  • 38. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC 38
  • 39. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • HandlerMethod argument for @ExceptionHandler methods • could be handy with @ControllerAdvice • CharSequence as controller method return value (alternative to String) • groovy.lang.GString, StringBuilder, StringBuffer • @InitBinder methods can register Formatter for specific field(s) • otherwise typically global in ConversionService 39
  • 40. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Async Return Value Types • Built-in support for • org.springframework.util.concurrent.ListenableFuture (4.1) • java.util.concurrent.CompletionStage (4.2) • Both adapted to DeferredResult • Easy to adapt others • RxJava Observable, Reactor Stream, … • Follow example of built-in types 40
  • 41. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JavaScript Templating 41
  • 42. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why? • Traditionally HTML served then enhanced with JavaScript • Trend towards generating the UI with JavaScript • Address challenges for single-page apps • As well as mobile devices 42
  • 43. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ React JavaScript Library • Developed at Facebook and Instagram • Virtual DOM with automatic DOM updates, fast, efficient • Supports server-side rendering (outside of DOM) • Fast adoption by major Internet players • Facebook/Instagram, Yahoo!, Netflix, Airbnb, etc. 43
  • 44. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Server-Side Rendering • For React adopters, server-side rendering has significant benefits • Faster load time, pre-generated HTML for web apps • Search-engine friendly • Client-centric UI still possible (e.g. Phonegap) 44
  • 45. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.2 and React • New view templating choice for JSR-223 scripting engines • ScriptTemplateView , ViewResolver, and Configurer • Configuration very similar to the alternatives (e.g. FreeMarker) • Use with Nashorn JavaScript engine from JDK 8 45
  • 46. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Talks Isomorphic Templating With Spring Boot, Nashorn and React by Sebastien Deleuze Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js by Matt Raible 46
  • 47. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Byte Ranges 47
  • 48. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Byte Ranges • HTTP 1.1 supports ability to download partial content • RFC 7233 • Server advertises willingness via Accept-Ranges response header • Client can then send a Range request header • e.g. Range: bytes=500-999 • Large media files, request any part / resume … 48
  • 49. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Byte Range Support in Spring 4.2 • HttpRange to create and parse ranges • Accept-Range and Range exposed in HttpHeaders • ResourceHttpRequestHandler supports byte ranges • e.g. server video files to iOS devices 49
  • 50. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ $ curl -v --range 0-99 http://localhost:8080/assets/jquery-2.1.4.js > GET /assets/jquery-2.1.4.js HTTP/1.1 > Range: bytes=0-99 ... < HTTP/1.1 206 Partial Content < ... < Accept-Ranges: bytes < Content-Range: bytes 0-99/247597 < Content-Length: 100 < ... 50 Example
  • 51. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Client Side 51
  • 52. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RestTemplate with OkHttp • RestTemplate + AsyncRestTemplate can be used with OkHttp • lightweight HTTP library • HTTP library support • JDK • Apache HttpComponents • Netty • OkHttp 52
  • 53. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flexible URI Template Handling • UriTemplateHandler for use with RestTemplate • Default implementation delegates to UriComponentsBuilder • Can be configured to • insert prefix in all URI templates • switch from path to path segment encoding by default • Potential to plug in 3rd party URI template library • e.g. full RFC 6570 syntax 53
  • 54. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WebSocket Messaging 54
  • 55. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Simple Broker: Heartbeats @Configuration @EnableWebSocketMessageBroker static class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { // … @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic").setTaskScheduler(scheduler()); } @Bean @Primary public TaskScheduler scheduler() { return new ThreadPoolTaskScheduler(); } } 55 Enable
  • 56. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Simple Broker: Selector Expression 56 • Add selector header on subscribe client.subscribe("/topic/interval", function(message) { // ... }, {'selector' : 'headers.parity == 'even''}); • SpEL expression evaluated against messages • Only matching messages received
  • 57. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Server User Destinations 57 • Spring supported special STOMP destination • /user/{username}/… • User receives message if connected • User can be connected to any application server (since 4.2)
  • 58. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Server User Destinations 58 Spring App RabbitMQ Browser Sergi /user/sergi/…
  • 59. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connected User Information • SimpUserRegistry bean • Expose information about connected users and subscriptions • Supported in multi-server scenarios • via UserRegistryMessageHandler • Broadcast local user registry to other servers (via broker relay) • every 10 seconds • remote registry info expires after 20 seconds 59
  • 60. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ STOMP Client • Supported over WebSocket + over TCP • Plug in any Spring WebSocketClient implementation • SockJsClient allows using STOMP over WebSocket/SockJS • Support for heartbeats, receipts 60
  • 61. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • Property placeholders for @MessageMapping methods • @JsonView on @Payload arguments • Destination template variables in @SendTo annotation • Async return value types • org.springframework.util.concurrent.ListenableFuture • CompletableFuture/CompletionStage (JDK 8) 61
  • 62. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • @ControllerAdvice + @MessageExceptionHandler methods • HandlerMethod arguments for @MessageExceptionHandler • Spring OXM Marshaller based MessageConverter 62
  • 63. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Related Talk From Zero to Hero with Spring WebSocket by Sergi Almar 63
  • 64. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 64 Thank You for Listening! @rstoya05 Learn More. Stay Connected. @springcentral Spring.io/video