Search in sources :

Example 1 with RequestHandlerAdapter

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

the class WebApplicationLoader method configureHandlerAdapter.

/**
 * Configure {@link HandlerAdapter}
 *
 * @param adapters {@link HandlerAdapter}s
 * @param mvcConfiguration {@link WebMvcConfiguration}
 */
protected void configureHandlerAdapter(List<HandlerAdapter> adapters, WebMvcConfiguration mvcConfiguration) {
    // 先看有的
    DispatcherHandler obtainDispatcher = obtainDispatcher();
    HandlerAdapter[] handlerAdapters = obtainDispatcher.getHandlerAdapters();
    if (handlerAdapters != null) {
        Collections.addAll(adapters, handlerAdapters);
    }
    // 添加默认的
    adapters.add(new RequestHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
    WebApplicationContext context = obtainApplicationContext();
    // ViewControllerHandlerRegistry must configured
    ViewControllerHandlerRegistry viewControllerRegistry = context.getBean(ViewControllerHandlerRegistry.class);
    if (viewControllerRegistry != null) {
        ViewControllerHandlerAdapter bean = context.getBean(ViewControllerHandlerAdapter.class);
        if (bean == null) {
            ViewControllerHandlerAdapter viewControllerHandlerAdapter = null;
            for (HandlerAdapter adapter : adapters) {
                if (adapter instanceof ViewControllerHandlerAdapter) {
                    viewControllerHandlerAdapter = (ViewControllerHandlerAdapter) adapter;
                    break;
                }
            }
            if (viewControllerHandlerAdapter == null) {
                adapters.add(new ViewControllerHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
            }
        }
    }
    // 排序
    sort(adapters);
    // apply request handler
    obtainDispatcher.setHandlerAdapters(adapters.toArray(new HandlerAdapter[adapters.size()]));
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) ViewControllerHandlerAdapter(cn.taketoday.web.handler.ViewControllerHandlerAdapter) RequestHandlerAdapter(cn.taketoday.web.handler.RequestHandlerAdapter) HandlerAdapter(cn.taketoday.web.handler.HandlerAdapter) ViewControllerHandlerRegistry(cn.taketoday.web.registry.ViewControllerHandlerRegistry) RequestHandlerAdapter(cn.taketoday.web.handler.RequestHandlerAdapter) WebApplicationContext(cn.taketoday.web.WebApplicationContext) ViewControllerHandlerAdapter(cn.taketoday.web.handler.ViewControllerHandlerAdapter)

Aggregations

WebApplicationContext (cn.taketoday.web.WebApplicationContext)1 DispatcherHandler (cn.taketoday.web.handler.DispatcherHandler)1 HandlerAdapter (cn.taketoday.web.handler.HandlerAdapter)1 RequestHandlerAdapter (cn.taketoday.web.handler.RequestHandlerAdapter)1 ViewControllerHandlerAdapter (cn.taketoday.web.handler.ViewControllerHandlerAdapter)1 ViewControllerHandlerRegistry (cn.taketoday.web.registry.ViewControllerHandlerRegistry)1