HttpHandler
HttpHandler
是反应式HTTP请求处理的最底层契约,支持不同的运行时(参见实践spring boot2之webserver),比如Netty、Tomcat等。运行时将请求处理传递给HttpHandler
。
1 |
|
handle的返回值是Mono<Void>
容器适配
ReactorHttpHandlerAdapter
Adapt HttpHandler to the Reactor Netty channel handling function.
1 |
|
ServletHttpHandlerAdapter
Adapt HttpHandler to an HttpServlet using Servlet Async support and Servlet 3.1 non-blocking I/O.
1 |
|
UndertowHttpHandlerAdapter
Adapt HttpHandler to the Undertow io.undertow.server.HttpHandler.
1 |
|
HttpWebHandlerAdapter
将WebHandler适配为HttpHandler,以便HttpHandler将请求转给WebHandler
1 |
|
ServerWebExchange
WebHandler
Web请求处理。spring boot默认基于webHandler
这个bean id来初始化WebHandler
,默认的WebHandler
实现是DispatcherHandler
,可以使用自定义的覆盖。
1 |
|
WebHandler:
1 |
|
DispatcherHandler
好比Spring MVC里面的DispatcherServlet,负责请求分发到具体的业务处理handler。
1 |
|
HandlerMapping
基于匹配寻找Handler
HandlerAdapter
适配多种不同类型的Handler,解耦DispatcherHandler和Handler
implement | support | comment |
---|---|---|
HandlerFunctionAdapter | HandlerFunction | |
RequestMappingHandlerAdapter | HandlerMethod | |
SimpleHandlerAdapter | WebHandler | |
WebSocketHandlerAdapter | WebSocketHandler |
HandlerResultHandler
基于handler处理结果HandlerResult,执行后续处理,比如直接应答或渲染视图页面
implement | ||
---|---|---|
ResponseEntityResultHandler | ResponseEntity , typically from @Controller instances. |
|
ServerResponseResultHandler | ServerResponse , typically from functional endpoints. |
|
ResponseBodyResultHandler | Handle return values from @ResponseBody methods or @RestController classes. |
|
ViewResolutionResultHandler | CharSequence , View , Model, Map , Rendering, or any other Object is treated as a model attribute. |
Handler
handler指业务处理方法,比如Controller里的业务处理方法。
ExceptionHandler
针对指定handler相关的异常处理,包括Handler调用和HandlerResultHandler调用
ExceptionHandlerMethodResolver
WebFilter
1 |
|
DefaultWebFilterChain
CORS
CorsWebFilter
CrossOrigin
Exception
装饰WebHandler,负责WebHandler的异常处理
1 |
|
WebSessionManager
ServerCodecConfigurer
LocaleContextResolver
ForwardedHeaderTransformer
当服务被反向代理时,中间经过了代理服务器,scheme、host和port等信息可能改变了,会导致客户端指向错误的地址信息,比如重定向时,RFC7239引入了Forwarded相关header(X-Forwarded-Host
, X-Forwarded-Port
, X-Forwarded-Proto
, X-Forwarded-Ssl
, and X-Forwarded-Prefix
),记录经过代理转发的相关信息,ForwardedHeaderTransformer会基于这些信息找到正确的地址信息。
WebHttpHandlerBuilder
流程编排
1 |
|
View
ViewResolutionResultHandler
ViewResolver
UrlBasedViewResolver:redirect
Codes
WebClient
ClientHttpConnector
Logging
WebFlux Config
EnableWebFlux
引入DelegatingWebFluxConfiguration
WebFluxConfigurationSupport
WebFlux的主要配置类
DelegatingWebFluxConfiguration
继承WebFluxConfigurationSupport,扩展以便通过WebFluxConfigurer来定制配置
1 |
|
WebFluxConfigurer
WebFlux定制配置,支持N个实例
1 |
|
业务层
Annotated Controller
Functional Handler
RouterFunction
HandlerFunction
ResourceHandler
ResourceHandlerRegistrationCustomizer
SSE
1 |
|
不断上送
1 |
|
线程模型
默认线程池跟cpu核数一致(最小值4)
1 |
|