类 WebHttpHandlerBuilder
- java.lang.Object
- org.springframework.web.server.adapter.WebHttpHandlerBuilder
public final class WebHttpHandlerBuilder extends Object
This builder has two purposes:One is to assemble a processing chain that consists of a target
WebHandler
, then decorated with a set ofWebFilters
, then further decorated with a set ofWebExceptionHandlers
.The second purpose is to adapt the resulting processing chain to an
HttpHandler
: the lowest-level reactive HTTP handling abstraction which can then be used with any of the supported runtimes. The adaptation is done with the help ofHttpWebHandlerAdapter
.The processing chain can be assembled manually via builder methods, or detected from a Spring
ApplicationContext
viaapplicationContext
, or a mix of both.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev, Sebastien Deleuze
- 另请参阅:
HttpWebHandlerAdapter
字段概要
字段 修饰符和类型 字段 说明 static String
FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
Well-known name for the ForwardedHeaderTransformer in the bean factory.static String
LOCALE_CONTEXT_RESOLVER_BEAN_NAME
Well-known name for the LocaleContextResolver in the bean factory.static String
SERVER_CODEC_CONFIGURER_BEAN_NAME
Well-known name for the ServerCodecConfigurer in the bean factory.static String
WEB_HANDLER_BEAN_NAME
Well-known name for the target WebHandler in the bean factory.static String
WEB_SESSION_MANAGER_BEAN_NAME
Well-known name for the WebSessionManager in the bean factory.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static WebHttpHandlerBuilder
applicationContext(ApplicationContext context)
Static factory method to create a new builder instance by detecting beans in anApplicationContext
.HttpHandler
build()
Build theHttpHandler
.WebHttpHandlerBuilder
clone()
Clone thisWebHttpHandlerBuilder
.WebHttpHandlerBuilder
codecConfigurer(ServerCodecConfigurer codecConfigurer)
Configure theServerCodecConfigurer
to set on theWebServerExchange
.WebHttpHandlerBuilder
exceptionHandler(WebExceptionHandler... handlers)
Add the given exception handler(s).WebHttpHandlerBuilder
exceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)
Manipulate the "live" list of currently configured exception handlers.WebHttpHandlerBuilder
filter(WebFilter... filters)
Add the given filter(s).WebHttpHandlerBuilder
filters(Consumer<List<WebFilter>> consumer)
Manipulate the "live" list of currently configured filters.WebHttpHandlerBuilder
forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)
Configure theForwardedHeaderTransformer
for extracting and/or removing forwarded headers.boolean
hasCodecConfigurer()
Whether aServerCodecConfigurer
is configured or not, either detected from anApplicationContext
or explicitly configured viacodecConfigurer
.boolean
hasForwardedHeaderTransformer()
Whether aForwardedHeaderTransformer
is configured or not, either detected from anApplicationContext
or explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer)
.boolean
hasLocaleContextResolver()
Whether aLocaleContextResolver
is configured or not, either detected from anApplicationContext
or explicitly configured vialocaleContextResolver
.boolean
hasSessionManager()
Whether aWebSessionManager
is configured or not, either detected from anApplicationContext
or explicitly configured viasessionManager
.WebHttpHandlerBuilder
localeContextResolver(LocaleContextResolver localeContextResolver)
Configure theLocaleContextResolver
to set on theWebServerExchange
.WebHttpHandlerBuilder
sessionManager(WebSessionManager manager)
Configure theWebSessionManager
to set on theWebServerExchange
.static WebHttpHandlerBuilder
webHandler(WebHandler webHandler)
Static factory method to create a new builder instance.
字段详细资料
WEB_HANDLER_BEAN_NAME
public static final String WEB_HANDLER_BEAN_NAME
Well-known name for the target WebHandler in the bean factory.- 另请参阅:
- 常量字段值
WEB_SESSION_MANAGER_BEAN_NAME
public static final String WEB_SESSION_MANAGER_BEAN_NAME
Well-known name for the WebSessionManager in the bean factory.- 另请参阅:
- 常量字段值
SERVER_CODEC_CONFIGURER_BEAN_NAME
public static final String SERVER_CODEC_CONFIGURER_BEAN_NAME
Well-known name for the ServerCodecConfigurer in the bean factory.- 另请参阅:
- 常量字段值
LOCALE_CONTEXT_RESOLVER_BEAN_NAME
public static final String LOCALE_CONTEXT_RESOLVER_BEAN_NAME
Well-known name for the LocaleContextResolver in the bean factory.- 另请参阅:
- 常量字段值
FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
public static final String FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
Well-known name for the ForwardedHeaderTransformer in the bean factory.- 另请参阅:
- 常量字段值
方法详细资料
webHandler
public static WebHttpHandlerBuilder webHandler(WebHandler webHandler)
Static factory method to create a new builder instance.- 参数:
webHandler
- the target handler for the request- 返回:
- the prepared builder
applicationContext
public static WebHttpHandlerBuilder applicationContext(ApplicationContext context)
Static factory method to create a new builder instance by detecting beans in anApplicationContext
. The following are detected:WebHandler
[1] -- looked up by the nameWEB_HANDLER_BEAN_NAME
.WebFilter
[0..N] -- detected by type and ordered, seeAnnotationAwareOrderComparator
.WebExceptionHandler
[0..N] -- detected by type and ordered.WebSessionManager
[0..1] -- looked up by the nameWEB_SESSION_MANAGER_BEAN_NAME
.ServerCodecConfigurer
[0..1] -- looked up by the nameSERVER_CODEC_CONFIGURER_BEAN_NAME
.LocaleContextResolver
[0..1] -- looked up by the nameLOCALE_CONTEXT_RESOLVER_BEAN_NAME
.
- 参数:
context
- the application context to use for the lookup- 返回:
- the prepared builder
filter
public WebHttpHandlerBuilder filter(WebFilter... filters)
Add the given filter(s).- 参数:
filters
- the filter(s) to add that's
filters
public WebHttpHandlerBuilder filters(Consumer<List<WebFilter>> consumer)
Manipulate the "live" list of currently configured filters.- 参数:
consumer
- the consumer to use
exceptionHandler
public WebHttpHandlerBuilder exceptionHandler(WebExceptionHandler... handlers)
Add the given exception handler(s).- 参数:
handlers
- the exception handler(s)
exceptionHandlers
public WebHttpHandlerBuilder exceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)
Manipulate the "live" list of currently configured exception handlers.- 参数:
consumer
- the consumer to use
sessionManager
public WebHttpHandlerBuilder sessionManager(WebSessionManager manager)
Configure theWebSessionManager
to set on theWebServerExchange
.By default
DefaultWebSessionManager
is used.- 参数:
manager
- the session manager- 另请参阅:
HttpWebHandlerAdapter.setSessionManager(WebSessionManager)
hasSessionManager
public boolean hasSessionManager()
Whether aWebSessionManager
is configured or not, either detected from anApplicationContext
or explicitly configured viasessionManager
.- 从以下版本开始:
- 5.0.9
codecConfigurer
public WebHttpHandlerBuilder codecConfigurer(ServerCodecConfigurer codecConfigurer)
Configure theServerCodecConfigurer
to set on theWebServerExchange
.- 参数:
codecConfigurer
- the codec configurer
hasCodecConfigurer
public boolean hasCodecConfigurer()
Whether aServerCodecConfigurer
is configured or not, either detected from anApplicationContext
or explicitly configured viacodecConfigurer
.- 从以下版本开始:
- 5.0.9
localeContextResolver
public WebHttpHandlerBuilder localeContextResolver(LocaleContextResolver localeContextResolver)
Configure theLocaleContextResolver
to set on theWebServerExchange
.- 参数:
localeContextResolver
- the locale context resolver
hasLocaleContextResolver
public boolean hasLocaleContextResolver()
Whether aLocaleContextResolver
is configured or not, either detected from anApplicationContext
or explicitly configured vialocaleContextResolver
.- 从以下版本开始:
- 5.0.9
forwardedHeaderTransformer
public WebHttpHandlerBuilder forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)
Configure theForwardedHeaderTransformer
for extracting and/or removing forwarded headers.- 参数:
transformer
- the transformer- 从以下版本开始:
- 5.1
hasForwardedHeaderTransformer
public boolean hasForwardedHeaderTransformer()
Whether aForwardedHeaderTransformer
is configured or not, either detected from anApplicationContext
or explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer)
.- 从以下版本开始:
- 5.1
build
public HttpHandler build()
Build theHttpHandler
.
clone
public WebHttpHandlerBuilder clone()
Clone thisWebHttpHandlerBuilder
.