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
Nested ClassesModifier and TypeClassDescriptionstatic classBlockHoundIntegrationfor spring-web classes. -
Field Summary
FieldsModifier 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 Summary
Modifier 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_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.ObservationRegistry-- detected by type and configured if unique.ServerRequestObservationConvention-- detected by type and configured if unique.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 theWebSessionManagerto set on theWebServerExchange.By default
DefaultWebSessionManageris used.- Parameters:
manager- the session manager- See Also:
-
hasSessionManager
public boolean hasSessionManager()Whether aWebSessionManageris configured or not, either detected from anApplicationContextor explicitly configured viasessionManager.- Since:
- 5.0.9
-
codecConfigurer
Configure theServerCodecConfigurerto set on theWebServerExchange.- Parameters:
codecConfigurer- the codec configurer
-
hasCodecConfigurer
public boolean hasCodecConfigurer()Whether aServerCodecConfigureris configured or not, either detected from anApplicationContextor explicitly configured viacodecConfigurer.- Since:
- 5.0.9
-
localeContextResolver
Configure theLocaleContextResolverto set on theWebServerExchange.- Parameters:
localeContextResolver- the locale context resolver
-
hasLocaleContextResolver
public boolean hasLocaleContextResolver()Whether aLocaleContextResolveris configured or not, either detected from anApplicationContextor explicitly configured vialocaleContextResolver.- Since:
- 5.0.9
-
forwardedHeaderTransformer
Configure theForwardedHeaderTransformerfor extracting and/or removing forwarded headers.- Parameters:
transformer- the transformer- Since:
- 5.1
-
hasForwardedHeaderTransformer
public boolean hasForwardedHeaderTransformer()Whether aForwardedHeaderTransformeris configured or not, either detected from anApplicationContextor explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer).- Since:
- 5.1
-
observationRegistry
public 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
-
observationConvention
public 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
-
httpHandlerDecorator
public 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
-
hasHttpHandlerDecorator
public boolean hasHttpHandlerDecorator()Whether a decorator forHttpHandleris configured or not viahttpHandlerDecorator(Function).- Since:
- 5.3
-
build
Build theHttpHandler. -
clone
Clone thisWebHttpHandlerBuilder.
-