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;
}
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()]));
}
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));
}
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);
}
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;
}
Aggregations