Top Description Inners Fields Constructors Methods
org.springframework.web.server.adapter

public final Class WebHttpHandlerBuilder

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .List, java.util.function.Consumer, .Function, io.micrometer.observation.ObservationRegistry, reactor.blockhound.BlockHound, reactor.blockhound.integration.BlockHoundIntegration, org.springframework.beans.factory.NoSuchBeanDefinitionException, org.springframework.context.ApplicationContext, org.springframework.core.annotation.AnnotationAwareOrderComparator, org.springframework.http.codec.ServerCodecConfigurer, org.springframework.http.server.reactive.HttpHandler, .HttpHandlerDecoratorFactory, org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention, .ServerRequestObservationConvention, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, org.springframework.web.server.ServerWebExchange, .WebExceptionHandler, .WebFilter, .WebHandler, org.springframework.web.server.handler.ExceptionHandlingWebHandler, .FilteringWebHandler, org.springframework.web.server.i18n.LocaleContextResolver, org.springframework.web.server.session.DefaultWebSessionManager, .WebSessionManager

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.

Authors
Rossen Stoyanchev, Sebastien Deleuze
Since
5.0
See Also
HttpWebHandlerAdapter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
WebHttpHandlerBuilder.SpringWebBlockHoundIntegration

BlockHoundIntegration for spring-web classes.

Field Summary

Modifier and TypeField and Description
private final ApplicationContext
private ServerCodecConfigurer
private final List<WebExceptionHandler>
private final List<WebFilter>
public static final String
FORWARDED_HEADER_TRANSFORMER_BEAN_NAME

Well-known name for the ForwardedHeaderTransformer in the bean factory.

private ForwardedHeaderTransformer
private Function<HttpHandler, HttpHandler>
public static final String
LOCALE_CONTEXT_RESOLVER_BEAN_NAME

Well-known name for the LocaleContextResolver in the bean factory.

private LocaleContextResolver
private ServerRequestObservationConvention
private ObservationRegistry
public static final String
SERVER_CODEC_CONFIGURER_BEAN_NAME

Well-known name for the ServerCodecConfigurer in the bean factory.

private WebSessionManager
public static final String
WEB_HANDLER_BEAN_NAME

Well-known name for the target WebHandler in the bean factory.

public static final String
WEB_SESSION_MANAGER_BEAN_NAME

Well-known name for the WebSessionManager in the bean factory.

private final WebHandler

Constructor Summary

AccessConstructor and Description
private
WebHttpHandlerBuilder(WebHandler webHandler, ApplicationContext applicationContext)

Private constructor to use when initialized from an ApplicationContext.

private

Method Summary

Modifier and TypeMethod and Description
public static WebHttpHandlerBuilder

Returns:

the prepared builder
applicationContext
(ApplicationContext
the application context to use for the lookup
context
)

Static factory method to create a new builder instance by detecting beans in an ApplicationContext.

public HttpHandler
build()

Build the HttpHandler.

public WebHttpHandlerBuilder

Returns:

the cloned builder instance
clone
()

Overrides java.lang.Object.clone.

Clone this WebHttpHandlerBuilder.

public WebHttpHandlerBuilder
codecConfigurer(ServerCodecConfigurer
the codec configurer
codecConfigurer
)

Configure the ServerCodecConfigurer to set on the WebServerExchange.

public WebHttpHandlerBuilder
exceptionHandler(WebExceptionHandler...
the exception handler(s)
handlers
)

Add the given exception handler(s).

public WebHttpHandlerBuilder
exceptionHandlers(Consumer<List<WebExceptionHandler>>
the consumer to use
consumer
)

Manipulate the "live" list of currently configured exception handlers.

public WebHttpHandlerBuilder
filter(WebFilter...
the filter(s) to add that's
filters
)

Add the given filter(s).

public WebHttpHandlerBuilder
filters(Consumer<List<WebFilter>>
the consumer to use
consumer
)

Manipulate the "live" list of currently configured filters.

public WebHttpHandlerBuilder
forwardedHeaderTransformer(ForwardedHeaderTransformer
the transformer
transformer
)

Configure the ForwardedHeaderTransformer for extracting and/or removing forwarded headers.

public boolean
hasCodecConfigurer()

Whether a ServerCodecConfigurer is configured or not, either detected from an ApplicationContext or explicitly configured via codecConfigurer.

public boolean
hasForwardedHeaderTransformer()

Whether a ForwardedHeaderTransformer is configured or not, either detected from an ApplicationContext or explicitly configured via forwardedHeaderTransformer(ForwardedHeaderTransformer).

public boolean
hasHttpHandlerDecorator()

Whether a decorator for HttpHandler is configured or not via httpHandlerDecorator(Function).

public boolean
hasLocaleContextResolver()

Whether a LocaleContextResolver is configured or not, either detected from an ApplicationContext or explicitly configured via localeContextResolver.

public boolean
hasSessionManager()

Whether a WebSessionManager is configured or not, either detected from an ApplicationContext or explicitly configured via sessionManager.

public WebHttpHandlerBuilder
httpHandlerDecorator(Function<HttpHandler, HttpHandler>
the decorator to apply
handlerDecorator
)

Configure a Function to decorate the HttpHandler returned by this builder which effectively wraps the entire WebExceptionHandler - WebFilter - WebHandler processing chain.

public WebHttpHandlerBuilder
localeContextResolver(LocaleContextResolver
the locale context resolver
localeContextResolver
)

Configure the LocaleContextResolver to set on the WebServerExchange.

public WebHttpHandlerBuilder
observationConvention(ServerRequestObservationConvention
the convention to use for all recorded observations
observationConvention
)

Configure a ServerRequestObservationConvention to use for server observations.

public WebHttpHandlerBuilder
observationRegistry(ObservationRegistry
the observation registry
observationRegistry
)

Configure an ObservationRegistry for recording server exchange observations.

public WebHttpHandlerBuilder
sessionManager(WebSessionManager
the session manager
manager
)

Configure the WebSessionManager to set on the WebServerExchange.

private void
public static WebHttpHandlerBuilder

Returns:

the prepared builder
webHandler
(WebHandler
the target handler for the request
webHandler
)

Static factory method to create a new builder instance.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationContextback to summary
private final ApplicationContext applicationContext
Annotations
@Nullable
codecConfigurerback to summary
private ServerCodecConfigurer codecConfigurer
Annotations
@Nullable
exceptionHandlersback to summary
private final List<WebExceptionHandler> exceptionHandlers
filtersback to summary
private final List<WebFilter> filters
FORWARDED_HEADER_TRANSFORMER_BEAN_NAMEback to summary
public static final String FORWARDED_HEADER_TRANSFORMER_BEAN_NAME

Well-known name for the ForwardedHeaderTransformer in the bean factory.

forwardedHeaderTransformerback to summary
private ForwardedHeaderTransformer forwardedHeaderTransformer
Annotations
@Nullable
httpHandlerDecoratorback to summary
private Function<HttpHandler, HttpHandler> httpHandlerDecorator
Annotations
@Nullable
LOCALE_CONTEXT_RESOLVER_BEAN_NAMEback to summary
public static final String LOCALE_CONTEXT_RESOLVER_BEAN_NAME

Well-known name for the LocaleContextResolver in the bean factory.

localeContextResolverback to summary
private LocaleContextResolver localeContextResolver
Annotations
@Nullable
observationConventionback to summary
private ServerRequestObservationConvention observationConvention
Annotations
@Nullable
observationRegistryback to summary
private ObservationRegistry observationRegistry
Annotations
@Nullable
SERVER_CODEC_CONFIGURER_BEAN_NAMEback to summary
public static final String SERVER_CODEC_CONFIGURER_BEAN_NAME

Well-known name for the ServerCodecConfigurer in the bean factory.

sessionManagerback to summary
private WebSessionManager sessionManager
Annotations
@Nullable
WEB_HANDLER_BEAN_NAMEback to summary
public static final String WEB_HANDLER_BEAN_NAME

Well-known name for the target WebHandler in the bean factory.

WEB_SESSION_MANAGER_BEAN_NAMEback to summary
public static final String WEB_SESSION_MANAGER_BEAN_NAME

Well-known name for the WebSessionManager in the bean factory.

webHandlerback to summary
private final WebHandler webHandler

Constructor Detail

WebHttpHandlerBuilderback to summary
private WebHttpHandlerBuilder(WebHandler webHandler, ApplicationContext applicationContext)

Private constructor to use when initialized from an ApplicationContext.

WebHttpHandlerBuilderback to summary
private WebHttpHandlerBuilder(WebHttpHandlerBuilder other)

Copy constructor.

Method Detail

applicationContextback to summary
public static WebHttpHandlerBuilder applicationContext(ApplicationContext context)

Static factory method to create a new builder instance by detecting beans in an ApplicationContext. The following are detected:

Parameters
context:ApplicationContext

the application context to use for the lookup

Returns:WebHttpHandlerBuilder

the prepared builder

buildback to summary
public HttpHandler build()

Build the HttpHandler.

cloneback to summary
public WebHttpHandlerBuilder clone()

Overrides java.lang.Object.clone.

Clone this WebHttpHandlerBuilder.

Returns:WebHttpHandlerBuilder

the cloned builder instance

Annotations
@Override
codecConfigurerback to summary
public WebHttpHandlerBuilder codecConfigurer(ServerCodecConfigurer codecConfigurer)

Configure the ServerCodecConfigurer to set on the WebServerExchange.

Parameters
codecConfigurer:ServerCodecConfigurer

the codec configurer

exceptionHandlerback to summary
public WebHttpHandlerBuilder exceptionHandler(WebExceptionHandler... handlers)

Add the given exception handler(s).

Parameters
handlers:WebExceptionHandler[]

the exception handler(s)

exceptionHandlersback to summary
public WebHttpHandlerBuilder exceptionHandlers(Consumer<List<WebExceptionHandler>> consumer)

Manipulate the "live" list of currently configured exception handlers.

Parameters
consumer:Consumer<List<WebExceptionHandler>>

the consumer to use

filterback to summary
public WebHttpHandlerBuilder filter(WebFilter... filters)

Add the given filter(s).

Parameters
filters:WebFilter[]

the filter(s) to add that's

filtersback to summary
public WebHttpHandlerBuilder filters(Consumer<List<WebFilter>> consumer)

Manipulate the "live" list of currently configured filters.

Parameters
consumer:Consumer<List<WebFilter>>

the consumer to use

forwardedHeaderTransformerback to summary
public WebHttpHandlerBuilder forwardedHeaderTransformer(ForwardedHeaderTransformer transformer)

Configure the ForwardedHeaderTransformer for extracting and/or removing forwarded headers.

Parameters
transformer:ForwardedHeaderTransformer

the transformer

Since
5.1
hasCodecConfigurerback to summary
public boolean hasCodecConfigurer()

Whether a ServerCodecConfigurer is configured or not, either detected from an ApplicationContext or explicitly configured via codecConfigurer.

Since
5.0.9
hasForwardedHeaderTransformerback to summary
public boolean hasForwardedHeaderTransformer()

Whether a ForwardedHeaderTransformer is configured or not, either detected from an ApplicationContext or explicitly configured via forwardedHeaderTransformer(ForwardedHeaderTransformer).

Since
5.1
hasHttpHandlerDecoratorback to summary
public boolean hasHttpHandlerDecorator()

Whether a decorator for HttpHandler is configured or not via httpHandlerDecorator(Function).

Since
5.3
hasLocaleContextResolverback to summary
public boolean hasLocaleContextResolver()

Whether a LocaleContextResolver is configured or not, either detected from an ApplicationContext or explicitly configured via localeContextResolver.

Since
5.0.9
hasSessionManagerback to summary
public boolean hasSessionManager()

Whether a WebSessionManager is configured or not, either detected from an ApplicationContext or explicitly configured via sessionManager.

Since
5.0.9
httpHandlerDecoratorback to summary
public 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. 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:Function<HttpHandler, HttpHandler>

the decorator to apply

Since
5.3
localeContextResolverback to summary
public WebHttpHandlerBuilder localeContextResolver(LocaleContextResolver localeContextResolver)

Configure the LocaleContextResolver to set on the WebServerExchange.

Parameters
localeContextResolver:LocaleContextResolver

the locale context resolver

observationConventionback to summary
public WebHttpHandlerBuilder observationConvention(ServerRequestObservationConvention observationConvention)

Configure a ServerRequestObservationConvention to use for server observations. By default, a DefaultServerRequestObservationConvention will be used.

Parameters
observationConvention:ServerRequestObservationConvention

the convention to use for all recorded observations

Since
6.1
observationRegistryback to summary
public WebHttpHandlerBuilder observationRegistry(ObservationRegistry observationRegistry)

Configure an ObservationRegistry for recording server exchange observations. By default, a no-op registry will be configured.

Parameters
observationRegistry:ObservationRegistry

the observation registry

Since
6.1
sessionManagerback to summary
public WebHttpHandlerBuilder sessionManager(WebSessionManager manager)

Configure the WebSessionManager to set on the WebServerExchange.

By default DefaultWebSessionManager is used.

Parameters
manager:WebSessionManager

the session manager

See Also
HttpWebHandlerAdapter#setSessionManager(WebSessionManager)
updateFiltersback to summary
private void updateFilters()
webHandlerback to summary
public static WebHttpHandlerBuilder webHandler(WebHandler webHandler)

Static factory method to create a new builder instance.

Parameters
webHandler:WebHandler

the target handler for the request

Returns:WebHttpHandlerBuilder

the prepared builder

org.springframework.web.server.adapter back to summary

public Class WebHttpHandlerBuilder.SpringWebBlockHoundIntegration

extends Object
implements BlockHoundIntegration
Class Inheritance
  • java.lang.Object
  • org.springframework.web.server.adapter.WebHttpHandlerBuilder.SpringWebBlockHoundIntegration
All Implemented Interfaces
reactor.blockhound.integration.BlockHoundIntegration, java.lang.Comparable

BlockHoundIntegration for spring-web classes.
Since
5.3.6

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
applyTo(BlockHound.Builder
an instance of BlockHound.Builder that is being installed
builder
)

Implements reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Lets an integration apply the customizations (see BlockHound.Builder) before BlockHound is installed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SpringWebBlockHoundIntegrationback to summary
public SpringWebBlockHoundIntegration()

Method Detail

applyToback to summary
public void applyTo(BlockHound.Builder builder)

Implements reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Doc from reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Lets an integration apply the customizations (see BlockHound.Builder) before BlockHound is installed.

Parameters
builder:BlockHound.Builder

an instance of BlockHound.Builder that is being installed

Annotations
@Override