Skip to content

Commit 4dbe9d6

Browse files
singhbaljitrstoyanchev
authored andcommitted
Use ContextView in ServerWebExchangeContextFilter
1 parent acedbfb commit 4dbe9d6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

spring-web/src/main/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import reactor.core.publisher.Mono;
2222
import reactor.util.context.Context;
23+
import reactor.util.context.ContextView;
2324

2425
import org.springframework.web.server.ServerWebExchange;
2526
import org.springframework.web.server.WebFilter;
@@ -32,7 +33,7 @@
3233
* exchange without explicitly passing it to components that participate in
3334
* request processing.
3435
*
35-
* <p>The convenience method {@link #get(Context)} looks up the exchange.
36+
* <p>The convenience method {@link #getExchange(ContextView)} looks up the exchange.
3637
*
3738
* @author Rossen Stoyanchev
3839
* @since 5.2
@@ -58,8 +59,22 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
5859
* @param context the context in which to access the exchange
5960
* @return the exchange
6061
*/
61-
public static Optional<ServerWebExchange> get(Context context) {
62+
public static Optional<ServerWebExchange> getExchange(ContextView context) {
6263
return context.getOrEmpty(EXCHANGE_CONTEXT_ATTRIBUTE);
6364
}
6465

66+
67+
/**
68+
* Access the {@link ServerWebExchange} from the Reactor Context, if available,
69+
* which is if {@link ServerWebExchangeContextFilter} is configured for use
70+
* and the give context was obtained from a request processing chain.
71+
* @param context the context in which to access the exchange
72+
* @return the exchange
73+
* @deprecated use {@link #getExchange(ContextView)}
74+
*/
75+
@Deprecated(since = "6.0.6")
76+
public static Optional<ServerWebExchange> get(Context context) {
77+
return getExchange(context);
78+
}
79+
6580
}

spring-web/src/test/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ServerWebExchange getExchange() {
6363

6464
public Mono<String> service() {
6565
return Mono.just("result").contextWrite(context -> {
66-
ServerWebExchangeContextFilter.get(context).ifPresent(exchangeRef::set);
66+
ServerWebExchangeContextFilter.getExchange(context).ifPresent(exchangeRef::set);
6767
return context;
6868
});
6969
}

0 commit comments

Comments
 (0)