Skip to content

Provide method with ContextView instead of Context in ServerWebExchangeContextFilter #29691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import reactor.core.publisher.Mono;
import reactor.util.context.Context;
import reactor.util.context.ContextView;

import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
Expand All @@ -32,7 +33,7 @@
* exchange without explicitly passing it to components that participate in
* request processing.
*
* <p>The convenience method {@link #get(Context)} looks up the exchange.
* <p>The convenience method {@link #getExchange(ContextView)} looks up the exchange.
*
* @author Rossen Stoyanchev
* @since 5.2
Expand All @@ -58,8 +59,22 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
* @param context the context in which to access the exchange
* @return the exchange
*/
public static Optional<ServerWebExchange> get(Context context) {
public static Optional<ServerWebExchange> getExchange(ContextView context) {
return context.getOrEmpty(EXCHANGE_CONTEXT_ATTRIBUTE);
}


/**
* Access the {@link ServerWebExchange} from the Reactor Context, if available,
* which is if {@link ServerWebExchangeContextFilter} is configured for use
* and the give context was obtained from a request processing chain.
* @param context the context in which to access the exchange
* @return the exchange
* @deprecated use {@link #getExchange(ContextView)}
*/
@Deprecated(since = "6.0.6")
public static Optional<ServerWebExchange> get(Context context) {
return getExchange(context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ServerWebExchange getExchange() {

public Mono<String> service() {
return Mono.just("result").contextWrite(context -> {
ServerWebExchangeContextFilter.get(context).ifPresent(exchangeRef::set);
ServerWebExchangeContextFilter.getExchange(context).ifPresent(exchangeRef::set);
return context;
});
}
Expand Down