Expert Spring MVC and Web Flow

(Dana P.) #1

you are intending to integrate an exotic web framework, you may use this class to integrate it
into the DispatcherServlet.
Listing 5-4 provides a simple example of an implementation of a HandlerAdapterfor some
exotic web framework.


Listing 5-4.Example HandlerAdapter


public class ExoticFrameworkHandlerAdapter implements HandlerAdapter {


public boolean supports(Object handler) {
return (handler != null) && (handler instanceof ExoticFramework);
}

public ModelAndView handle(HttpServletRequest req, HttpServletResponse res,
Object handler) throws Exception {
ExoticResult result = ((ExoticFramework)handler).executeRequest(req, res);
return adaptResult(result);
}

private ModelAndView adaptResult(ExoticResult result) {
ModelAndView mav = new ModelAndView();
mav.getModel().putAll(result.getObjectsToRender());
return mav;
}

public long getLastModified(HttpServletRequest req, Object handler) {
return -1; // exotic framework doesn't support this
}

}


Configuring the DispatcherServletto use this HandlerAdapteris quite easy, as the
DispatcherServletby default looks into the ApplicationContextfor all HandlerAdapters. It
will find all adapters by their type, and it will order them, paying special attention to any
adapters that implement the org.springframework.core.Orderedinterface.
Listing 5-5 contains the bean definition for the ExoticFrameworkHandlerAdapter.


Listing 5-5.ApplicationContext with ExoticFrameworkHandlerAdapter


<?xml version="1.0"?
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">



class="com.apress.expertspringmvc.chap4.ExoticFrameworkHandlerAdapter"
/>

CHAPTER 5 ■THE PROCESSING PIPELINE 85
Free download pdf