public final class WebHttpHandlerBuilder extends Object
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.
HttpWebHandlerAdapter
Modifier and Type | Field and 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.
|
Modifier and Type | Method and Description |
---|---|
static WebHttpHandlerBuilder |
applicationContext(ApplicationContext context)
Static factory method to create a new builder instance by detecting beans
in an
ApplicationContext . |
HttpHandler |
build()
Build the
HttpHandler . |
WebHttpHandlerBuilder |
clone()
Clone this
WebHttpHandlerBuilder . |
WebHttpHandlerBuilder |
codecConfigurer(ServerCodecConfigurer codecConfigurer)
Configure the
ServerCodecConfigurer to set on the WebServerExchange . |
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 the
ForwardedHeaderTransformer for extracting and/or
removing forwarded headers. |
boolean |
hasCodecConfigurer()
Whether a
ServerCodecConfigurer is configured or not, either detected from an
ApplicationContext or explicitly configured via codecConfigurer . |
boolean |
hasForwardedHeaderTransformer()
Whether a
ForwardedHeaderTransformer is configured or not, either
detected from an ApplicationContext or explicitly configured via
forwardedHeaderTransformer(ForwardedHeaderTransformer) . |
boolean |
hasHttpHandlerDecorator()
Whether a decorator for
HttpHandler is configured or not via
httpHandlerDecorator(Function) . |
boolean |
hasLocaleContextResolver()
Whether a
LocaleContextResolver is configured or not, either detected from an
ApplicationContext or explicitly configured via localeContextResolver . |
boolean |
hasSessionManager()
Whether a
WebSessionManager is configured or not, either detected from an
ApplicationContext or explicitly configured via sessionManager . |
WebHttpHandlerBuilder |
httpHandlerDecorator(Function<HttpHandler,HttpHandler> handlerDecorator)
Configure a
Function to decorate the HttpHandler returned
by this builder which effectively wraps the entire
WebExceptionHandler - WebFilter - WebHandler
processing chain. |
WebHttpHandlerBuilder |
localeContextResolver(LocaleContextResolver localeContextResolver)
Configure the
LocaleContextResolver to set on the
WebServerExchange . |
WebHttpHandlerBuilder |
sessionManager(WebSessionManager manager)
Configure the
WebSessionManager to set on the
WebServerExchange . |
static WebHttpHandlerBuilder |
webHandler(WebHandler webHandler)
Static factory method to create a new builder instance.
|
public static final String WEB_HANDLER_BEAN_NAME
public static final String WEB_SESSION_MANAGER_BEAN_NAME
public static final String SERVER_CODEC_CONFIGURER_BEAN_NAME
public static final String LOCALE_CONTEXT_RESOLVER_BEAN_NAME
public static final String FORWARDED_HEADER_TRANSFORMER_BEAN_NAME
public static WebHttpHandlerBuilder webHandler(WebHandler webHandler)
webHandler
- the target handler for the requestpublic static WebHttpHandlerBuilder applicationContext(ApplicationContext context)
ApplicationContext
. 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.
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
.
context
- the application context to use for the lookuppublic WebHttpHandlerBuilder filter(WebFilter... filters)
filters
- the filter(s) to add that'spublic WebHttpHandlerBuilder filters(Consumer<List<WebFilter>> consumer)
consumer
- the consumer to usepublic WebHttpHandlerBuilder exceptionHandler(WebExceptionHandler... handlers)
handlers
- the exception handler(s)public WebHttpHandlerBuilder exceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)
consumer
- the consumer to usepublic WebHttpHandlerBuilder sessionManager(WebSessionManager manager)
WebSessionManager
to set on the
WebServerExchange
.
By default DefaultWebSessionManager
is used.
manager
- the session managerHttpWebHandlerAdapter.setSessionManager(WebSessionManager)
public boolean hasSessionManager()
WebSessionManager
is configured or not, either detected from an
ApplicationContext
or explicitly configured via sessionManager
.public WebHttpHandlerBuilder codecConfigurer(ServerCodecConfigurer codecConfigurer)
ServerCodecConfigurer
to set on the WebServerExchange
.codecConfigurer
- the codec configurerpublic boolean hasCodecConfigurer()
ServerCodecConfigurer
is configured or not, either detected from an
ApplicationContext
or explicitly configured via codecConfigurer
.public WebHttpHandlerBuilder localeContextResolver(LocaleContextResolver localeContextResolver)
LocaleContextResolver
to set on the
WebServerExchange
.localeContextResolver
- the locale context resolverpublic boolean hasLocaleContextResolver()
LocaleContextResolver
is configured or not, either detected from an
ApplicationContext
or explicitly configured via localeContextResolver
.public WebHttpHandlerBuilder forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)
ForwardedHeaderTransformer
for extracting and/or
removing forwarded headers.transformer
- the transformerpublic boolean hasForwardedHeaderTransformer()
ForwardedHeaderTransformer
is configured or not, either
detected from an ApplicationContext
or explicitly configured via
forwardedHeaderTransformer(ForwardedHeaderTransformer)
.public WebHttpHandlerBuilder httpHandlerDecorator(Function<HttpHandler,HttpHandler> handlerDecorator)
Function
to decorate the HttpHandler
returned
by this builder which effectively wraps the entire
WebExceptionHandler
- 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.handlerDecorator
- the decorator to applypublic boolean hasHttpHandlerDecorator()
HttpHandler
is configured or not via
httpHandlerDecorator(Function)
.public HttpHandler build()
HttpHandler
.public WebHttpHandlerBuilder clone()
WebHttpHandlerBuilder
.