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
ApplicationContext
viaapplicationContext
, 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 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.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
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 theWebSessionManager
to set on theWebServerExchange
.By default
DefaultWebSessionManager
is used.- Parameters:
manager
- the session manager- See Also:
HttpWebHandlerAdapter.setSessionManager(WebSessionManager)
hasSessionManager
public boolean hasSessionManager()
Whether aWebSessionManager
is configured or not, either detected from anApplicationContext
or explicitly configured viasessionManager
.- Since:
- 5.0.9
codecConfigurer
public WebHttpHandlerBuilder codecConfigurer(ServerCodecConfigurer 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
public WebHttpHandlerBuilder localeContextResolver(LocaleContextResolver 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
public WebHttpHandlerBuilder forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)
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
build
public HttpHandler build()
Build theHttpHandler
.
clone
public WebHttpHandlerBuilder clone()
Clone thisWebHttpHandlerBuilder
.