Package org.springframework.web.filter.reactive

# 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 Summary

Fields
Modifier and Type
Field
Description
`static final String`
`EXCHANGE_CONTEXT_ATTRIBUTE`
Attribute name under which the exchange is saved in the context.

## Constructor Summary

Constructors
Constructor
Description
`ServerWebExchangeContextFilter()`

## Method Summary

Modifier and Type
Method
Description
`reactor.core.publisher.Mono<Void>`
`filter(ServerWebExchange exchange, WebFilterChain chain)`
Process the Web request and (optionally) delegate to the next `WebFilter` through the given `WebFilterChain`.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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