Search in sources :

Example 1 with DispatcherHandler

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

the class LightWebServer method initializeContext.

@Override
protected void initializeContext() {
    super.initializeContext();
    HTTPServer server = new HTTPServer(getPort());
    server.setPort(getPort());
    server.setExecutor(executor);
    server.setSocketTimeout(socketTimeout);
    this.httpHandler = new DispatcherHandler(obtainApplicationContext());
    server.setHttpHandler(httpHandler);
    server.setConfig(obtainHttpConfig());
    this.server = server;
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler)

Example 2 with DispatcherHandler

use of cn.taketoday.web.handler.DispatcherHandler 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)

Example 3 with DispatcherHandler

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

the class WebApplicationLoader method configureHandlerRegistry.

protected void configureHandlerRegistry(List<HandlerRegistry> registries, WebMvcConfiguration mvcConfiguration) {
    DispatcherHandler obtainDispatcher = obtainDispatcher();
    HandlerRegistry handlerRegistry = obtainDispatcher.getHandlerRegistry();
    if (handlerRegistry != null) {
        registries.add(handlerRegistry);
    }
    // 自定义
    mvcConfiguration.configureHandlerRegistry(registries);
    obtainDispatcher.setHandlerRegistry(registries.size() == 1 ? registries.get(0) : new HandlerRegistries(registries));
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) ViewControllerHandlerRegistry(cn.taketoday.web.registry.ViewControllerHandlerRegistry) HandlerRegistry(cn.taketoday.web.registry.HandlerRegistry) HandlerRegistries(cn.taketoday.web.registry.HandlerRegistries)

Example 4 with DispatcherHandler

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

the class WebApplicationLoader method configureExceptionHandler.

/**
 * configure HandlerExceptionHandler
 *
 * @param handlers handlers in application-context {@link #obtainApplicationContext()}
 */
protected void configureExceptionHandler(List<HandlerExceptionHandler> handlers, WebMvcConfiguration mvcConfiguration) {
    DispatcherHandler dispatcherHandler = obtainDispatcher();
    HandlerExceptionHandler exceptionHandler = dispatcherHandler.getExceptionHandler();
    if (exceptionHandler != null) {
        handlers.add(exceptionHandler);
    }
    // user config
    mvcConfiguration.configureExceptionHandlers(handlers);
    // at least one exception-handler
    if (handlers.size() == 1) {
        exceptionHandler = handlers.get(0);
    } else {
        // @since 3.0.3 exception handlers order
        sort(handlers);
        exceptionHandler = new CompositeHandlerExceptionHandler(handlers);
    }
    // set
    dispatcherHandler.setExceptionHandler(exceptionHandler);
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) CompositeHandlerExceptionHandler(cn.taketoday.web.handler.CompositeHandlerExceptionHandler) HandlerExceptionHandler(cn.taketoday.web.handler.HandlerExceptionHandler) CompositeHandlerExceptionHandler(cn.taketoday.web.handler.CompositeHandlerExceptionHandler)

Example 5 with DispatcherHandler

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

the class WebApplicationLoader method obtainDispatcher.

public DispatcherHandler obtainDispatcher() {
    if (dispatcher == null) {
        // FIXME DispatcherHandler automatic registration
        WebApplicationContext context = obtainApplicationContext();
        DispatcherHandler dispatcherHandler = context.getBean(DispatcherHandler.class);
        if (dispatcherHandler == null) {
            dispatcherHandler = createDispatcher(context);
            Assert.state(dispatcherHandler != null, "DispatcherHandler must not be null, sub class must create its instance");
            context.unwrap(BeanDefinitionRegistrar.class).registerSingleton(DispatcherHandler.BEAN_NAME, dispatcherHandler);
        }
        this.dispatcher = dispatcherHandler;
    }
    return dispatcher;
}
Also used : DispatcherHandler(cn.taketoday.web.handler.DispatcherHandler) BeanDefinitionRegistrar(cn.taketoday.context.loader.BeanDefinitionRegistrar) WebApplicationContext(cn.taketoday.web.WebApplicationContext)

Aggregations

DispatcherHandler (cn.taketoday.web.handler.DispatcherHandler)6 WebApplicationContext (cn.taketoday.web.WebApplicationContext)3 ViewControllerHandlerRegistry (cn.taketoday.web.registry.ViewControllerHandlerRegistry)2 BeanDefinitionRegistrar (cn.taketoday.context.loader.BeanDefinitionRegistrar)1 CompositeHandlerExceptionHandler (cn.taketoday.web.handler.CompositeHandlerExceptionHandler)1 HandlerAdapter (cn.taketoday.web.handler.HandlerAdapter)1 HandlerExceptionHandler (cn.taketoday.web.handler.HandlerExceptionHandler)1 RequestHandlerAdapter (cn.taketoday.web.handler.RequestHandlerAdapter)1 ReturnValueHandlerManager (cn.taketoday.web.handler.ReturnValueHandlerManager)1 SelectableReturnValueHandler (cn.taketoday.web.handler.SelectableReturnValueHandler)1 ViewControllerHandlerAdapter (cn.taketoday.web.handler.ViewControllerHandlerAdapter)1 HandlerRegistries (cn.taketoday.web.registry.HandlerRegistries)1 HandlerRegistry (cn.taketoday.web.registry.HandlerRegistry)1