Remove APIs marked as deprecated for removal

Closes gh-33809
This commit is contained in:
Juergen Hoeller
2024-12-04 13:19:39 +01:00
parent 078d683f47
commit 2b9010c2a2
150 changed files with 141 additions and 5922 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2024 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.
@@ -32,7 +32,6 @@ import org.springframework.web.reactive.resource.PathResourceResolver;
import org.springframework.web.reactive.resource.ResourceResolver;
import org.springframework.web.reactive.resource.ResourceTransformer;
import org.springframework.web.reactive.resource.VersionResourceResolver;
import org.springframework.web.reactive.resource.WebJarsResourceResolver;
/**
* Assists with the registration of resource resolvers and transformers.
@@ -44,10 +43,7 @@ public class ResourceChainRegistration {
private static final String DEFAULT_CACHE_NAME = "spring-resource-chain-cache";
private static final boolean isWebJarAssetLocatorPresent = ClassUtils.isPresent(
"org.webjars.WebJarAssetLocator", ResourceChainRegistration.class.getClassLoader());
private static final boolean isWebJarVersionLocatorPresent = ClassUtils.isPresent(
private static final boolean webJarsPresent = ClassUtils.isPresent(
"org.webjars.WebJarVersionLocator", ResourceChainRegistration.class.getClassLoader());
@@ -93,7 +89,7 @@ public class ResourceChainRegistration {
else if (resolver instanceof PathResourceResolver) {
this.hasPathResolver = true;
}
else if (resolver instanceof WebJarsResourceResolver || resolver instanceof LiteWebJarsResourceResolver) {
else if (resolver instanceof LiteWebJarsResourceResolver) {
this.hasWebjarsResolver = true;
}
return this;
@@ -113,16 +109,12 @@ public class ResourceChainRegistration {
return this;
}
@SuppressWarnings("removal")
protected List<ResourceResolver> getResourceResolvers() {
if (!this.hasPathResolver) {
List<ResourceResolver> result = new ArrayList<>(this.resolvers);
if (isWebJarVersionLocatorPresent && !this.hasWebjarsResolver) {
if (webJarsPresent && !this.hasWebjarsResolver) {
result.add(new LiteWebJarsResourceResolver());
}
else if (isWebJarAssetLocatorPresent && !this.hasWebjarsResolver) {
result.add(new WebJarsResourceResolver());
}
result.add(new PathResourceResolver());
return result;
}

View File

@@ -42,15 +42,6 @@ public class ClientRequestObservationContext extends RequestReplySenderContext<C
private ClientRequest request;
/**
* Create a new Observation context for HTTP client observations.
* @deprecated as of 6.1.2, in favor of {@link #ClientRequestObservationContext(ClientRequest.Builder)}
*/
@Deprecated(since = "6.1.2", forRemoval = true)
public ClientRequestObservationContext() {
super(ClientRequestObservationContext::setRequestHeader);
}
/**
* Create a new Observation context for HTTP client observations.
* @param request client request builder
@@ -116,5 +107,4 @@ public class ClientRequestObservationContext extends RequestReplySenderContext<C
return this.request;
}
}

View File

@@ -57,17 +57,6 @@ public interface ClientResponse {
*/
HttpStatusCode statusCode();
/**
* Return the raw status code of this response.
* @return the HTTP status as an integer value
* @since 5.1
* @deprecated in favor of {@link #statusCode()}, for removal in 7.0
*/
@Deprecated(since = "6.0", forRemoval = true)
default int rawStatusCode() {
return statusCode().value();
}
/**
* Return the headers of this response.
*/

View File

@@ -319,13 +319,6 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return this.statusCode;
}
@Override
@Deprecated
@SuppressWarnings("removal")
public int rawStatusCode() {
return this.statusCode.value();
}
@Override
public final HttpHeaders headers() {
return this.headers;

View File

@@ -66,15 +66,6 @@ public interface ServerResponse {
*/
HttpStatusCode statusCode();
/**
* Return the status code of this response as integer.
* @return the status as an integer
* @since 5.2
* @deprecated in favor of {@link #statusCode()}, for removal in 7.0
*/
@Deprecated(since = "6.0", forRemoval = true)
int rawStatusCode();
/**
* Return the headers of this response.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -161,7 +161,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
}
}
@SuppressWarnings({"unchecked", "removal"})
@SuppressWarnings("unchecked")
private void setAttributes(
Map<String, Object> attributes, ServerRequest serverRequest, HandlerFunction<?> handlerFunction) {
@@ -171,9 +171,6 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
PathPattern matchingPattern = (PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
if (matchingPattern != null) {
attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern);
org.springframework.web.filter.reactive.ServerHttpObservationFilter
.findObservationContext(serverRequest.exchange())
.ifPresent(context -> context.setPathPattern(matchingPattern.toString()));
ServerRequestObservationContext.findCurrent(serverRequest.exchange().getAttributes())
.ifPresent(context -> context.setPathPattern(matchingPattern.toString()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -167,9 +167,6 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handler);
exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, pattern);
org.springframework.web.filter.reactive.ServerHttpObservationFilter
.findObservationContext(exchange)
.ifPresent(context -> context.setPathPattern(pattern.toString()));
ServerRequestObservationContext.findCurrent(exchange.getAttributes())
.ifPresent(context -> context.setPathPattern(pattern.toString()));
exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, pathWithinMapping);

View File

@@ -1,125 +0,0 @@
/*
* Copyright 2002-2024 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.web.reactive.resource;
import java.util.List;
import org.webjars.WebJarAssetLocator;
import reactor.core.publisher.Mono;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
import org.springframework.web.server.ServerWebExchange;
/**
* A {@code ResourceResolver} that delegates to the chain to locate a resource and then
* attempts to find a matching versioned resource contained in a WebJar JAR file.
*
* <p>This allows WebJars.org users to write version agnostic paths in their templates,
* like {@code <script src="/webjars/jquery/jquery.min.js"/>}.
* This path will be resolved to the unique version {@code <script src="/webjars/jquery/1.2.0/jquery.min.js"/>},
* which is a better fit for HTTP caching and version management in applications.
*
* <p>This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
*
* <p>This resolver requires the {@code org.webjars:webjars-locator-core} library
* on the classpath and is automatically registered if that library is present.
*
* <p>Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that
* could slow down application startup.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @since 5.0
* @see <a href="https://www.webjars.org">webjars.org</a>
* @deprecated as of 6.2, in favor of {@link LiteWebJarsResourceResolver}
*/
@Deprecated(since = "6.2", forRemoval = true)
public class WebJarsResourceResolver extends AbstractResourceResolver {
private static final String WEBJARS_LOCATION = "META-INF/resources/webjars/";
private static final int WEBJARS_LOCATION_LENGTH = WEBJARS_LOCATION.length();
private final WebJarAssetLocator webJarAssetLocator;
/**
* Create a {@code WebJarsResourceResolver} with a default {@code WebJarAssetLocator} instance.
*/
public WebJarsResourceResolver() {
this(new WebJarAssetLocator());
}
/**
* Create a {@code WebJarsResourceResolver} with a custom {@code WebJarAssetLocator} instance,
* for example, with a custom index.
*/
public WebJarsResourceResolver(WebJarAssetLocator webJarAssetLocator) {
this.webJarAssetLocator = webJarAssetLocator;
}
@Override
protected Mono<Resource> resolveResourceInternal(@Nullable ServerWebExchange exchange,
String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveResource(exchange, requestPath, locations)
.switchIfEmpty(Mono.defer(() -> {
String webJarsResourcePath = findWebJarResourcePath(requestPath);
if (webJarsResourcePath != null) {
return chain.resolveResource(exchange, webJarsResourcePath, locations);
}
else {
return Mono.empty();
}
}));
}
@Override
protected Mono<String> resolveUrlPathInternal(String resourceUrlPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveUrlPath(resourceUrlPath, locations)
.switchIfEmpty(Mono.defer(() -> {
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
if (webJarResourcePath != null) {
return chain.resolveUrlPath(webJarResourcePath, locations);
}
else {
return Mono.empty();
}
}));
}
@Nullable
protected String findWebJarResourcePath(String path) {
int startOffset = (path.startsWith("/") ? 1 : 0);
int endOffset = path.indexOf('/', 1);
if (endOffset != -1) {
String webjar = path.substring(startOffset, endOffset);
String partialPath = path.substring(endOffset + 1);
String webJarPath = this.webJarAssetLocator.getFullPathExact(webjar, partialPath);
if (webJarPath != null) {
return webJarPath.substring(WEBJARS_LOCATION_LENGTH);
}
}
return null;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -144,9 +144,6 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerMethod);
exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern);
org.springframework.web.filter.reactive.ServerHttpObservationFilter
.findObservationContext(exchange)
.ifPresent(context -> context.setPathPattern(bestPattern.toString()));
ServerRequestObservationContext.findCurrent(exchange.getAttributes())
.ifPresent(context -> context.setPathPattern(bestPattern.toString()));
exchange.getAttributes().put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);

View File

@@ -122,66 +122,6 @@ public interface FragmentsRendering {
return fragmentsPublisher(publisher);
}
/**
* Create a builder with one HTML fragment, also inheriting attributes from
* the shared model for the request.
* @param viewName the name of the view for the fragment
* @return this builder
* @deprecated in favor of {@link #fragment(String)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder with(String viewName) {
return fragment(viewName);
}
/**
* Create a builder with one HTML fragment.
* @param viewName the view name for the fragment
* @param model attributes for the fragment, in addition to attributes from the
* shared model for the request
* @return this builder
* @deprecated in favor of {@link #fragment(String, Map)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder with(String viewName, Map<String, Object> model) {
return fragment(viewName, model);
}
/**
* Create a builder with multiple HTML fragments.
* @param fragments the fragments to add; each fragment also inherits
* attributes from the shared model for the request
* @return the created builder
* @deprecated in favor of {@link #fragments(Collection)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder withCollection(Collection<Fragment> fragments) {
return fragments(fragments);
}
/**
* Create a builder with a {@link Publisher} of fragments.
* @param fragmentsPublisher the fragments to add; each fragment also
* inherits model attributes from the shared model for the request
* @return the created builder
* @deprecated in favor of {@link #fragmentsPublisher(Publisher)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static <P extends Publisher<Fragment>> Builder withPublisher(P fragmentsPublisher) {
return fragmentsPublisher(fragmentsPublisher);
}
/**
* Variant of {@link #fragmentsPublisher(Publisher)} that allows using any
* producer that can be resolved to {@link Publisher} via
* {@link ReactiveAdapterRegistry}.
* @deprecated in favor of {@link #fragmentsProducer(Object)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder withProducer(Object fragmentsProducer) {
return fragmentsProducer(fragmentsProducer);
}
/**
* Defines a builder for {@link FragmentsRendering}.

View File

@@ -54,18 +54,6 @@ class DefaultClientRequestObservationConventionTests {
assertThat(this.observationConvention.supportsContext(new Observation.Context())).isFalse();
}
@Test
@SuppressWarnings("removal")
void shouldAddKeyValuesForNullExchange() {
ClientRequestObservationContext context = new ClientRequestObservationContext();
assertThat(this.observationConvention.getLowCardinalityKeyValues(context)).hasSize(6)
.contains(KeyValue.of("method", "none"), KeyValue.of("uri", "none"), KeyValue.of("status", "CLIENT_ERROR"),
KeyValue.of("client.name", "none"),
KeyValue.of("exception", "none"), KeyValue.of("outcome", "UNKNOWN"));
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).hasSize(1)
.contains(KeyValue.of("http.url", "none"));
}
@Test
void shouldAddKeyValuesForExchangeWithException() {
ClientRequest.Builder request = ClientRequest.create(HttpMethod.GET, URI.create("/test"));

View File

@@ -84,13 +84,11 @@ class DefaultEntityResponseBuilderTests {
}
@Test
@SuppressWarnings("removal")
void status() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).status(HttpStatus.CREATED).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()) &&
response.rawStatusCode() == 201)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()))
.expectComplete()
.verify();
}

View File

@@ -80,12 +80,10 @@ class DefaultServerResponseBuilderTests {
}
@Test
@SuppressWarnings("removal")
void status() {
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()) &&
response.rawStatusCode() == 201)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()))
.expectComplete()
.verify();
}

View File

@@ -223,11 +223,6 @@ class RouterFunctionsTests {
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@SuppressWarnings("removal")
@Override
public int rawStatusCode() {
return 200;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();
@@ -262,11 +257,6 @@ class RouterFunctionsTests {
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@SuppressWarnings("removal")
@Override
public int rawStatusCode() {
return 200;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -115,7 +115,6 @@ class RouterFunctionMappingTests {
}
@Test
@SuppressWarnings("removal")
void mappedRequestShouldHoldAttributes() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route()
@@ -135,8 +134,6 @@ class RouterFunctionMappingTests {
PathPattern matchingPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
assertThat(matchingPattern).isNotNull();
assertThat(matchingPattern.getPatternString()).isEqualTo("/match");
assertThat(org.springframework.web.filter.reactive.ServerHttpObservationFilter.findObservationContext(exchange))
.hasValueSatisfying(context -> assertThat(context.getPathPattern()).isEqualTo(matchingPattern.getPatternString()));
assertThat(ServerRequestObservationContext.findCurrent(exchange.getAttributes()))
.hasValueSatisfying(context -> assertThat(context.getPathPattern()).isEqualTo(matchingPattern.getPatternString()));
@@ -147,11 +144,9 @@ class RouterFunctionMappingTests {
assertThat(handler).isEqualTo(handlerFunction);
}
@SuppressWarnings("removal")
private ServerWebExchange createExchange(String urlTemplate) {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(urlTemplate));
ServerRequestObservationContext observationContext = new ServerRequestObservationContext(exchange.getRequest(), exchange.getResponse(), exchange.getAttributes());
exchange.getAttributes().put(org.springframework.web.filter.reactive.ServerHttpObservationFilter.CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE, observationContext);
exchange.getAttributes().put(ServerRequestObservationContext.CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE, observationContext);
return exchange;
}

View File

@@ -1,155 +0,0 @@
/*
* Copyright 2002-2024 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.web.reactive.resource;
import java.time.Duration;
import java.util.List;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link WebJarsResourceResolver}.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
@SuppressWarnings("removal")
class WebJarsResourceResolverTests {
private static final Duration TIMEOUT = Duration.ofSeconds(1);
private List<Resource> locations = List.of(new ClassPathResource("/META-INF/resources/webjars"));
// for this to work, an actual WebJar must be on the test classpath
private WebJarsResourceResolver resolver = new WebJarsResourceResolver();
private ResourceResolverChain chain = mock();
private ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
@Test
void resolveUrlExisting() {
String file = "/foo/2.3/foo.txt";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.just(file));
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertThat(actual).isEqualTo(file);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
}
@Test
void resolveUrlExistingNotInJarFile() {
String file = "foo/foo.txt";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath("foo/2.3/foo.txt", this.locations);
}
@Test
void resolveUrlWebJarResource() {
String file = "underscorejs/underscore.js";
String expected = "underscorejs/1.8.3/underscore.js";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
given(this.chain.resolveUrlPath(expected, this.locations)).willReturn(Mono.just(expected));
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, times(1)).resolveUrlPath(expected, this.locations);
}
@Test
void resolveUrlWebJarResourceNotFound() {
String file = "something/something.js";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).block(TIMEOUT);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath(null, this.locations);
}
@Test
void resolveResourceExisting() {
Resource expected = mock();
String file = "foo/2.3/foo.txt";
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.just(expected));
Resource actual = this.resolver
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
}
@Test
void resolveResourceNotFound() {
String file = "something/something.js";
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
Resource actual = this.resolver
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
verify(this.chain, never()).resolveResource(this.exchange, null, this.locations);
}
@Test
void resolveResourceWebJar() {
String file = "underscorejs/underscore.js";
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
Resource expected = mock();
String expectedPath = "underscorejs/1.8.3/underscore.js";
given(this.chain.resolveResource(this.exchange, expectedPath, this.locations))
.willReturn(Mono.just(expected));
Resource actual = this.resolver
.resolveResource(this.exchange, file, this.locations, this.chain)
.block(TIMEOUT);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
}
}