#983 - Switch to Spring's ServerWebExchangeContextFilter.

Replace HypermediaWebFilter with ServerWebExchangeContextFilter.

Related issues: #986, spring-projects/spring-framework#21746.
This commit is contained in:
Greg Turnquist
2019-04-16 11:20:54 -05:00
committed by Oliver Drotbohm
parent 440e1852cc
commit 6a7e343acc
5 changed files with 13 additions and 59 deletions

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas.server.reactive;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
/**
* {@link WebFilter} that ensures a copy of the {@link ServerWebExchange} is added to the Reactor {@link Context}.
*
* @author Greg Turnquist
* @since 1.0
*/
public class HypermediaWebFilter implements WebFilter {
public static final String SERVER_WEB_EXCHANGE = "serverWebExchange";
/*
* (non-Javadoc)
* @see org.springframework.web.server.WebFilter#filter(org.springframework.web.server.ServerWebExchange, org.springframework.web.server.WebFilterChain)
*/
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange) //
.subscriberContext(Context.of(SERVER_WEB_EXCHANGE, exchange));
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.hateoas.server.reactive;
import static org.springframework.hateoas.server.reactive.HypermediaWebFilter.*;
import static org.springframework.web.filter.reactive.ServerWebExchangeContextFilter.*;
import lombok.RequiredArgsConstructor;
@@ -241,7 +241,7 @@ public class WebFluxLinkBuilder extends TemplateVariableAwareLinkBuilderSupport<
private static Mono<WebFluxLinkBuilder> linkToInternal(Object invocation) {
return linkToInternal(invocation,
Mono.subscriberContext().map(context -> getBuilder(context.getOrDefault(SERVER_WEB_EXCHANGE, null))));
Mono.subscriberContext().map(context -> getBuilder(context.getOrDefault(EXCHANGE_CONTEXT_ATTRIBUTE, null))));
}
private static Mono<WebFluxLinkBuilder> linkToInternal(Object invocation, Mono<UriComponentsBuilder> exchange) {