From 4920086225000e49bf78ded6b9da6fbb579d1437 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 15 Jan 2025 13:02:20 +0000 Subject: [PATCH] Remove deprecated web APIs See gh-33809 --- .../reactive/JettyClientHttpConnector.java | 18 +- .../reactive/ReactorClientHttpResponse.java | 16 +- .../http/codec/CodecConfigurer.java | 56 +--- .../codec/support/BaseCodecConfigurer.java | 32 +- .../HttpMessageNotReadableException.java | 25 +- .../AbstractListenerWriteProcessor.java | 15 +- .../reactive/AbstractServerHttpRequest.java | 17 +- .../client/DefaultResponseErrorHandler.java | 21 +- .../web/client/RestTemplate.java | 20 +- .../cors/UrlBasedCorsConfigurationSource.java | 22 +- .../web/cors/reactive/CorsUtils.java | 7 +- .../web/util/UrlPathHelper.java | 23 +- .../codec/support/CodecConfigurerTests.java | 16 +- .../web/cors/reactive/CorsUtilsTests.java | 11 +- .../reactive/MockServerHttpRequest.java | 17 - .../function/DefaultServerRequest.java | 8 +- .../function/DefaultServerRequestBuilder.java | 8 +- .../servlet/function/RequestPredicates.java | 22 +- .../web/servlet/function/ServerRequest.java | 20 +- .../handler/AbstractHandlerMethodMapping.java | 23 +- .../servlet/handler/MappedInterceptor.java | 30 +- .../servlet/i18n/CookieLocaleResolver.java | 60 ---- .../servlet/i18n/SessionLocaleResolver.java | 34 -- .../RequestMappingInfoHandlerMapping.java | 11 +- .../view/ResourceBundleViewResolver.java | 296 ------------------ .../web/servlet/view/XmlViewResolver.java | 179 ----------- .../servlet/ComplexWebApplicationContext.java | 25 +- .../servlet/SimpleWebApplicationContext.java | 7 +- .../web/servlet/config/MvcNamespaceTests.java | 1 + .../annotation/InterceptorRegistryTests.java | 10 +- ...RequestMappingInfoHandlerMappingTests.java | 6 +- .../ResponseEntityExceptionHandlerTests.java | 4 +- .../DefaultHandlerExceptionResolverTests.java | 4 +- ...esourceBundleViewResolverNoCacheTests.java | 29 -- .../view/ResourceBundleViewResolverTests.java | 177 ----------- .../web/servlet/view/ViewResolverTests.java | 81 +---- .../web/context/WEB-INF/sessionContext.xml | 16 - .../web/servlet/complexviews.properties | 3 - 38 files changed, 65 insertions(+), 1305 deletions(-) delete mode 100644 spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java delete mode 100644 spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java delete mode 100644 spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverNoCacheTests.java delete mode 100644 spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java delete mode 100644 spring-webmvc/src/test/resources/org/springframework/web/context/WEB-INF/sessionContext.xml delete mode 100644 spring-webmvc/src/test/resources/org/springframework/web/servlet/complexviews.properties diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java index 229e105e7fce..284733051c86 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -17,7 +17,6 @@ package org.springframework.http.client.reactive; import java.net.URI; -import java.util.function.Consumer; import java.util.function.Function; import org.eclipse.jetty.client.HttpClient; @@ -76,21 +75,6 @@ public JettyClientHttpConnector(HttpClient httpClient, @Nullable JettyResourceFa this.httpClient = httpClient; } - /** - * Constructor with an {@link JettyResourceFactory} that will manage shared resources. - * @param resourceFactory the {@link JettyResourceFactory} to use - * @param customizer the lambda used to customize the {@link HttpClient} - * @deprecated as of 5.2, in favor of - * {@link JettyClientHttpConnector#JettyClientHttpConnector(HttpClient, JettyResourceFactory)} - */ - @Deprecated - public JettyClientHttpConnector(JettyResourceFactory resourceFactory, @Nullable Consumer customizer) { - this(new HttpClient(), resourceFactory); - if (customizer != null) { - customizer.accept(this.httpClient); - } - } - /** * Set the buffer factory to use. diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index fdd915be92c8..3d6ae019fd39 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; -import io.netty.buffer.ByteBufAllocator; import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.codec.http.cookie.DefaultCookie; import org.apache.commons.logging.Log; @@ -81,19 +80,6 @@ public ReactorClientHttpResponse(HttpClientResponse response, Connection connect this.bufferFactory = new NettyDataBufferFactory(connection.outbound().alloc()); } - /** - * Constructor with inputs extracted from a {@link Connection}. - * @deprecated as of 5.2.8, in favor of {@link #ReactorClientHttpResponse(HttpClientResponse, Connection)} - */ - @Deprecated - public ReactorClientHttpResponse(HttpClientResponse response, NettyInbound inbound, ByteBufAllocator alloc) { - this.response = response; - MultiValueMap adapter = new Netty4HeadersAdapter(response.responseHeaders()); - this.headers = HttpHeaders.readOnlyHttpHeaders(adapter); - this.inbound = inbound; - this.bufferFactory = new NettyDataBufferFactory(alloc); - } - @Override public String getId() { diff --git a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java index 1b0aa23e7014..95add785f171 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -326,60 +326,6 @@ interface CustomCodecs { * @since 5.1.13 */ void registerWithDefaultConfig(Object codec, Consumer configConsumer); - - /** - * Add a custom {@code Decoder} internally wrapped with - * {@link DecoderHttpMessageReader}). - * @param decoder the decoder to add - * @deprecated as of 5.1.13, use {@link #register(Object)} or - * {@link #registerWithDefaultConfig(Object)} instead. - */ - @Deprecated - void decoder(Decoder decoder); - - /** - * Add a custom {@code Encoder}, internally wrapped with - * {@link EncoderHttpMessageWriter}. - * @param encoder the encoder to add - * @deprecated as of 5.1.13, use {@link #register(Object)} or - * {@link #registerWithDefaultConfig(Object)} instead. - */ - @Deprecated - void encoder(Encoder encoder); - - /** - * Add a custom {@link HttpMessageReader}. For readers of type - * {@link DecoderHttpMessageReader} consider using the shortcut - * {@link #decoder(Decoder)} instead. - * @param reader the reader to add - * @deprecated as of 5.1.13, use {@link #register(Object)} or - * {@link #registerWithDefaultConfig(Object)} instead. - */ - @Deprecated - void reader(HttpMessageReader reader); - - /** - * Add a custom {@link HttpMessageWriter}. For writers of type - * {@link EncoderHttpMessageWriter} consider using the shortcut - * {@link #encoder(Encoder)} instead. - * @param writer the writer to add - * @deprecated as of 5.1.13, use {@link #register(Object)} or - * {@link #registerWithDefaultConfig(Object)} instead. - */ - @Deprecated - void writer(HttpMessageWriter writer); - - /** - * Register a callback for the {@link DefaultCodecConfig configuration} - * applied to default codecs. This allows custom codecs to follow general - * guidelines applied to default ones, such as logging details and limiting - * the amount of buffered data. - * @param codecsConfigConsumer the default codecs configuration callback - * @deprecated as of 5.1.13, use {@link #registerWithDefaultConfig(Object)} - * or {@link #registerWithDefaultConfig(Object, Consumer)} instead. - */ - @Deprecated - void withDefaultCodecConfig(Consumer codecsConfigConsumer); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java index 3b7b4ddb2e23..f722cb4011bc 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -166,36 +166,6 @@ public void registerWithDefaultConfig(Object codec, Consumer this.defaultConfigConsumers.add(configConsumer); } - @SuppressWarnings("deprecation") - @Override - public void decoder(Decoder decoder) { - addCodec(decoder, false); - } - - @SuppressWarnings("deprecation") - @Override - public void encoder(Encoder encoder) { - addCodec(encoder, false); - } - - @SuppressWarnings("deprecation") - @Override - public void reader(HttpMessageReader reader) { - addCodec(reader, false); - } - - @SuppressWarnings("deprecation") - @Override - public void writer(HttpMessageWriter writer) { - addCodec(writer, false); - } - - @SuppressWarnings("deprecation") - @Override - public void withDefaultCodecConfig(Consumer codecsConfigConsumer) { - this.defaultConfigConsumers.add(codecsConfigConsumer); - } - private void addCodec(Object codec, boolean applyDefaultConfig) { if (codec instanceof Decoder decoder) { diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java index 693e097f730b..72b106e713d0 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2025 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. @@ -35,29 +35,6 @@ public class HttpMessageNotReadableException extends HttpMessageConversionExcept private final @Nullable HttpInputMessage httpInputMessage; - /** - * Create a new HttpMessageNotReadableException. - * @param msg the detail message - * @deprecated as of 5.1, in favor of {@link #HttpMessageNotReadableException(String, HttpInputMessage)} - */ - @Deprecated - public HttpMessageNotReadableException(String msg) { - super(msg); - this.httpInputMessage = null; - } - - /** - * Create a new HttpMessageNotReadableException. - * @param msg the detail message - * @param cause the root cause (if any) - * @deprecated as of 5.1, in favor of {@link #HttpMessageNotReadableException(String, Throwable, HttpInputMessage)} - */ - @Deprecated - public HttpMessageNotReadableException(String msg, @Nullable Throwable cause) { - super(msg, cause); - this.httpInputMessage = null; - } - /** * Create a new HttpMessageNotReadableException. * @param msg the detail message diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java index 5a3e878be97a..19f82840f30f 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -248,18 +248,6 @@ protected void dataReceived(T data) { */ protected abstract boolean write(T data) throws IOException; - /** - * Invoked after the current data has been written and before requesting - * the next item from the upstream, write Publisher. - *

The default implementation is a no-op. - * @deprecated originally introduced for Undertow to stop write notifications - * when no data is available, but deprecated as of 5.0.6 since constant - * switching on every requested item causes a significant slowdown. - */ - @Deprecated - protected void writingPaused() { - } - /** * Invoked after onComplete or onError notification. *

The default implementation is a no-op. @@ -409,7 +397,6 @@ else if (processor.changeState(this, WRITING)) { processor.changeStateToReceived(REQUESTED); } else { - processor.writingPaused(); Assert.state(processor.subscription != null, "No subscription"); processor.subscription.request(1); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java index 4cb0d82917cd..7835ee84720b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -72,21 +72,6 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { private @Nullable Supplier> attributesSupplier; - /** - * Constructor with the method, URI and headers for the request. - * @param method the HTTP method for the request - * @param uri the URI for the request - * @param contextPath the context path for the request - * @param headers the headers for the request (as {@link MultiValueMap}) - * @since 6.0.8 - * @deprecated Use {@link #AbstractServerHttpRequest(HttpMethod, URI, String, HttpHeaders)} - */ - @Deprecated - public AbstractServerHttpRequest(HttpMethod method, URI uri, @Nullable String contextPath, - MultiValueMap headers) { - this(method, uri, contextPath, new HttpHeaders(headers)); - } - /** * Constructor with the method, URI and headers for the request. * @param method the HTTP method for the request diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index ed725eb9e3a5..d81bcbb364df 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -97,25 +97,6 @@ protected boolean hasError(HttpStatusCode statusCode) { return statusCode.isError(); } - /** - * Template method called from {@link #hasError(ClientHttpResponse)}. - *

The default implementation checks if the given status code is - * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or - * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR SERVER_ERROR}. - * Can be overridden in subclasses. - * @param statusCode the HTTP status code as raw value - * @return {@code true} if the response indicates an error; {@code false} otherwise - * @since 4.3.21 - * @see org.springframework.http.HttpStatus.Series#CLIENT_ERROR - * @see org.springframework.http.HttpStatus.Series#SERVER_ERROR - * @deprecated in favor of {@link #hasError(HttpStatusCode)} - */ - @Deprecated - protected boolean hasError(int statusCode) { - HttpStatus.Series series = HttpStatus.Series.resolve(statusCode); - return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR); - } - /** * Handle the error in the given response with the given resolved status code * and extra information providing access to the request URL and HTTP method. diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 0bd298014abb..4c32c8bdaf72 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -823,24 +823,6 @@ else if (ext.getVarsMap() != null) { return doExecute(url, null, method, requestCallback, responseExtractor); } - /** - * Execute the given method on the provided URI. - *

The {@link ClientHttpRequest} is processed using the {@link RequestCallback}; - * the response with the {@link ResponseExtractor}. - * @param url the fully-expanded URL to connect to - * @param method the HTTP method to execute (GET, POST, etc.) - * @param requestCallback object that prepares the request (can be {@code null}) - * @param responseExtractor object that extracts the return value from the response (can be {@code null}) - * @return an arbitrary object, as returned by the {@link ResponseExtractor} - * @deprecated in favor of {@link #doExecute(URI, String, HttpMethod, RequestCallback, ResponseExtractor)} - */ - @Deprecated - protected @Nullable T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor) throws RestClientException { - - return doExecute(url, null, method, requestCallback, responseExtractor); - } - /** * Execute the given method on the provided URI. *

The {@link ClientHttpRequest} is processed using the {@link RequestCallback}; diff --git a/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java b/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java index 34a98f0dc65d..51081a8c07e7 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java +++ b/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -62,8 +62,6 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource private PathMatcher pathMatcher = defaultPathMatcher; - private @Nullable String lookupPathAttributeName; - private boolean allowInitLookupPath = true; private final Map corsConfigurations = new LinkedHashMap<>(); @@ -180,19 +178,6 @@ public void setAllowInitLookupPath(boolean allowInitLookupPath) { this.allowInitLookupPath = allowInitLookupPath; } - /** - * Configure the name of the attribute that holds the lookupPath extracted - * via {@link UrlPathHelper#getLookupPathForRequest(HttpServletRequest)}. - *

By default this is {@link UrlPathHelper#PATH_ATTRIBUTE}. - * @param name the request attribute to check - * @since 5.2 - * @deprecated as of 5.3 in favor of {@link UrlPathHelper#PATH_ATTRIBUTE}. - */ - @Deprecated - public void setLookupPathAttributeName(String name) { - this.lookupPathAttributeName = name; - } - /** * Configure a {@code PathMatcher} to use for pattern matching. *

This is an advanced property that should be used only when a @@ -262,12 +247,9 @@ public Map getCorsConfigurations() { return null; } - @SuppressWarnings("deprecation") private Object resolvePath(HttpServletRequest request) { if (this.allowInitLookupPath && !ServletRequestPathUtils.hasCachedPath(request)) { - return (this.lookupPathAttributeName != null ? - this.urlPathHelper.getLookupPathForRequest(request, this.lookupPathAttributeName) : - this.urlPathHelper.getLookupPathForRequest(request)); + return this.urlPathHelper.getLookupPathForRequest(request); } Object lookupPath = ServletRequestPathUtils.getCachedPath(request); if (this.pathMatcher != defaultPathMatcher) { diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java index 49613155664f..38dde26370cb 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -40,7 +40,6 @@ public abstract class CorsUtils { * Returns {@code true} if the request is a valid CORS one by checking {@code Origin} * header presence and ensuring that origins are different via {@link #isSameOrigin}. */ - @SuppressWarnings("deprecation") public static boolean isCorsRequest(ServerHttpRequest request) { return request.getHeaders().containsHeader(HttpHeaders.ORIGIN) && !isSameOrigin(request); } @@ -66,10 +65,8 @@ public static boolean isPreFlightRequest(ServerHttpRequest request) { * to extract and use, or to discard such headers. * @return {@code true} if the request is a same-origin one, {@code false} in case * of a cross-origin request - * @deprecated as of 5.2, same-origin checks are performed directly by {@link #isCorsRequest} */ - @Deprecated - public static boolean isSameOrigin(ServerHttpRequest request) { + private static boolean isSameOrigin(ServerHttpRequest request) { String origin = request.getHeaders().getOrigin(); if (origin == null) { return true; diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index a7035825155e..20c460673453 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -209,27 +209,6 @@ public static String getResolvedLookupPath(ServletRequest request) { return lookupPath; } - /** - * Variant of {@link #getLookupPathForRequest(HttpServletRequest)} that - * automates checking for a previously computed lookupPath saved as a - * request attribute. The attribute is only used for lookup purposes. - * @param request current HTTP request - * @param name the request attribute that holds the lookupPath - * @return the lookup path - * @since 5.2 - * @deprecated as of 5.3 in favor of using - * {@link #resolveAndCacheLookupPath(HttpServletRequest)} and - * {@link #getResolvedLookupPath(ServletRequest)}. - */ - @Deprecated - public String getLookupPathForRequest(HttpServletRequest request, @Nullable String name) { - String result = null; - if (name != null) { - result = (String) request.getAttribute(name); - } - return (result != null ? result : getLookupPathForRequest(request)); - } - /** * Return the mapping lookup path for the given request, within the current * servlet mapping if applicable, else within the web application. diff --git a/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java b/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java index 1b3b9ee5368a..9d21ac2732d8 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -17,7 +17,6 @@ package org.springframework.http.codec.support; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -413,19 +412,6 @@ void cloneDefaultCodecs() { assertThat(encoders).doesNotContain(jacksonEncoder, jaxb2Encoder, protoEncoder); } - @SuppressWarnings("deprecation") - @Test - void withDefaultCodecConfig() { - AtomicBoolean callbackCalled = new AtomicBoolean(); - this.configurer.defaultCodecs().enableLoggingRequestDetails(true); - this.configurer.customCodecs().withDefaultCodecConfig(config -> { - assertThat(config.isEnableLoggingRequestDetails()).isTrue(); - callbackCalled.compareAndSet(false, true); - }); - this.configurer.getReaders(); - assertThat(callbackCalled).isTrue(); - } - private Decoder getNextDecoder(List> readers) { HttpMessageReader reader = readers.get(this.index.getAndIncrement()); assertThat(reader.getClass()).isEqualTo(DecoderHttpMessageReader.class); diff --git a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java index 3b816e87c811..b26498eab99d 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -89,16 +89,14 @@ public void isSameOriginWithForwardedHeader() { } @Test // SPR-16362 - @SuppressWarnings("deprecation") public void isSameOriginWithDifferentSchemes() { MockServerHttpRequest request = MockServerHttpRequest .get("http://mydomain1.example") .header(HttpHeaders.ORIGIN, "https://mydomain1.example") .build(); - assertThat(CorsUtils.isSameOrigin(request)).isFalse(); + assertThat(CorsUtils.isCorsRequest(request)).isTrue(); } - @SuppressWarnings("deprecation") private void testWithXForwardedHeaders(String serverName, int port, String forwardedProto, String forwardedHost, int forwardedPort, String originHeader) { @@ -119,10 +117,9 @@ private void testWithXForwardedHeaders(String serverName, int port, } ServerHttpRequest request = adaptFromForwardedHeaders(builder); - assertThat(CorsUtils.isSameOrigin(request)).isTrue(); + assertThat(CorsUtils.isCorsRequest(request)).isFalse(); } - @SuppressWarnings("deprecation") private void testWithForwardedHeader(String serverName, int port, String forwardedHeader, String originHeader) { @@ -136,7 +133,7 @@ private void testWithForwardedHeader(String serverName, int port, .header(HttpHeaders.ORIGIN, originHeader); ServerHttpRequest request = adaptFromForwardedHeaders(builder); - assertThat(CorsUtils.isSameOrigin(request)).isTrue(); + assertThat(CorsUtils.isCorsRequest(request)).isFalse(); } // SPR-16668 diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java index 57328d531783..d69532c165bd 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java @@ -43,7 +43,6 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MimeType; import org.springframework.util.MultiValueMap; -import org.springframework.util.StringUtils; import org.springframework.web.util.UriComponentsBuilder; /** @@ -210,22 +209,6 @@ public static BodyBuilder method(HttpMethod method, String uri, @Nullable Object return method(method, toUri(uri, vars)); } - /** - * Create a builder with a raw HTTP method value that is outside the - * range of {@link HttpMethod} enum values. - * @param httpMethod the HTTP methodValue value - * @param uri the URI template for target the URL - * @param vars variables to expand into the template - * @return the created builder - * @since 5.2.7 - * @deprecated in favor of {@link #method(HttpMethod, String, Object...)} - */ - @Deprecated - public static BodyBuilder method(String httpMethod, String uri, @Nullable Object... vars) { - Assert.isTrue(StringUtils.hasText(httpMethod), "HTTP method is required."); - return new DefaultBodyBuilder(HttpMethod.valueOf(httpMethod), toUri(uri, vars)); - } - private static URI toUri(String uri, @Nullable Object[] vars) { return UriComponentsBuilder.fromUriString(uri).buildAndExpand(vars).encode().toUri(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java index 45881cd4780d..96017c00bc0d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -124,12 +124,6 @@ public HttpMethod method() { return HttpMethod.valueOf(servletRequest().getMethod()); } - @Override - @Deprecated - public String methodName() { - return servletRequest().getMethod(); - } - @Override public URI uri() { return this.serverHttpRequest.getURI(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java index 920ab58fa648..d06549484d5f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -251,12 +251,6 @@ public HttpMethod method() { return this.method; } - @Override - @Deprecated - public String methodName() { - return this.method.name(); - } - @Override public MultiValueMap multipartData() throws IOException, ServletException { return servletRequest().getParts().stream() diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java index 5e7b0348760f..6333b87c7870 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -1048,7 +1048,7 @@ public void changeParser(PathPatternParser parser) { @Override public String toString() { - return "!" + this.delegate.toString(); + return "!" + this.delegate; } } @@ -1142,12 +1142,6 @@ public HttpMethod method() { return this.delegate.method(); } - @Override - @Deprecated - public String methodName() { - return this.delegate.methodName(); - } - @Override public URI uri() { return this.delegate.uri(); @@ -1163,12 +1157,6 @@ public String path() { return this.delegate.path(); } - @Override - @Deprecated - public PathContainer pathContainer() { - return this.delegate.pathContainer(); - } - @Override public RequestPath requestPath() { return this.delegate.requestPath(); @@ -1383,11 +1371,5 @@ public RequestPath requestPath() { public String path() { return this.requestPath.pathWithinApplication().value(); } - - @Override - @Deprecated - public PathContainer pathContainer() { - return this.requestPath; - } } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java index 1051e3bca73f..99671b637a31 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -43,7 +43,6 @@ import org.springframework.http.HttpRange; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -70,14 +69,6 @@ public interface ServerRequest { */ HttpMethod method(); - /** - * Get the name of the HTTP method. - * @return the HTTP method as a String - * @deprecated in favor of {@link #method()} - */ - @Deprecated - String methodName(); - /** * Get the request URI. */ @@ -97,15 +88,6 @@ default String path() { return requestPath().pathWithinApplication().value(); } - /** - * Get the request path as a {@code PathContainer}. - * @deprecated as of 5.3, in favor on {@link #requestPath()} - */ - @Deprecated - default PathContainer pathContainer() { - return requestPath(); - } - /** * Get the request path as a {@code PathContainer}. * @since 5.3 diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index 6a79e4450bde..c96f0b989f77 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -511,30 +510,12 @@ protected boolean hasCorsConfigurationSource(Object handler) { */ protected abstract @Nullable T getMappingForMethod(Method method, Class handlerType); - /** - * Extract and return the URL paths contained in the supplied mapping. - * @deprecated as of 5.3 in favor of providing non-pattern mappings via - * {@link #getDirectPaths(Object)} instead - */ - @Deprecated - protected Set getMappingPathPatterns(T mapping) { - return Collections.emptySet(); - } - /** * Return the request mapping paths that are not patterns. * @since 5.3 */ - @SuppressWarnings("removal") protected Set getDirectPaths(T mapping) { - Set urls = Collections.emptySet(); - for (String path : getMappingPathPatterns(mapping)) { - if (!getPathMatcher().isPattern(path)) { - urls = (urls.isEmpty() ? new HashSet<>(1) : urls); - urls.add(path); - } - } - return urls; + return Collections.emptySet(); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java index 1fd2d2b0d7ef..3c3dcc8c6336 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -224,34 +224,6 @@ public boolean matches(HttpServletRequest request) { return false; } - /** - * Determine if there is a match for the given lookup path. - * @param lookupPath the current request path - * @param pathMatcher a path matcher for path pattern matching - * @return {@code true} if the interceptor applies to the given request path - * @deprecated as of 5.3 in favor of {@link #matches(HttpServletRequest)} - */ - @Deprecated(since = "5.3") - public boolean matches(String lookupPath, PathMatcher pathMatcher) { - pathMatcher = (this.pathMatcher != defaultPathMatcher ? this.pathMatcher : pathMatcher); - if (!ObjectUtils.isEmpty(this.excludePatterns)) { - for (PatternAdapter adapter : this.excludePatterns) { - if (pathMatcher.match(adapter.getPatternString(), lookupPath)) { - return false; - } - } - } - if (ObjectUtils.isEmpty(this.includePatterns)) { - return true; - } - for (PatternAdapter adapter : this.includePatterns) { - if (pathMatcher.match(adapter.getPatternString(), lookupPath)) { - return true; - } - } - return false; - } - // HandlerInterceptor delegation diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java index 68486969f6da..38f72564788e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java @@ -122,25 +122,6 @@ public CookieLocaleResolver() { } - /** - * Set the name of cookie created by this resolver. - * @param cookieName the cookie name - * @deprecated as of 6.0 in favor of {@link #CookieLocaleResolver(String)} - */ - @Deprecated - public void setCookieName(String cookieName) { - Assert.notNull(cookieName, "cookieName must not be null"); - this.cookie = ResponseCookie.from(cookieName) - .maxAge(this.cookie.getMaxAge()) - .domain(this.cookie.getDomain()) - .path(this.cookie.getPath()) - .secure(this.cookie.isSecure()) - .httpOnly(this.cookie.isHttpOnly()) - .sameSite(this.cookie.getSameSite()) - .build(); - - } - /** * Set the cookie "Max-Age" attribute. *

By default, this is set to -1 in which case the cookie persists until @@ -153,15 +134,6 @@ public void setCookieMaxAge(Duration cookieMaxAge) { this.cookie = this.cookie.mutate().maxAge(cookieMaxAge).build(); } - /** - * Variant of {@link #setCookieMaxAge(Duration)} with a value in seconds. - * @deprecated as of 6.0 in favor of {@link #setCookieMaxAge(Duration)} - */ - @Deprecated - public void setCookieMaxAge(@Nullable Integer cookieMaxAge) { - setCookieMaxAge(Duration.ofSeconds((cookieMaxAge != null) ? cookieMaxAge : -1)); - } - /** * Set the cookie "Path" attribute. *

By default, this is set to {@code "/"}. @@ -411,36 +383,4 @@ protected String toLocaleValue(Locale locale) { return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString()); } - /** - * Determine the default locale for the given request, called if no locale - * cookie has been found. - *

The default implementation returns the configured default locale, if any, - * and otherwise falls back to the request's {@code Accept-Language} header - * locale or the default locale for the server. - * @param request the request to resolve the locale for - * @return the default locale (never {@code null}) - * @see #setDefaultLocale - * @see jakarta.servlet.http.HttpServletRequest#getLocale() - * @deprecated as of 6.0, in favor of {@link #setDefaultLocaleFunction(Function)} - */ - @Deprecated(since = "6.0") - protected Locale determineDefaultLocale(HttpServletRequest request) { - return this.defaultLocaleFunction.apply(request); - } - - /** - * Determine the default time zone for the given request, called if no locale - * cookie has been found. - *

The default implementation returns the configured default time zone, - * if any, or {@code null} otherwise. - * @param request the request to resolve the time zone for - * @return the default time zone (or {@code null} if none defined) - * @see #setDefaultTimeZone - * @deprecated as of 6.0, in favor of {@link #setDefaultTimeZoneFunction(Function)} - */ - @Deprecated(since = "6.0") - protected @Nullable TimeZone determineDefaultTimeZone(HttpServletRequest request) { - return this.defaultTimeZoneFunction.apply(request); - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java index 2a3a474b862a..3947d0da9322 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/SessionLocaleResolver.java @@ -193,38 +193,4 @@ public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletRe WebUtils.setSessionAttribute(request, this.timeZoneAttributeName, timeZone); } - - /** - * Determine the default locale for the given request, called if no - * {@link Locale} session attribute has been found. - *

The default implementation returns the configured - * {@linkplain #setDefaultLocale(Locale) default locale}, if any, and otherwise - * falls back to the request's {@code Accept-Language} header locale or the - * default locale for the server. - * @param request the request to resolve the locale for - * @return the default locale (never {@code null}) - * @see #setDefaultLocale - * @see jakarta.servlet.http.HttpServletRequest#getLocale() - * @deprecated as of 6.0, in favor of {@link #setDefaultLocaleFunction(Function)} - */ - @Deprecated(since = "6.0") - protected Locale determineDefaultLocale(HttpServletRequest request) { - return this.defaultLocaleFunction.apply(request); - } - - /** - * Determine the default time zone for the given request, called if no - * {@link TimeZone} session attribute has been found. - *

The default implementation returns the configured default time zone, - * if any, or {@code null} otherwise. - * @param request the request to resolve the time zone for - * @return the default time zone (or {@code null} if none defined) - * @see #setDefaultTimeZone - * @deprecated as of 6.0, in favor of {@link #setDefaultTimeZoneFunction(Function)} - */ - @Deprecated(since = "6.0") - protected @Nullable TimeZone determineDefaultTimeZone(HttpServletRequest request) { - return this.defaultTimeZoneFunction.apply(request); - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index 5923e9ead263..f525ea014dda 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -85,15 +85,6 @@ protected RequestMappingInfoHandlerMapping() { } - /** - * Get the URL path patterns associated with the supplied {@link RequestMappingInfo}. - */ - @Override - @SuppressWarnings("deprecation") - protected Set getMappingPathPatterns(RequestMappingInfo info) { - return info.getPatternValues(); - } - @Override protected Set getDirectPaths(RequestMappingInfo info) { return info.getDirectPaths(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java deleted file mode 100644 index 7d5d65e8070b..000000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2002-2020 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.servlet.view; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.jspecify.annotations.Nullable; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.Ordered; -import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.servlet.View; - -/** - * A {@link org.springframework.web.servlet.ViewResolver} implementation that uses - * bean definitions in a {@link ResourceBundle}, specified by the bundle basename. - * - *

The bundle is typically defined in a properties file, located in the classpath. - * The default bundle basename is "views". - * - *

This {@code ViewResolver} supports localized view definitions, using the - * default support of {@link java.util.PropertyResourceBundle}. For example, the - * basename "views" will be resolved as class path resources "views_de_AT.properties", - * "views_de.properties", "views.properties" - for a given Locale "de_AT". - * - *

Note: This {@code ViewResolver} implements the {@link Ordered} interface - * in order to allow for flexible participation in {@code ViewResolver} chaining. - * For example, some special views could be defined via this {@code ViewResolver} - * (giving it 0 as "order" value), while all remaining views could be resolved by - * a {@link UrlBasedViewResolver}. - * - * @author Rod Johnson - * @author Juergen Hoeller - * @see java.util.ResourceBundle#getBundle - * @see java.util.PropertyResourceBundle - * @see UrlBasedViewResolver - * @see BeanNameViewResolver - * @deprecated as of 5.3, in favor of Spring's common view resolver variants - * and/or custom resolver implementations - */ -@Deprecated -public class ResourceBundleViewResolver extends AbstractCachingViewResolver - implements Ordered, InitializingBean, DisposableBean { - - /** The default basename if no other basename is supplied. */ - public static final String DEFAULT_BASENAME = "views"; - - - private String[] basenames = new String[] {DEFAULT_BASENAME}; - - private ClassLoader bundleClassLoader = Thread.currentThread().getContextClassLoader(); - - private @Nullable String defaultParentView; - - private Locale @Nullable [] localesToInitialize; - - private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - - /* Locale -> BeanFactory */ - private final Map localeCache = new HashMap<>(); - - /* List of ResourceBundle -> BeanFactory */ - private final Map, ConfigurableApplicationContext> bundleCache = new HashMap<>(); - - - /** - * Set a single basename, following {@link java.util.ResourceBundle} conventions. - * The default is "views". - *

{@code ResourceBundle} supports different locale suffixes. For example, - * a base name of "views" might map to {@code ResourceBundle} files - * "views", "views_en_au" and "views_de". - *

Note that ResourceBundle names are effectively classpath locations: As a - * consequence, the JDK's standard ResourceBundle treats dots as package separators. - * This means that "test.theme" is effectively equivalent to "test/theme", - * just like it is for programmatic {@code java.util.ResourceBundle} usage. - * @see #setBasenames - * @see ResourceBundle#getBundle(String) - * @see ResourceBundle#getBundle(String, Locale) - */ - public void setBasename(String basename) { - setBasenames(basename); - } - - /** - * Set an array of basenames, each following {@link java.util.ResourceBundle} - * conventions. The default is a single basename "views". - *

{@code ResourceBundle} supports different locale suffixes. For example, - * a base name of "views" might map to {@code ResourceBundle} files - * "views", "views_en_au" and "views_de". - *

The associated resource bundles will be checked sequentially when resolving - * a message code. Note that message definitions in a previous resource - * bundle will override ones in a later bundle, due to the sequential lookup. - *

Note that ResourceBundle names are effectively classpath locations: As a - * consequence, the JDK's standard ResourceBundle treats dots as package separators. - * This means that "test.theme" is effectively equivalent to "test/theme", - * just like it is for programmatic {@code java.util.ResourceBundle} usage. - * @see #setBasename - * @see ResourceBundle#getBundle(String) - * @see ResourceBundle#getBundle(String, Locale) - */ - public void setBasenames(String... basenames) { - this.basenames = basenames; - } - - /** - * Set the {@link ClassLoader} to load resource bundles with. - * Default is the thread context {@code ClassLoader}. - */ - public void setBundleClassLoader(ClassLoader classLoader) { - this.bundleClassLoader = classLoader; - } - - /** - * Return the {@link ClassLoader} to load resource bundles with. - *

Default is the specified bundle {@code ClassLoader}, - * usually the thread context {@code ClassLoader}. - */ - protected ClassLoader getBundleClassLoader() { - return this.bundleClassLoader; - } - - /** - * Set the default parent for views defined in the {@code ResourceBundle}. - *

This avoids repeated "yyy1.(parent)=xxx", "yyy2.(parent)=xxx" definitions - * in the bundle, especially if all defined views share the same parent. - *

The parent will typically define the view class and common attributes. - * Concrete views might simply consist of a URL definition then: - * a la "yyy1.url=/my.jsp", "yyy2.url=/your.jsp". - *

View definitions that define their own parent or carry their own - * class can still override this. Strictly speaking, the rule that a - * default parent setting does not apply to a bean definition that - * carries a class is there for backwards compatibility reasons. - * It still matches the typical use case. - */ - public void setDefaultParentView(String defaultParentView) { - this.defaultParentView = defaultParentView; - } - - /** - * Specify Locales to initialize eagerly, rather than lazily when actually accessed. - *

Allows for pre-initialization of common Locales, eagerly checking - * the view configuration for those Locales. - */ - public void setLocalesToInitialize(Locale... localesToInitialize) { - this.localesToInitialize = localesToInitialize; - } - - /** - * Specify the order value for this ViewResolver bean. - *

The default value is {@code Ordered.LOWEST_PRECEDENCE}, meaning non-ordered. - * @see org.springframework.core.Ordered#getOrder() - */ - public void setOrder(int order) { - this.order = order; - } - - @Override - public int getOrder() { - return this.order; - } - - /** - * Eagerly initialize Locales if necessary. - * @see #setLocalesToInitialize - */ - @Override - public void afterPropertiesSet() throws BeansException { - if (this.localesToInitialize != null) { - for (Locale locale : this.localesToInitialize) { - initFactory(locale); - } - } - } - - - @Override - protected @Nullable View loadView(String viewName, Locale locale) throws Exception { - BeanFactory factory = initFactory(locale); - try { - return factory.getBean(viewName, View.class); - } - catch (NoSuchBeanDefinitionException ex) { - // Allow for ViewResolver chaining... - return null; - } - } - - /** - * Initialize the View {@link BeanFactory} from the {@code ResourceBundle}, - * for the given {@link Locale locale}. - *

Synchronized because of access by parallel threads. - * @param locale the target {@code Locale} - * @return the View factory for the given Locale - * @throws BeansException in case of initialization errors - */ - protected synchronized BeanFactory initFactory(Locale locale) throws BeansException { - // Try to find cached factory for Locale: - // Have we already encountered that Locale before? - if (isCache()) { - BeanFactory cachedFactory = this.localeCache.get(locale); - if (cachedFactory != null) { - return cachedFactory; - } - } - - // Build list of ResourceBundle references for Locale. - List bundles = new ArrayList<>(this.basenames.length); - for (String basename : this.basenames) { - bundles.add(getBundle(basename, locale)); - } - - // Try to find cached factory for ResourceBundle list: - // even if Locale was different, same bundles might have been found. - if (isCache()) { - BeanFactory cachedFactory = this.bundleCache.get(bundles); - if (cachedFactory != null) { - this.localeCache.put(locale, cachedFactory); - return cachedFactory; - } - } - - // Create child ApplicationContext for views. - GenericWebApplicationContext factory = new GenericWebApplicationContext(); - factory.setParent(getApplicationContext()); - factory.setServletContext(getServletContext()); - - // Load bean definitions from resource bundle. - org.springframework.beans.factory.support.PropertiesBeanDefinitionReader reader = - new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(factory); - reader.setDefaultParentBean(this.defaultParentView); - for (ResourceBundle bundle : bundles) { - reader.registerBeanDefinitions(bundle); - } - - factory.refresh(); - - // Cache factory for both Locale and ResourceBundle list. - if (isCache()) { - this.localeCache.put(locale, factory); - this.bundleCache.put(bundles, factory); - } - - return factory; - } - - /** - * Obtain the resource bundle for the given basename and {@link Locale}. - * @param basename the basename to look for - * @param locale the {@code Locale} to look for - * @return the corresponding {@code ResourceBundle} - * @throws MissingResourceException if no matching bundle could be found - * @see ResourceBundle#getBundle(String, Locale, ClassLoader) - */ - protected ResourceBundle getBundle(String basename, Locale locale) throws MissingResourceException { - return ResourceBundle.getBundle(basename, locale, getBundleClassLoader()); - } - - - /** - * Close the bundle View factories on context shutdown. - */ - @Override - public void destroy() throws BeansException { - for (ConfigurableApplicationContext factory : this.bundleCache.values()) { - factory.close(); - } - this.localeCache.clear(); - this.bundleCache.clear(); - } - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java deleted file mode 100644 index cc086e68a2e3..000000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/XmlViewResolver.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2002-2020 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.servlet.view; - -import java.util.Locale; - -import org.jspecify.annotations.Nullable; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.xml.ResourceEntityResolver; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.Ordered; -import org.springframework.core.io.Resource; -import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.servlet.View; - -/** - * A {@link org.springframework.web.servlet.ViewResolver} implementation that uses - * bean definitions in a dedicated XML file for view definitions, specified by - * resource location. The file will typically be located in the WEB-INF directory; - * the default is "/WEB-INF/views.xml". - * - *

This {@code ViewResolver} does not support internationalization at the level - * of its definition resources. Consider {@link ResourceBundleViewResolver} if you - * need to apply different view resources per locale. - * - *

Note: This {@code ViewResolver} implements the {@link Ordered} interface - * in order to allow for flexible participation in {@code ViewResolver} chaining. - * For example, some special views could be defined via this {@code ViewResolver} - * (giving it 0 as "order" value), while all remaining views could be resolved by - * a {@link UrlBasedViewResolver}. - * - * @author Juergen Hoeller - * @since 18.06.2003 - * @see org.springframework.context.ApplicationContext#getResource - * @see UrlBasedViewResolver - * @see BeanNameViewResolver - * @deprecated as of 5.3, in favor of Spring's common view resolver variants - * and/or custom resolver implementations - */ -@Deprecated -public class XmlViewResolver extends AbstractCachingViewResolver - implements Ordered, InitializingBean, DisposableBean { - - /** Default if no other location is supplied. */ - public static final String DEFAULT_LOCATION = "/WEB-INF/views.xml"; - - - private @Nullable Resource location; - - private @Nullable ConfigurableApplicationContext cachedFactory; - - private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - - - /** - * Set the location of the XML file that defines the view beans. - *

The default is "/WEB-INF/views.xml". - * @param location the location of the XML file. - */ - public void setLocation(Resource location) { - this.location = location; - } - - /** - * Specify the order value for this ViewResolver bean. - *

The default value is {@code Ordered.LOWEST_PRECEDENCE}, meaning non-ordered. - * @see org.springframework.core.Ordered#getOrder() - */ - public void setOrder(int order) { - this.order = order; - } - - @Override - public int getOrder() { - return this.order; - } - - /** - * Pre-initialize the factory from the XML file. - * Only effective if caching is enabled. - */ - @Override - public void afterPropertiesSet() throws BeansException { - if (isCache()) { - initFactory(); - } - } - - - /** - * This implementation returns just the view name, - * as XmlViewResolver doesn't support localized resolution. - */ - @Override - protected Object getCacheKey(String viewName, Locale locale) { - return viewName; - } - - @Override - protected @Nullable View loadView(String viewName, Locale locale) throws BeansException { - BeanFactory factory = initFactory(); - try { - return factory.getBean(viewName, View.class); - } - catch (NoSuchBeanDefinitionException ex) { - // Allow for ViewResolver chaining... - return null; - } - } - - /** - * Initialize the view bean factory from the XML file. - * Synchronized because of access by parallel threads. - * @throws BeansException in case of initialization errors - */ - protected synchronized BeanFactory initFactory() throws BeansException { - if (this.cachedFactory != null) { - return this.cachedFactory; - } - - ApplicationContext applicationContext = obtainApplicationContext(); - - Resource actualLocation = this.location; - if (actualLocation == null) { - actualLocation = applicationContext.getResource(DEFAULT_LOCATION); - } - - // Create child ApplicationContext for views. - GenericWebApplicationContext factory = new GenericWebApplicationContext(); - factory.setParent(applicationContext); - factory.setServletContext(getServletContext()); - - // Load XML resource with context-aware entity resolver. - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); - reader.setEnvironment(applicationContext.getEnvironment()); - reader.setEntityResolver(new ResourceEntityResolver(applicationContext)); - reader.loadBeanDefinitions(actualLocation); - - factory.refresh(); - - if (isCache()) { - this.cachedFactory = factory; - } - return factory; - } - - - /** - * Close the view bean factory on context shutdown. - */ - @Override - public void destroy() throws BeansException { - if (this.cachedFactory != null) { - this.cachedFactory.close(); - } - } - -} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java index 25c56911419b..c209a66b82b2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java @@ -64,6 +64,7 @@ import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter; import org.springframework.web.servlet.support.RequestContext; import org.springframework.web.servlet.support.RequestContextUtils; +import org.springframework.web.servlet.view.InternalResourceView; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.util.WebUtils; @@ -118,10 +119,7 @@ public void refresh() throws BeansException { registerSingleton("noviewController", NoViewController.class); pvs = new MutablePropertyValues(); - pvs.add("order", 0); - pvs.add("basename", "org.springframework.web.servlet.complexviews"); - registerSingleton("viewResolver", - org.springframework.web.servlet.view.ResourceBundleViewResolver.class, pvs); + registerSingleton("viewResolver", TestViewResolver.class, pvs); pvs = new MutablePropertyValues(); pvs.add("suffix", ".jsp"); @@ -511,6 +509,25 @@ public void cleanupMultipart(MultipartHttpServletRequest request) { } + private static class TestViewResolver implements ViewResolver, Ordered { + + @Override + public int getOrder() { + return 0; + } + + @Override + public @Nullable View resolveViewName(String viewName, Locale locale) throws Exception { + if (viewName.equalsIgnoreCase("form")) { + InternalResourceView view = new InternalResourceView("myform.jsp"); + view.setRequestContextAttribute("rc"); + return view; + } + return null; + } + } + + public static class TestApplicationListener implements ApplicationListener { public int counter = 0; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java index ed40136151c3..4f3891a2e53f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java @@ -24,7 +24,6 @@ import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.BeansException; -import org.springframework.beans.MutablePropertyValues; import org.springframework.web.context.support.StaticWebApplicationContext; import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; @@ -36,7 +35,6 @@ * @author Juergen Hoeller * @since 21.05.2003 */ -@SuppressWarnings("deprecation") public class SimpleWebApplicationContext extends StaticWebApplicationContext { @Override @@ -51,14 +49,11 @@ public void refresh() throws BeansException { registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class); registerSingleton("viewResolver", InternalResourceViewResolver.class); - MutablePropertyValues pvs = new MutablePropertyValues(); - pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml"); - registerSingleton("viewResolver2", org.springframework.web.servlet.view.XmlViewResolver.class, pvs); - super.refresh(); } + @SuppressWarnings("deprecation") public static class LocaleChecker implements Controller, org.springframework.web.servlet.mvc.LastModified { @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java index 8253d97705c3..c71d67550e26 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java @@ -316,6 +316,7 @@ void testCustomValidator() throws Exception { doTestCustomValidator("mvc-config-custom-validator.xml"); } + @SuppressWarnings("removal") private void doTestCustomValidator(String xml) throws Exception { loadBeanDefinitions(xml); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java index 3fed71e13c78..3308635a03c2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java @@ -26,8 +26,8 @@ import org.junit.jupiter.api.Test; import org.springframework.core.Ordered; +import org.springframework.http.server.RequestPath; import org.springframework.ui.ModelMap; -import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.web.context.request.WebRequest; import org.springframework.web.context.request.WebRequestInterceptor; @@ -37,6 +37,7 @@ import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; +import org.springframework.web.util.ServletRequestPathUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -178,12 +179,13 @@ void nonOrderedInterceptors() { } - private List getInterceptorsForPath(String lookupPath) { - PathMatcher pathMatcher = new AntPathMatcher(); + private List getInterceptorsForPath(@Nullable String lookupPath) { + lookupPath = (lookupPath != null ? lookupPath : ""); + this.request.setAttribute(ServletRequestPathUtils.PATH_ATTRIBUTE, RequestPath.parse(lookupPath, null)); List result = new ArrayList<>(); for (Object interceptor : this.registry.getInterceptors()) { if (interceptor instanceof MappedInterceptor mappedInterceptor) { - if (mappedInterceptor.matches(lookupPath, pathMatcher)) { + if (mappedInterceptor.matches(this.request)) { result.add(mappedInterceptor.getInterceptor()); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java index c6cb7c4045dc..1e1e1d7b7594 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java @@ -117,12 +117,12 @@ void setup() throws Exception { @PathPatternsParameterizedTest - void getMappingPathPatterns(TestRequestMappingInfoHandlerMapping mapping) { + void getDirectPaths(TestRequestMappingInfoHandlerMapping mapping) { String[] patterns = {"/foo/*", "/foo", "/bar/*", "/bar"}; RequestMappingInfo info = mapping.createInfo(patterns); - Set actual = mapping.getMappingPathPatterns(info); + Set actual = mapping.getDirectPaths(info); - assertThat(actual).isEqualTo(new HashSet<>(Arrays.asList(patterns))); + assertThat(actual).containsExactly("/foo", "/bar"); } @PathPatternsParameterizedTest diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java index 8d6b079be133..32182b2d672f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java @@ -69,6 +69,7 @@ import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; import org.springframework.web.servlet.resource.NoResourceFoundException; +import org.springframework.web.testfixture.http.MockHttpInputMessage; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; import org.springframework.web.testfixture.servlet.MockServletConfig; @@ -261,9 +262,8 @@ void typeMismatchWithProblemDetailViaMessageSource() { } @Test - @SuppressWarnings("deprecation") public void httpMessageNotReadable() { - testException(new HttpMessageNotReadableException("message")); + testException(new HttpMessageNotReadableException("message", new MockHttpInputMessage(new byte[0]))); } @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java index b9e26107d109..a81ac3f97dc5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java @@ -49,6 +49,7 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.resource.NoResourceFoundException; +import org.springframework.web.testfixture.http.MockHttpInputMessage; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -153,9 +154,8 @@ void handleTypeMismatch() { } @Test - @SuppressWarnings("deprecation") public void handleHttpMessageNotReadable() { - HttpMessageNotReadableException ex = new HttpMessageNotReadableException("foo"); + HttpMessageNotReadableException ex = new HttpMessageNotReadableException("foo", new MockHttpInputMessage(new byte[0])); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); assertThat(mav.isEmpty()).as("No Empty ModelAndView returned").isTrue(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverNoCacheTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverNoCacheTests.java deleted file mode 100644 index 3b8c14d3d9d6..000000000000 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverNoCacheTests.java +++ /dev/null @@ -1,29 +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.servlet.view; - -/** - * @author Rod Johnson - */ -class ResourceBundleViewResolverNoCacheTests extends ResourceBundleViewResolverTests { - - @Override - protected boolean getCache() { - return false; - } - -} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java deleted file mode 100644 index 5443fc044b93..000000000000 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java +++ /dev/null @@ -1,177 +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.servlet.view; - -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.BeanIsAbstractException; -import org.springframework.core.io.Resource; -import org.springframework.web.context.support.ServletContextResource; -import org.springframework.web.context.support.StaticWebApplicationContext; -import org.springframework.web.servlet.View; -import org.springframework.web.testfixture.servlet.MockServletContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -/** - * @author Rod Johnson - * @author Juergen Hoeller - * @author Sam Brannen - */ -@SuppressWarnings("deprecation") -public class ResourceBundleViewResolverTests { - - /** Comes from this package */ - private static final String PROPS_FILE = "org.springframework.web.servlet.view.testviews"; - - private final ResourceBundleViewResolver rb = new ResourceBundleViewResolver(); - - private final StaticWebApplicationContext wac = new StaticWebApplicationContext(); - - - @BeforeEach - void setUp() { - rb.setBasename(PROPS_FILE); - rb.setCache(getCache()); - rb.setDefaultParentView("testParent"); - - wac.setServletContext(new MockServletContext()); - wac.refresh(); - - // This will be propagated to views, so we need it. - rb.setApplicationContext(wac); - } - - /** - * Not a constant: allows overrides. - * Controls whether to cache views. - */ - protected boolean getCache() { - return true; - } - - - @Test - void parentsAreAbstract() { - assertThatExceptionOfType(BeanIsAbstractException.class).isThrownBy(() -> - rb.resolveViewName("debug.Parent", Locale.ENGLISH)); - assertThatExceptionOfType(BeanIsAbstractException.class).isThrownBy(() -> - rb.resolveViewName("testParent", Locale.ENGLISH)); - } - - @Test - void debugViewEnglish() throws Exception { - View v = rb.resolveViewName("debugView", Locale.ENGLISH); - assertThat(v).isInstanceOf(InternalResourceView.class); - InternalResourceView jv = (InternalResourceView) v; - assertThat(jv.getUrl()).as("debugView must have correct URL").isEqualTo("jsp/debug/debug.jsp"); - - Map m = jv.getStaticAttributes(); - assertThat(m.size()).as("Must have 2 static attributes").isEqualTo(2); - assertThat(m.get("foo")).as("attribute foo").isEqualTo("bar"); - assertThat(m.get("postcode")).as("attribute postcode").isEqualTo("SE10 9JY"); - - assertThat(jv.getContentType()).as("Correct default content type").isEqualTo(AbstractView.DEFAULT_CONTENT_TYPE); - } - - @Test - void debugViewFrench() throws Exception { - View v = rb.resolveViewName("debugView", Locale.FRENCH); - assertThat(v).isInstanceOf(InternalResourceView.class); - InternalResourceView jv = (InternalResourceView) v; - assertThat(jv.getUrl()).as("French debugView must have correct URL").isEqualTo("jsp/debug/deboug.jsp"); - assertThat(jv.getContentType()).as("Correct overridden (XML) content type").isEqualTo("text/xml;charset=ISO-8859-1"); - } - - @Test - void eagerInitialization() throws Exception { - ResourceBundleViewResolver rb = new ResourceBundleViewResolver(); - rb.setBasename(PROPS_FILE); - rb.setCache(getCache()); - rb.setDefaultParentView("testParent"); - rb.setLocalesToInitialize(Locale.ENGLISH, Locale.FRENCH); - rb.setApplicationContext(wac); - - View v = rb.resolveViewName("debugView", Locale.FRENCH); - assertThat(v).isInstanceOf(InternalResourceView.class); - InternalResourceView jv = (InternalResourceView) v; - assertThat(jv.getUrl()).as("French debugView must have correct URL").isEqualTo("jsp/debug/deboug.jsp"); - assertThat(jv.getContentType()).as("Correct overridden (XML) content type").isEqualTo("text/xml;charset=ISO-8859-1"); - } - - @Test - void sameBundleOnlyCachedOnce() throws Exception { - assumeTrue(rb.isCache()); - - View v1 = rb.resolveViewName("debugView", Locale.ENGLISH); - View v2 = rb.resolveViewName("debugView", Locale.UK); - assertThat(v2).isSameAs(v1); - } - - @Test - void noSuchViewEnglish() throws Exception { - assertThat(rb.resolveViewName("xxxxxxweorqiwuopeir", Locale.ENGLISH)).isNull(); - } - - @Test - void onSetContextCalledOnce() throws Exception { - TestView tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); - tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); - tv = (TestView) rb.resolveViewName("test", Locale.ENGLISH); - assertThat(tv.getBeanName()).as("test has correct name").isEqualTo("test"); - assertThat(tv.initCount).as("test should have been initialized once, not ").isEqualTo(1); - } - - @Test - void noSuchBasename() { - rb.setBasename("weoriwoierqupowiuer"); - assertThatExceptionOfType(MissingResourceException.class).isThrownBy(() -> - rb.resolveViewName("debugView", Locale.ENGLISH)); - } - - - static class TestView extends AbstractView { - - public int initCount; - - public void setLocation(Resource location) { - if (!(location instanceof ServletContextResource)) { - throw new IllegalArgumentException("Expecting ServletContextResource, not " + location.getClass().getName()); - } - } - - @Override - protected void renderMergedOutputModel(Map model, HttpServletRequest request, - HttpServletResponse response) { - } - - @Override - protected void initApplicationContext() { - ++initCount; - } - } - -} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java index e7d8d985bdf4..c8225a0d430f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java @@ -34,9 +34,7 @@ import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; -import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.testfixture.beans.TestBean; -import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.web.context.support.ServletContextResource; import org.springframework.web.context.support.StaticWebApplicationContext; @@ -51,19 +49,16 @@ import org.springframework.web.testfixture.servlet.MockServletContext; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests for {@link BeanNameViewResolver}, {@link UrlBasedViewResolver}, - * {@link InternalResourceViewResolver}, {@link org.springframework.web.servlet.view.XmlViewResolver}, - * and {@link AbstractCachingViewResolver}. + * {@link InternalResourceViewResolver}, and {@link AbstractCachingViewResolver}. * * @author Juergen Hoeller * @author Chris Beams * @author Sam Brannen * @since 18.06.2003 */ -@SuppressWarnings("deprecation") class ViewResolverTests { private final StaticWebApplicationContext wac = new StaticWebApplicationContext(); @@ -396,80 +391,6 @@ void internalResourceViewResolverWithJstlAndContextParam() throws Exception { assertThat(lc.getResourceBundle().getString("code2")).isEqualTo("message2"); } - @Test - @SuppressWarnings("deprecation") - void xmlViewResolver() throws Exception { - this.wac.registerSingleton("testBean", TestBean.class); - this.wac.refresh(); - TestBean testBean = (TestBean) this.wac.getBean("testBean"); - org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); - vr.setLocation(new ClassPathResource("org/springframework/web/servlet/view/views.xml")); - vr.setApplicationContext(this.wac); - - View view1 = vr.resolveViewName("example1", Locale.getDefault()); - assertThat(TestView.class.equals(view1.getClass())).as("Correct view class").isTrue(); - assertThat(((InternalResourceView) view1).getUrl()).as("Correct URL").isEqualTo("/example1.jsp"); - - View view2 = vr.resolveViewName("example2", Locale.getDefault()); - assertThat(JstlView.class.equals(view2.getClass())).as("Correct view class").isTrue(); - assertThat(((InternalResourceView) view2).getUrl()).as("Correct URL").isEqualTo("/example2new.jsp"); - - Map model = new HashMap<>(); - TestBean tb = new TestBean(); - model.put("tb", tb); - - this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac); - this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); - view1.render(model, this.request, this.response); - assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue(); - assertThat(this.request.getAttribute("test1")).as("Correct test1 attribute").isEqualTo("testvalue1"); - assertThat(testBean.equals(this.request.getAttribute("test2"))).as("Correct test2 attribute").isTrue(); - - this.request.clearAttributes(); - this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac); - this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); - view2.render(model, this.request, this.response); - assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue(); - assertThat(this.request.getAttribute("test1")).as("Correct test1 attribute").isEqualTo("testvalue1"); - assertThat(this.request.getAttribute("test2")).as("Correct test2 attribute").isEqualTo("testvalue2"); - } - - @Test - @SuppressWarnings("deprecation") - void xmlViewResolverDefaultLocation() { - StaticWebApplicationContext wac = new StaticWebApplicationContext() { - @Override - protected Resource getResourceByPath(String path) { - assertThat(path).as("Correct default location").isEqualTo(XmlViewResolver.DEFAULT_LOCATION); - return super.getResourceByPath(path); - } - }; - wac.setServletContext(this.sc); - wac.refresh(); - org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); - vr.setApplicationContext(wac); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(vr::afterPropertiesSet); - } - - @Test - @SuppressWarnings("deprecation") - void xmlViewResolverWithoutCache() { - StaticWebApplicationContext wac = new StaticWebApplicationContext() { - @Override - protected Resource getResourceByPath(String path) { - assertThat(path).as("Correct default location").isEqualTo(XmlViewResolver.DEFAULT_LOCATION); - return super.getResourceByPath(path); - } - }; - wac.setServletContext(this.sc); - wac.refresh(); - org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); - vr.setCache(false); - vr.setApplicationContext(wac); - assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> - vr.resolveViewName("example1", Locale.getDefault())); - } - @Test void cacheRemoval() throws Exception { this.wac.refresh(); diff --git a/spring-webmvc/src/test/resources/org/springframework/web/context/WEB-INF/sessionContext.xml b/spring-webmvc/src/test/resources/org/springframework/web/context/WEB-INF/sessionContext.xml deleted file mode 100644 index bf6fec590f56..000000000000 --- a/spring-webmvc/src/test/resources/org/springframework/web/context/WEB-INF/sessionContext.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-webmvc/src/test/resources/org/springframework/web/servlet/complexviews.properties b/spring-webmvc/src/test/resources/org/springframework/web/servlet/complexviews.properties deleted file mode 100644 index 6917be216279..000000000000 --- a/spring-webmvc/src/test/resources/org/springframework/web/servlet/complexviews.properties +++ /dev/null @@ -1,3 +0,0 @@ -form.(class)=org.springframework.web.servlet.view.InternalResourceView -form.requestContextAttribute=rc -form.url=myform.jsp