Class ServerwebExchangeContextFilter

java.lang.Object
org.springframework.web.filter.reactive.ServerwebExchangeContextFilter
All Implemented Interfaces:
webFilter

public class ServerwebExchangeContextFilter extends Object implements webFilter
Inserts an attribute in the Reactor Context that makes the current ServerwebExchange available under the attribute name EXCHANGE_CONTEXT_ATTRIBUTE. This is useful for access to the exchange without explicitly passing it to components that participate in request processing.

The convenience method getExchange(ContextView) looks up the exchange.

Since:
5.2
Author:
Rossen Stoyanchev
  • Field Details

    • EXCHANGE_CONTEXT_ATTRIBUTE

      public static final String EXCHANGE_CONTEXT_ATTRIBUTE
      Attribute name under which the exchange is saved in the context.
  • Constructor Details

    • ServerwebExchangeContextFilter

      public ServerwebExchangeContextFilter()
  • Method Details

    • filter

      public reactor.core.publisher.Mono<Void> filter(ServerwebExchange exchange, webFilterChain chain)
      Description copied from interface: webFilter
      Process the web request and (optionally) delegate to the next webFilter through the given webFilterChain.
      Specified by:
      filter in interface webFilter
      Parameters:
      exchange - the current server exchange
      chain - provides a way to delegate to the next filter
      Returns:
      Mono<Void> to indicate when request processing is complete
    • getExchange

      public static Optional<ServerwebExchange> getExchange(reactor.util.context.ContextView contextView)
      Access the ServerwebExchange from a Reactor ContextView, if available, which is generally the case when ServerwebExchangeContextFilter is present in the filter chain.
      Parameters:
      contextView - the contextView to get the exchange from
      Returns:
      an Optional with the exchange if found
      Since:
      6.0.6