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 SummaryNested ClassesModifier and TypeClassDescriptionstatic classBlockHoundIntegrationfor spring-web classes.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringWell-known name for the ForwardedHeaderTransformer in the bean factory.static final StringWell-known name for the LocaleContextResolver in the bean factory.static final StringWell-known name for the ServerCodecConfigurer in the bean factory.static final StringWell-known name for the target WebHandler in the bean factory.static final StringWell-known name for the WebSessionManager in the bean factory.
- 
Method SummaryModifier and TypeMethodDescriptionstatic WebHttpHandlerBuilderapplicationContext(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 theServerCodecConfigurerto 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 theForwardedHeaderTransformerfor extracting and/or removing forwarded headers.booleanWhether aServerCodecConfigureris configured or not, either detected from anApplicationContextor explicitly configured viacodecConfigurer.booleanWhether aForwardedHeaderTransformeris configured or not, either detected from anApplicationContextor explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer).booleanWhether a decorator forHttpHandleris configured or not viahttpHandlerDecorator(Function).booleanWhether aLocaleContextResolveris configured or not, either detected from anApplicationContextor explicitly configured vialocaleContextResolver.booleanWhether aWebSessionManageris configured or not, either detected from anApplicationContextor explicitly configured viasessionManager.httpHandlerDecorator(Function<HttpHandler, HttpHandler> handlerDecorator) Configure aFunctionto decorate theHttpHandlerreturned by this builder which effectively wraps the entireWebExceptionHandler-WebFilter-WebHandlerprocessing chain.localeContextResolver(LocaleContextResolver localeContextResolver) Configure theLocaleContextResolverto set on theWebServerExchange.observationConvention(ServerRequestObservationConvention observationConvention) Configure aServerRequestObservationConventionto use for server observations.observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure anObservationRegistryfor recording server exchange observations.sessionManager(WebSessionManager manager) Configure theWebSessionManagerto set on theWebServerExchange.static WebHttpHandlerBuilderwebHandler(WebHandler webHandler) Static factory method to create a new builder instance.
- 
Field Details- 
WEB_HANDLER_BEAN_NAMEWell-known name for the target WebHandler in the bean factory.- See Also:
 
- 
WEB_SESSION_MANAGER_BEAN_NAMEWell-known name for the WebSessionManager in the bean factory.- See Also:
 
- 
SERVER_CODEC_CONFIGURER_BEAN_NAMEWell-known name for the ServerCodecConfigurer in the bean factory.- See Also:
 
- 
LOCALE_CONTEXT_RESOLVER_BEAN_NAMEWell-known name for the LocaleContextResolver in the bean factory.- See Also:
 
- 
FORWARDED_HEADER_TRANSFORMER_BEAN_NAMEWell-known name for the ForwardedHeaderTransformer in the bean factory.- See Also:
 
 
- 
- 
Method Details- 
webHandlerStatic factory method to create a new builder instance.- Parameters:
- webHandler- the target handler for the request
- Returns:
- the prepared builder
 
- 
applicationContextStatic factory method to create a new builder instance by detecting beans in anApplicationContext. The following are detected:- WebHandler[1] -- looked up by the name- WEB_HANDLER_BEAN_NAME.
- WebFilter[0..N] -- detected by type and ordered, see- AnnotationAwareOrderComparator.
- WebExceptionHandler[0..N] -- detected by type and ordered.
- HttpHandlerDecoratorFactory[0..N] -- detected by type and ordered.
- ObservationRegistry-- detected by type and configured if unique.
- ServerRequestObservationConvention-- detected by type and configured if unique.
- WebSessionManager[0..1] -- looked up by the name- WEB_SESSION_MANAGER_BEAN_NAME.
- ServerCodecConfigurer[0..1] -- looked up by the name- SERVER_CODEC_CONFIGURER_BEAN_NAME.
- LocaleContextResolver[0..1] -- looked up by the name- LOCALE_CONTEXT_RESOLVER_BEAN_NAME.
 - Parameters:
- context- the application context to use for the lookup
- Returns:
- the prepared builder
 
- 
filterAdd the given filter(s).- Parameters:
- filters- the filter(s) to add that's
 
- 
filtersManipulate the "live" list of currently configured filters.- Parameters:
- consumer- the consumer to use
 
- 
exceptionHandlerAdd the given exception handler(s).- Parameters:
- handlers- the exception handler(s)
 
- 
exceptionHandlersManipulate the "live" list of currently configured exception handlers.- Parameters:
- consumer- the consumer to use
 
- 
sessionManagerConfigure theWebSessionManagerto set on theWebServerExchange.By default DefaultWebSessionManageris used.- Parameters:
- manager- the session manager
- See Also:
 
- 
hasSessionManagerpublic boolean hasSessionManager()Whether aWebSessionManageris configured or not, either detected from anApplicationContextor explicitly configured viasessionManager.- Since:
- 5.0.9
 
- 
codecConfigurerConfigure theServerCodecConfigurerto set on theWebServerExchange.- Parameters:
- codecConfigurer- the codec configurer
 
- 
hasCodecConfigurerpublic boolean hasCodecConfigurer()Whether aServerCodecConfigureris configured or not, either detected from anApplicationContextor explicitly configured viacodecConfigurer.- Since:
- 5.0.9
 
- 
localeContextResolverConfigure theLocaleContextResolverto set on theWebServerExchange.- Parameters:
- localeContextResolver- the locale context resolver
 
- 
hasLocaleContextResolverpublic boolean hasLocaleContextResolver()Whether aLocaleContextResolveris configured or not, either detected from anApplicationContextor explicitly configured vialocaleContextResolver.- Since:
- 5.0.9
 
- 
forwardedHeaderTransformerConfigure theForwardedHeaderTransformerfor extracting and/or removing forwarded headers.- Parameters:
- transformer- the transformer
- Since:
- 5.1
 
- 
hasForwardedHeaderTransformerpublic boolean hasForwardedHeaderTransformer()Whether aForwardedHeaderTransformeris configured or not, either detected from anApplicationContextor explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer).- Since:
- 5.1
 
- 
observationRegistrypublic WebHttpHandlerBuilder observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure anObservationRegistryfor recording server exchange observations. By default, ano-opregistry will be configured.- Parameters:
- observationRegistry- the observation registry
- Since:
- 6.1
 
- 
observationConventionpublic WebHttpHandlerBuilder observationConvention(ServerRequestObservationConvention observationConvention) Configure aServerRequestObservationConventionto use for server observations. By default, aDefaultServerRequestObservationConventionwill be used.- Parameters:
- observationConvention- the convention to use for all recorded observations
- Since:
- 6.1
 
- 
httpHandlerDecoratorpublic WebHttpHandlerBuilder httpHandlerDecorator(Function<HttpHandler, HttpHandler> handlerDecorator) Configure aFunctionto decorate theHttpHandlerreturned by this builder which effectively wraps the entireWebExceptionHandler-WebFilter-WebHandlerprocessing 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
 
- 
hasHttpHandlerDecoratorpublic boolean hasHttpHandlerDecorator()Whether a decorator forHttpHandleris configured or not viahttpHandlerDecorator(Function).- Since:
- 5.3
 
- 
buildBuild theHttpHandler.
- 
cloneClone thisWebHttpHandlerBuilder.
 
-