Class WebHttpHandlerBuilder
java.lang.Object
org.springframework.web.server.adapter.WebHttpHandlerBuilder
This builder has two purposes:
One is to assemble a processing chain that consists of a target WebHandler
,
then decorated with a set of WebFilters
, then further decorated with
a set of WebExceptionHandlers
.
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 of HttpWebHandlerAdapter
.
The processing chain can be assembled manually via builder methods, or detected from
a Spring ApplicationContext
via applicationContext
, or a mix of both.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
BlockHoundIntegration
for spring-web classes. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Well-known name for the ForwardedHeaderTransformer in the bean factory.static final String
Well-known name for the LocaleContextResolver in the bean factory.static final String
Well-known name for the ServerCodecConfigurer in the bean factory.static final String
Well-known name for the target WebHandler in the bean factory.static final String
Well-known name for the WebSessionManager in the bean factory. -
Method Summary
Modifier and TypeMethodDescriptionstatic WebHttpHandlerBuilder
applicationContext
(ApplicationContext context) Static factory method to create a new builder instance by detecting beans in anApplicationContext
.build()
Build theHttpHandler
.clone()
Clone thisWebHttpHandlerBuilder
.codecConfigurer
(ServerCodecConfigurer codecConfigurer) Configure theServerCodecConfigurer
to set on theWebServerExchange
.exceptionHandler
(WebExceptionHandler... handlers) Add the given exception handler(s).exceptionHandlers
(Consumer<List<WebExceptionHandler>> consumer) Manipulate the "live" list of currently configured exception handlers.Add the given filter(s).Manipulate the "live" list of currently configured filters.forwardedHeaderTransformer
(ForwardedHeaderTransformer transformer) Configure theForwardedHeaderTransformer
for extracting and/or removing forwarded headers.boolean
Whether aServerCodecConfigurer
is configured or not, either detected from anApplicationContext
or explicitly configured viacodecConfigurer
.boolean
Whether aForwardedHeaderTransformer
is configured or not, either detected from anApplicationContext
or explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer)
.boolean
Whether a decorator forHttpHandler
is configured or not viahttpHandlerDecorator(Function)
.boolean
Whether aLocaleContextResolver
is configured or not, either detected from anApplicationContext
or explicitly configured vialocaleContextResolver
.boolean
Whether aWebSessionManager
is configured or not, either detected from anApplicationContext
or explicitly configured viasessionManager
.httpHandlerDecorator
(Function<HttpHandler, HttpHandler> handlerDecorator) Configure aFunction
to decorate theHttpHandler
returned by this builder which effectively wraps the entireWebExceptionHandler
-WebFilter
-WebHandler
processing chain.localeContextResolver
(LocaleContextResolver localeContextResolver) Configure theLocaleContextResolver
to set on theWebServerExchange
.sessionManager
(WebSessionManager manager) Configure theWebSessionManager
to set on theWebServerExchange
.static WebHttpHandlerBuilder
webHandler
(WebHandler webHandler) Static factory method to create a new builder instance.
-
Field Details
-
WEB_HANDLER_BEAN_NAME
Well-known name for the target WebHandler in the bean factory.- See Also:
-
WEB_SESSION_MANAGER_BEAN_NAME
Well-known name for the WebSessionManager in the bean factory.- See Also:
-
SERVER_CODEC_CONFIGURER_BEAN_NAME
Well-known name for the ServerCodecConfigurer in the bean factory.- See Also:
-
LOCALE_CONTEXT_RESOLVER_BEAN_NAME
Well-known name for the LocaleContextResolver in the bean factory.- See Also:
-
FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
Well-known name for the ForwardedHeaderTransformer in the bean factory.- See Also:
-
-
Method Details
-
webHandler
Static factory method to create a new builder instance.- Parameters:
webHandler
- the target handler for the request- Returns:
- the prepared builder
-
applicationContext
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.HttpHandlerDecoratorFactory
[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
.
- Parameters:
context
- the application context to use for the lookup- Returns:
- the prepared builder
-
filter
Add the given filter(s).- Parameters:
filters
- the filter(s) to add that's
-
filters
Manipulate the "live" list of currently configured filters.- Parameters:
consumer
- the consumer to use
-
exceptionHandler
Add the given exception handler(s).- Parameters:
handlers
- the exception handler(s)
-
exceptionHandlers
Manipulate the "live" list of currently configured exception handlers.- Parameters:
consumer
- the consumer to use
-
sessionManager
Configure theWebSessionManager
to set on theWebServerExchange
.By default
DefaultWebSessionManager
is used.- Parameters:
manager
- the session manager- See Also:
-
hasSessionManager
public boolean hasSessionManager()Whether aWebSessionManager
is configured or not, either detected from anApplicationContext
or explicitly configured viasessionManager
.- Since:
- 5.0.9
-
codecConfigurer
Configure theServerCodecConfigurer
to set on theWebServerExchange
.- Parameters:
codecConfigurer
- the codec configurer
-
hasCodecConfigurer
public boolean hasCodecConfigurer()Whether aServerCodecConfigurer
is configured or not, either detected from anApplicationContext
or explicitly configured viacodecConfigurer
.- Since:
- 5.0.9
-
localeContextResolver
Configure theLocaleContextResolver
to set on theWebServerExchange
.- Parameters:
localeContextResolver
- the locale context resolver
-
hasLocaleContextResolver
public boolean hasLocaleContextResolver()Whether aLocaleContextResolver
is configured or not, either detected from anApplicationContext
or explicitly configured vialocaleContextResolver
.- Since:
- 5.0.9
-
forwardedHeaderTransformer
Configure theForwardedHeaderTransformer
for extracting and/or removing forwarded headers.- Parameters:
transformer
- the transformer- Since:
- 5.1
-
hasForwardedHeaderTransformer
public boolean hasForwardedHeaderTransformer()Whether aForwardedHeaderTransformer
is configured or not, either detected from anApplicationContext
or explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer)
.- Since:
- 5.1
-
httpHandlerDecorator
public WebHttpHandlerBuilder httpHandlerDecorator(Function<HttpHandler, HttpHandler> handlerDecorator) Configure aFunction
to decorate theHttpHandler
returned by this builder which effectively wraps the entireWebExceptionHandler
-WebFilter
-WebHandler
processing chain. This provides access to the request and response before the entire chain and likewise the ability to observe the result of the entire chain.- Parameters:
handlerDecorator
- the decorator to apply- Since:
- 5.3
-
hasHttpHandlerDecorator
public boolean hasHttpHandlerDecorator()Whether a decorator forHttpHandler
is configured or not viahttpHandlerDecorator(Function)
.- Since:
- 5.3
-
build
Build theHttpHandler
. -
clone
Clone thisWebHttpHandlerBuilder
.
-