Search in sources :

Example 1 with SelectableReturnValueHandler

use of cn.taketoday.web.handler.SelectableReturnValueHandler in project today-framework by TAKETODAY.

the class WebApplicationLoader method configureReturnValueHandler.

/**
 * Configure {@link ReturnValueHandler} to resolve handler method result
 *
 * @param handlers {@link ReturnValueHandler} registry
 * @param mvcConfiguration All {@link WebMvcConfiguration} object
 */
protected void configureReturnValueHandler(List<ReturnValueHandler> handlers, WebMvcConfiguration mvcConfiguration) {
    DispatcherHandler obtainDispatcher = obtainDispatcher();
    SelectableReturnValueHandler existingHandlers = obtainDispatcher.getReturnValueHandler();
    if (existingHandlers != null) {
        handlers.addAll(existingHandlers.getInternalHandlers());
    }
    WebApplicationContext context = obtainApplicationContext();
    // @since 3.0
    ReturnValueHandlerManager manager = context.getBean(ReturnValueHandlerManager.class);
    Assert.state(manager != null, "No ReturnValueHandlers");
    // user config
    mvcConfiguration.configureResultHandler(handlers);
    manager.addHandlers(handlers);
    // apply result handler
    SelectableReturnValueHandler selectable = new SelectableReturnValueHandler(manager.getHandlers());
    selectable.trimToSize();
    obtainDispatcher.setReturnValueHandler(selectable);
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) SelectableReturnValueHandler(cn.taketoday.web.handler.SelectableReturnValueHandler) ReturnValueHandlerManager(cn.taketoday.web.handler.ReturnValueHandlerManager) WebApplicationContext(cn.taketoday.web.WebApplicationContext)

Aggregations

WebApplicationContext (cn.taketoday.web.WebApplicationContext)1 DispatcherHandler (cn.taketoday.web.handler.DispatcherHandler)1 ReturnValueHandlerManager (cn.taketoday.web.handler.ReturnValueHandlerManager)1 SelectableReturnValueHandler (cn.taketoday.web.handler.SelectableReturnValueHandler)1