Expert Spring MVC and Web Flow

(Dana P.) #1

The Processing Pipeline


Spring MVC applications are highly configurable and extensible, and most of that power comes
from its software architecture. Inside Spring MVC, as is the case with the Spring Framework as a
whole, interfaces and abstractions are provided so that you can easily customize the behavior and
work flow of your web application. In this chapter we will examine the DispatcherServletand the
processing pipeline that it controls in order to understand how a request is handled, as well as
how best to tap into the many extension points and life cycle events.


Processing Requests


A new HTTP request entering the system is passed to many different handlers, each playing its
own small part in the overall processing of the request. We will now look at the timeline of a
new request and the order in which the handlers are activated.


Request Work Flow


1.Discover the request’s Locale; expose for later usage.

2.If the request is a multipart request (for file uploads), the file upload data is exposed
for later processing.

3.Locate which request handler is responsible for this request (e.g., a Controller).

4.Locate any request interceptors for this request. Interceptors are like filters, but cus-
tomized for Spring MVC.

5.Call preHandle()methods on any interceptors, which may circumvent the normal pro-
cessing order (see “HandlerInterceptors” in Chapter 6).

6.Invoke the Controller.

7.Call postHandle()methods on any interceptors.

8.If there is any exception, handle it with a HandlerExceptionResolver.

9.If no exceptions were thrown, and the Controllerreturned a ModelAndView, then render
the view. When rendering the view, first resolve the view name to a Viewinstance.

10.Call afterCompletion()methods on any interceptors.
77

CHAPTER 5


■ ■ ■

Free download pdf