Class 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
ApplicationContextviaapplicationContext, or a mix of both.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
- See Also:
HttpWebHandlerAdapter
Field Summary
Fields Modifier and Type Field Description static StringFORWARDED_HEADER_TRANSFORMER_BEAN_NAMEWell-known name for the ForwardedHeaderTransformer in the bean factory.static StringLOCALE_CONTEXT_RESOLVER_BEAN_NAMEWell-known name for the LocaleContextResolver in the bean factory.static StringSERVER_CODEC_CONFIGURER_BEAN_NAMEWell-known name for the ServerCodecConfigurer in the bean factory.static StringWEB_HANDLER_BEAN_NAMEWell-known name for the target WebHandler in the bean factory.static StringWEB_SESSION_MANAGER_BEAN_NAMEWell-known name for the WebSessionManager in the bean factory.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WebHttpHandlerBuilderapplicationContext(ApplicationContext context)Static factory method to create a new builder instance by detecting beans in anApplicationContext.HttpHandlerbuild()Build theHttpHandler.WebHttpHandlerBuilderclone()Clone thisWebHttpHandlerBuilder.WebHttpHandlerBuildercodecConfigurer(ServerCodecConfigurer codecConfigurer)Configure theServerCodecConfigurerto set on theWebServerExchange.WebHttpHandlerBuilderexceptionHandler(WebExceptionHandler... handlers)Add the given exception handler(s).WebHttpHandlerBuilderexceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)Manipulate the "live" list of currently configured exception handlers.WebHttpHandlerBuilderfilter(WebFilter... filters)Add the given filter(s).WebHttpHandlerBuilderfilters(Consumer<List<WebFilter>> consumer)Manipulate the "live" list of currently configured filters.WebHttpHandlerBuilderforwardedHeaderTransformer(ForwardedHeaderTransformer transformer)Configure theForwardedHeaderTransformerfor extracting and/or removing forwarded headers.booleanhasCodecConfigurer()Whether aServerCodecConfigureris configured or not, either detected from anApplicationContextor explicitly configured viacodecConfigurer.booleanhasForwardedHeaderTransformer()Whether aForwardedHeaderTransformeris configured or not, either detected from anApplicationContextor explicitly configured viaforwardedHeaderTransformer(ForwardedHeaderTransformer).booleanhasLocaleContextResolver()Whether aLocaleContextResolveris configured or not, either detected from anApplicationContextor explicitly configured vialocaleContextResolver.booleanhasSessionManager()Whether aWebSessionManageris configured or not, either detected from anApplicationContextor explicitly configured viasessionManager.WebHttpHandlerBuilderlocaleContextResolver(LocaleContextResolver localeContextResolver)Configure theLocaleContextResolverto set on theWebServerExchange.WebHttpHandlerBuildersessionManager(WebSessionManager manager)Configure theWebSessionManagerto set on theWebServerExchange.static WebHttpHandlerBuilderwebHandler(WebHandler webHandler)Static factory method to create a new builder instance.
Field Detail
WEB_HANDLER_BEAN_NAME
public static final String WEB_HANDLER_BEAN_NAME
Well-known name for the target WebHandler in the bean factory.- See Also:
- Constant Field Values
WEB_SESSION_MANAGER_BEAN_NAME
public static final String WEB_SESSION_MANAGER_BEAN_NAME
Well-known name for the WebSessionManager in the bean factory.- See Also:
- Constant Field Values
SERVER_CODEC_CONFIGURER_BEAN_NAME
public static final String SERVER_CODEC_CONFIGURER_BEAN_NAME
Well-known name for the ServerCodecConfigurer in the bean factory.- See Also:
- Constant Field Values
LOCALE_CONTEXT_RESOLVER_BEAN_NAME
public static final String LOCALE_CONTEXT_RESOLVER_BEAN_NAME
Well-known name for the LocaleContextResolver in the bean factory.- See Also:
- Constant Field Values
FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
public static final String FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
Well-known name for the ForwardedHeaderTransformer in the bean factory.- See Also:
- Constant Field Values
Method Detail
webHandler
public static WebHttpHandlerBuilder webHandler(WebHandler webHandler)
Static factory method to create a new builder instance.- Parameters:
webHandler- the target handler for the request- Returns:
- 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.
- Parameters:
context- the application context to use for the lookup- Returns:
- the prepared builder
filter
public WebHttpHandlerBuilder filter(WebFilter... filters)
Add the given filter(s).- Parameters:
filters- the filter(s) to add that's
filters
public WebHttpHandlerBuilder filters(Consumer<List<WebFilter>> consumer)
Manipulate the "live" list of currently configured filters.- Parameters:
consumer- the consumer to use
exceptionHandler
public WebHttpHandlerBuilder exceptionHandler(WebExceptionHandler... handlers)
Add the given exception handler(s).- Parameters:
handlers- the exception handler(s)
exceptionHandlers
public WebHttpHandlerBuilder exceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)
Manipulate the "live" list of currently configured exception handlers.- Parameters:
consumer- the consumer to use
sessionManager
public WebHttpHandlerBuilder sessionManager(WebSessionManager manager)
Configure theWebSessionManagerto set on theWebServerExchange.By default
DefaultWebSessionManageris used.- Parameters:
manager- the session manager- See Also:
HttpWebHandlerAdapter.setSessionManager(WebSessionManager)
hasSessionManager
public boolean hasSessionManager()
Whether aWebSessionManageris configured or not, either detected from anApplicationContextor explicitly configured viasessionManager.- Since:
- 5.0.9
codecConfigurer
public WebHttpHandlerBuilder codecConfigurer(ServerCodecConfigurer 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
public WebHttpHandlerBuilder localeContextResolver(LocaleContextResolver 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
public WebHttpHandlerBuilder forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)
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
build
public HttpHandler build()
Build theHttpHandler.
clone
public WebHttpHandlerBuilder clone()
Clone thisWebHttpHandlerBuilder.