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

public Class HttpWebHandlerAdapter

extends WebHandlerDecorator
implements HttpHandler
Class Inheritance
All Implemented Interfaces
org.springframework.http.server.reactive.HttpHandler
Imports
java.util.concurrent.atomic.AtomicBoolean, io.micrometer.observation.Observation, .ObservationRegistry, io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor, org.apache.commons.logging.Log, .LogFactory, reactor.core.observability.DefaultSignalListener, reactor.core.publisher.Mono, reactor.util.context.Context, org.springframework.context.ApplicationContext, org.springframework.core.log.LogFormatUtils, org.springframework.http.HttpHeaders, .HttpStatus, .HttpStatusCode, org.springframework.http.codec.LoggingCodecSupport, .ServerCodecConfigurer, org.springframework.http.server.reactive.HttpHandler, .ServerHttpRequest, .ServerHttpResponse, org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention, .ServerHttpObservationDocumentation, .ServerRequestObservationContext, .ServerRequestObservationConvention, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.server.ServerWebExchange, .WebHandler, org.springframework.web.server.handler.ExceptionHandlingWebHandler, .WebHandlerDecorator, org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver, .LocaleContextResolver, org.springframework.web.server.session.DefaultWebSessionManager, .WebSessionManager, org.springframework.web.util.DisconnectedClientHelper

Default adapter of WebHandler to the HttpHandler contract.

By default creates and configures a DefaultServerWebExchange and then invokes the target WebHandler.

Authors
Rossen Stoyanchev, Sebastien Deleuze, Brian Clozel
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private ApplicationContext
private ServerCodecConfigurer
private static final ServerRequestObservationConvention
private static final String
DISCONNECTED_CLIENT_LOG_CATEGORY

Log category to use for network failure after a client has gone away.

private static final DisconnectedClientHelper
private boolean
enableLoggingRequestDetails

Whether to log potentially sensitive info (form data at DEBUG, headers at TRACE).

private ForwardedHeaderTransformer
private LocaleContextResolver
private static final Log
private ServerRequestObservationConvention
private ObservationRegistry
private WebSessionManager

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

This method must be invoked after all properties have been set to complete initialization.

protected ServerWebExchange
private String
formatHeaders(HttpHeaders responseHeaders)

protected String

Returns:

the String to display, never empty or null
formatRequest
(ServerHttpRequest
the request to format
request
)

Format the request for logging purposes including HTTP method and URL.

public ApplicationContext
getApplicationContext()

Return the configured ApplicationContext, if any.

public ServerCodecConfigurer
getCodecConfigurer()

Return the configured ServerCodecConfigurer.

public ForwardedHeaderTransformer
public LocaleContextResolver
public ServerRequestObservationConvention
getObservationConvention()

Return the Observation convention configured for server exchanges observations.

public ObservationRegistry
public WebSessionManager
getSessionManager()

Return the configured WebSessionManager.

public Mono<Void>
handle(ServerHttpRequest
current request
request
,
ServerHttpResponse
current response
response
)

Implements org.springframework.http.server.reactive.HttpHandler.handle.

Handle the given request and write to the response.

private Mono<Void>
private void
public void
setApplicationContext(ApplicationContext
the context
applicationContext
)

Configure the ApplicationContext associated with the web application, if it was initialized with one via org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext).

public void
setCodecConfigurer(ServerCodecConfigurer
the codec configurer to use
codecConfigurer
)

Configure a custom ServerCodecConfigurer.

public void
setForwardedHeaderTransformer(ForwardedHeaderTransformer
the transformer to use
transformer
)

Enable processing of forwarded headers, either extracting and removing, or remove only.

public void
setLocaleContextResolver(LocaleContextResolver
the locale context resolver to use
resolver
)

Configure a custom LocaleContextResolver.

public void
setObservationConvention(ServerRequestObservationConvention
the observation convention to use
observationConvention
)

Configure a ServerRequestObservationConvention for server exchanges observations.

public void
setObservationRegistry(ObservationRegistry
the observation registry to use
observationRegistry
)

Configure an ObservationRegistry for recording server exchange observations.

public void
setSessionManager(WebSessionManager
the session manager to use
sessionManager
)

Configure a custom WebSessionManager to use for managing web sessions.

Inherited from org.springframework.web.server.handler.WebHandlerDecorator:
getDelegatehandletoString

Field Detail

applicationContextback to summary
private ApplicationContext applicationContext
Annotations
@Nullable
codecConfigurerback to summary
private ServerCodecConfigurer codecConfigurer
Annotations
@Nullable
DEFAULT_OBSERVATION_CONVENTIONback to summary
private static final ServerRequestObservationConvention DEFAULT_OBSERVATION_CONVENTION
DISCONNECTED_CLIENT_LOG_CATEGORYback to summary
private static final String DISCONNECTED_CLIENT_LOG_CATEGORY

Log category to use for network failure after a client has gone away.

See Also
DisconnectedClientHelper
disconnectedClientHelperback to summary
private static final DisconnectedClientHelper disconnectedClientHelper
enableLoggingRequestDetailsback to summary
private boolean enableLoggingRequestDetails

Whether to log potentially sensitive info (form data at DEBUG, headers at TRACE).

forwardedHeaderTransformerback to summary
private ForwardedHeaderTransformer forwardedHeaderTransformer
Annotations
@Nullable
localeContextResolverback to summary
private LocaleContextResolver localeContextResolver
loggerback to summary
private static final Log logger
observationConventionback to summary
private ServerRequestObservationConvention observationConvention
observationRegistryback to summary
private ObservationRegistry observationRegistry
sessionManagerback to summary
private WebSessionManager sessionManager

Constructor Detail

HttpWebHandlerAdapterback to summary
public HttpWebHandlerAdapter(WebHandler delegate)

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

This method must be invoked after all properties have been set to complete initialization.

createExchangeback to summary
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response)
formatHeadersback to summary
private String formatHeaders(HttpHeaders responseHeaders)
formatRequestback to summary
protected String formatRequest(ServerHttpRequest request)

Format the request for logging purposes including HTTP method and URL.

By default this prints the HTTP method, the URL path, and the query.

Parameters
request:ServerHttpRequest

the request to format

Returns:String

the String to display, never empty or null

getApplicationContextback to summary
public ApplicationContext getApplicationContext()

Return the configured ApplicationContext, if any.

Annotations
@Nullable
Since
5.0.3
getCodecConfigurerback to summary
public ServerCodecConfigurer getCodecConfigurer()

Return the configured ServerCodecConfigurer.

getForwardedHeaderTransformerback to summary
public ForwardedHeaderTransformer getForwardedHeaderTransformer()

Return the configured ForwardedHeaderTransformer.

Annotations
@Nullable
Since
5.1
getLocaleContextResolverback to summary
public LocaleContextResolver getLocaleContextResolver()

Return the configured LocaleContextResolver.

getObservationConventionback to summary
public ServerRequestObservationConvention getObservationConvention()

Return the Observation convention configured for server exchanges observations.

Since
6.1
getObservationRegistryback to summary
public ObservationRegistry getObservationRegistry()

Return the configured ObservationRegistry.

Since
6.1
getSessionManagerback to summary
public WebSessionManager getSessionManager()

Return the configured WebSessionManager.

handleback to summary
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)

Implements org.springframework.http.server.reactive.HttpHandler.handle.

Doc from org.springframework.http.server.reactive.HttpHandler.handle.

Handle the given request and write to the response.

Parameters
request:ServerHttpRequest

current request

response:ServerHttpResponse

current response

Returns:Mono<Void>

indicates completion of request handling

Annotations
@Override
handleUnresolvedErrorback to summary
private Mono<Void> handleUnresolvedError(ServerWebExchange exchange, ServerRequestObservationContext observationContext, Throwable ex)
logResponseback to summary
private void logResponse(ServerWebExchange exchange)
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext)

Configure the ApplicationContext associated with the web application, if it was initialized with one via org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext).

Parameters
applicationContext:ApplicationContext

the context

Since
5.0.3
setCodecConfigurerback to summary
public void setCodecConfigurer(ServerCodecConfigurer codecConfigurer)

Configure a custom ServerCodecConfigurer. The provided instance is set on each created DefaultServerWebExchange.

By default this is set to ServerCodecConfigurer#create().

Parameters
codecConfigurer:ServerCodecConfigurer

the codec configurer to use

setForwardedHeaderTransformerback to summary
public void setForwardedHeaderTransformer(ForwardedHeaderTransformer transformer)

Enable processing of forwarded headers, either extracting and removing, or remove only.

By default this is not set.

Parameters
transformer:ForwardedHeaderTransformer

the transformer to use

Since
5.1
setLocaleContextResolverback to summary
public void setLocaleContextResolver(LocaleContextResolver resolver)

Configure a custom LocaleContextResolver. The provided instance is set on each created DefaultServerWebExchange.

By default this is set to org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver.

Parameters
resolver:LocaleContextResolver

the locale context resolver to use

setObservationConventionback to summary
public void setObservationConvention(ServerRequestObservationConvention observationConvention)

Configure a ServerRequestObservationConvention for server exchanges observations. By default, a DefaultServerRequestObservationConvention instance will be used.

Parameters
observationConvention:ServerRequestObservationConvention

the observation convention to use

Since
6.1
setObservationRegistryback to summary
public void setObservationRegistry(ObservationRegistry observationRegistry)

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

Parameters
observationRegistry:ObservationRegistry

the observation registry to use

Since
6.1
setSessionManagerback to summary
public void setSessionManager(WebSessionManager sessionManager)

Configure a custom WebSessionManager to use for managing web sessions. The provided instance is set on each created DefaultServerWebExchange.

By default this is set to DefaultWebSessionManager.

Parameters
sessionManager:WebSessionManager

the session manager to use

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

private final Class HttpWebHandlerAdapter.ObservationSignalListener

extends DefaultSignalListener<Void>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Observation
private final ServerRequestObservationContext
private final AtomicBoolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Context
addToContext(Context
the original downstream operator's Context
originalContext
)

Overrides default reactor.core.observability.SignalListener.addToContext.

In some cases, the tap operation should alter the Context exposed by the operator in order to store additional data.

public void
public void
public void
public void
doOnError(Throwable
the exception that terminated the sequence
error
)

Overrides reactor.core.observability.DefaultSignalListener.doOnError.

Implements reactor.core.observability.SignalListener.doOnError.

Handle onError sequence termination.

private void
Inherited from reactor.core.observability.DefaultSignalListener:
doAfterCompletedoAfterErrordoFinallydoOnFusiondoOnMalformedOnCompletedoOnMalformedOnErrordoOnMalformedOnNextdoOnNextdoOnRequestdoOnSubscriptiongetFusionModehandleListenerError

Field Detail

observationback to summary
private final Observation observation
observationContextback to summary
private final ServerRequestObservationContext observationContext
observationRecordedback to summary
private final AtomicBoolean observationRecorded

Constructor Detail

ObservationSignalListenerback to summary
pack-priv ObservationSignalListener(ServerRequestObservationContext observationContext)

Method Detail

addToContextback to summary
public Context addToContext(Context originalContext)

Overrides default reactor.core.observability.SignalListener.addToContext.

Doc from reactor.core.observability.SignalListener.addToContext.

In some cases, the tap operation should alter the Context exposed by the operator in order to store additional data. This method is invoked when the tap subscriber is created, which is between the invocation of doFirst() and the invocation of doOnSubscription(). Generally, only addition of new keys should be performed on the downstream original Context. Extra care should be exercised if any pre-existing key is to be removed or replaced.

Parameters
originalContext:Context

the original downstream operator's Context

Returns:Context

the Context to use and expose upstream

Annotations
@Override
doFirstback to summary
public void doFirst() throws Throwable

Overrides reactor.core.observability.DefaultSignalListener.doFirst.

Implements reactor.core.observability.SignalListener.doFirst.

Doc from reactor.core.observability.SignalListener.doFirst.

Handle the very beginning of the Subscriber-Publisher interaction. This handler is invoked right before subscribing to the parent Publisher, as a downstream Subscriber has called Publisher#subscribe(Subscriber).

Once the Publisher has acknowledged with a Subscription, the doOnSubscription() handler will be invoked before that Subscription is passed down.

Annotations
@Override
doOnCancelback to summary
public void doOnCancel() throws Throwable

Overrides reactor.core.observability.DefaultSignalListener.doOnCancel.

Implements reactor.core.observability.SignalListener.doOnCancel.

Doc from reactor.core.observability.SignalListener.doOnCancel.

Handle the downstream cancelling its currently observed Subscription.

This handler is invoked before propagating the cancellation upstream, while doFinally(SignalType) is invoked right after the cancellation has been propagated upstream.

Annotations
@Override
doOnCompleteback to summary
public void doOnComplete() throws Throwable

Overrides reactor.core.observability.DefaultSignalListener.doOnComplete.

Implements reactor.core.observability.SignalListener.doOnComplete.

Doc from reactor.core.observability.SignalListener.doOnComplete.

Handle graceful onComplete sequence termination.

This handler is invoked before propagating the completion downstream, while both doAfterComplete() and doFinally(SignalType) are invoked after.

Annotations
@Override
doOnErrorback to summary
public void doOnError(Throwable error) throws Throwable

Overrides reactor.core.observability.DefaultSignalListener.doOnError.

Implements reactor.core.observability.SignalListener.doOnError.

Doc from reactor.core.observability.SignalListener.doOnError.

Handle onError sequence termination.

This handler is invoked before propagating the error downstream, while both doAfterError(Throwable) and doFinally(SignalType) are invoked after.

Parameters
error:Throwable

the exception that terminated the sequence

Annotations
@Override
doOnTerminateback to summary
private void doOnTerminate(ServerRequestObservationContext context)