From ade812806099eccb5b14314e98a7f92c8652ce77 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Thu, 18 Jul 2024 10:42:45 +0100 Subject: [PATCH] Remove deprecated methods Closes gh-33123 --- .../bind/MethodArgumentNotValidException.java | 44 +--------- .../support/WebExchangeBindException.java | 15 +--- .../service/invoker/HttpRequestValues.java | 87 +------------------ .../invoker/HttpServiceProxyFactory.java | 63 +------------- .../invoker/ReactiveHttpRequestValues.java | 35 -------- .../client/support/WebClientAdapter.java | 14 +-- .../view/freemarker/FreeMarkerView.java | 38 +------- .../view/freemarker/FreeMarkerViewTests.java | 4 +- 8 files changed, 10 insertions(+), 290 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/bind/MethodArgumentNotValidException.java b/spring-web/src/main/java/org/springframework/web/bind/MethodArgumentNotValidException.java index c8487e6f802f..442c9ac30d1b 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/MethodArgumentNotValidException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/MethodArgumentNotValidException.java @@ -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. @@ -16,16 +16,13 @@ package org.springframework.web.bind; -import java.util.List; import java.util.Locale; -import java.util.Map; import org.springframework.context.MessageSource; import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; import org.springframework.validation.ObjectError; @@ -92,45 +89,6 @@ public Object[] getDetailMessageArguments() { BindErrorUtils.resolveAndJoin(getFieldErrors())}; } - /** - * Convert each given {@link ObjectError} to a String. - * @since 6.0 - * @deprecated in favor of using {@link BindErrorUtils} and - * {@link #getAllErrors()}, to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public static List errorsToStringList(List errors) { - return BindErrorUtils.resolve(errors).values().stream().toList(); - } - - /** - * Convert each given {@link ObjectError} to a String, and use a - * {@link MessageSource} to resolve each error. - * @since 6.0 - * @deprecated in favor of {@link BindErrorUtils}, to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public static List errorsToStringList( - List errors, @Nullable MessageSource messageSource, Locale locale) { - - return (messageSource != null ? - BindErrorUtils.resolve(errors, messageSource, locale).values().stream().toList() : - BindErrorUtils.resolve(errors).values().stream().toList()); - } - - /** - * Resolve global and field errors to messages with the given - * {@link MessageSource} and {@link Locale}. - * @return a Map with errors as keys and resolved messages as values - * @since 6.0.3 - * @deprecated in favor of using {@link BindErrorUtils} and - * {@link #getAllErrors()}, to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public Map resolveErrorMessages(MessageSource messageSource, Locale locale) { - return BindErrorUtils.resolve(getAllErrors(), messageSource, locale); - } - @Override public String getMessage() { StringBuilder sb = new StringBuilder("Validation failed for argument [") diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java index d6a90a079549..d7204f7498f3 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java @@ -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. @@ -78,19 +78,6 @@ public Object[] getDetailMessageArguments(MessageSource source, Locale locale) { BindErrorUtils.resolveAndJoin(getFieldErrors(), source, locale)}; } - /** - * Resolve global and field errors to messages with the given - * {@link MessageSource} and {@link Locale}. - * @return a Map with errors as key and resolves messages as value - * @since 6.0.3 - * @deprecated in favor of using {@link BindErrorUtils} and - * {@link #getAllErrors()}, to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public Map resolveErrorMessages(MessageSource messageSource, Locale locale) { - return BindErrorUtils.resolve(getAllErrors(), messageSource, locale); - } - // BindingResult implementation methods diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java index 12598fb22a00..77f2bb03e566 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java @@ -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. @@ -23,10 +23,6 @@ import java.util.List; import java.util.Map; -import org.reactivestreams.Publisher; - -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.ResolvableType; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -80,22 +76,6 @@ public class HttpRequestValues { private final Object bodyValue; - /** - * Constructor without UriBuilderFactory. - * @deprecated in favour of - * {@link HttpRequestValues#HttpRequestValues(HttpMethod, URI, UriBuilderFactory, String, Map, HttpHeaders, MultiValueMap, Map, Object)} - * to be removed in 6.2. - */ - @Deprecated(since = "6.1", forRemoval = true) - protected HttpRequestValues(@Nullable HttpMethod httpMethod, - @Nullable URI uri, @Nullable String uriTemplate, - Map uriVariables, - HttpHeaders headers, MultiValueMap cookies, Map attributes, - @Nullable Object bodyValue) { - - this(httpMethod, uri, null, uriTemplate, uriVariables, headers, cookies, attributes, bodyValue); - } - /** * Construct {@link HttpRequestValues}. * @since 6.1 @@ -197,30 +177,6 @@ public Object getBodyValue() { return this.bodyValue; } - /** - * Return the request body as a Publisher. - *

This is mutually exclusive with {@link #getBodyValue()}. - * Only one of the two or neither is set. - * @deprecated in favor of {@link ReactiveHttpRequestValues#getBodyPublisher()}; - * to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - @Nullable - public Publisher getBody() { - throw new UnsupportedOperationException(); - } - - /** - * Return the element type for a Publisher body. - * @deprecated in favor of {@link ReactiveHttpRequestValues#getBodyPublisherElementType()}; - * to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - @Nullable - public ParameterizedTypeReference getBodyElementType() { - throw new UnsupportedOperationException(); - } - public static Builder builder() { return new Builder(); @@ -383,17 +339,6 @@ public Builder addRequestPart(String name, Object part) { return this; } - /** - * Variant of {@link #addRequestPart(String, Object)} that allows the - * part value to be produced by a {@link Publisher}. - * @deprecated in favor of {@link ReactiveHttpRequestValues.Builder#addRequestPartPublisher}; - * to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public > Builder addRequestPart(String name, P publisher, ResolvableType type) { - throw new UnsupportedOperationException(); - } - /** * Configure an attribute to associate with the request. * @param name the attribute name @@ -412,18 +357,6 @@ public void setBodyValue(@Nullable Object bodyValue) { this.bodyValue = bodyValue; } - /** - * Set the request body as a Reactive Streams Publisher. - *

This is mutually exclusive with, and resets any previously set - * {@linkplain #setBodyValue(Object) body value}. - * @deprecated in favor of {@link ReactiveHttpRequestValues.Builder#setBodyPublisher}; - * to be removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - public > void setBody(P body, ParameterizedTypeReference elementTye) { - throw new UnsupportedOperationException(); - } - /** * Build the {@link HttpRequestValues} instance. */ @@ -513,24 +446,6 @@ private String appendQueryParams( return uriComponentsBuilder.build().toUriString(); } - /** - * Create {@link HttpRequestValues} from values passed to the {@link Builder}. - * @deprecated in favour of - * {@link Builder#createRequestValues(HttpMethod, URI, UriBuilderFactory, String, Map, HttpHeaders, MultiValueMap, Map, Object)} - * to be removed in 6.2. - */ - @Deprecated(since = "6.1", forRemoval = true) - protected HttpRequestValues createRequestValues( - @Nullable HttpMethod httpMethod, - @Nullable URI uri, @Nullable String uriTemplate, - Map uriVars, - HttpHeaders headers, MultiValueMap cookies, Map attributes, - @Nullable Object bodyValue) { - - return createRequestValues(httpMethod, uri, null, uriTemplate, - uriVars, headers, cookies, attributes, bodyValue); - } - /** * Create {@link HttpRequestValues} from values passed to the {@link Builder}. * @since 6.1 diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java index ec78080c7c30..863377344b16 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java @@ -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. @@ -18,7 +18,6 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -32,7 +31,6 @@ import org.springframework.aop.framework.ReflectiveMethodInvocation; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodIntrospector; -import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; @@ -112,17 +110,6 @@ public static Builder builderFor(HttpExchangeAdapter exchangeAdapter) { return new Builder().exchangeAdapter(exchangeAdapter); } - /** - * Return a builder that's initialized with the given client. - * @deprecated in favor of {@link #builderFor(HttpExchangeAdapter)}; - * to be removed in 6.2. - */ - @SuppressWarnings("removal") - @Deprecated(since = "6.1", forRemoval = true) - public static Builder builder(HttpClientAdapter clientAdapter) { - return new Builder().exchangeAdapter(clientAdapter.asReactorExchangeAdapter()); - } - /** * Return an empty builder, with the client to be provided to builder. */ @@ -161,20 +148,6 @@ public Builder exchangeAdapter(HttpExchangeAdapter adapter) { return this; } - /** - * Provide the HTTP client to perform requests through. - * @param clientAdapter a client adapted to {@link HttpClientAdapter} - * @return this same builder instance - * @deprecated in favor of {@link #exchangeAdapter(HttpExchangeAdapter)}; - * to be removed in 6.2 - */ - @SuppressWarnings("removal") - @Deprecated(since = "6.1", forRemoval = true) - public Builder clientAdapter(HttpClientAdapter clientAdapter) { - this.exchangeAdapter = clientAdapter.asReactorExchangeAdapter(); - return this; - } - /** * Register a custom argument resolver, invoked ahead of default resolvers. * @param resolver the resolver to add @@ -207,40 +180,6 @@ public Builder embeddedValueResolver(StringValueResolver embeddedValueResolver) return this; } - /** - * Set the {@link ReactiveAdapterRegistry} to use to support different - * asynchronous types for HTTP service method return values. - *

By default this is {@link ReactiveAdapterRegistry#getSharedInstance()}. - * @return this same builder instance - * @deprecated in favor of setting the same directly on the {@link HttpExchangeAdapter} - */ - @Deprecated(since = "6.1", forRemoval = true) - public Builder reactiveAdapterRegistry(ReactiveAdapterRegistry registry) { - if (this.exchangeAdapter instanceof AbstractReactorHttpExchangeAdapter settable) { - settable.setReactiveAdapterRegistry(registry); - } - return this; - } - - /** - * Configure how long to block for the response of an HTTP service method - * with a synchronous (blocking) method signature. - *

By default this is not set, in which case the behavior depends on - * connection and request timeout settings of the underlying HTTP client. - * We recommend configuring timeout values directly on the underlying HTTP - * client, which provides more control over such settings. - * @param blockTimeout the timeout value - * @return this same builder instance - * @deprecated in favor of setting the same directly on the {@link HttpExchangeAdapter} - */ - @Deprecated(since = "6.1", forRemoval = true) - public Builder blockTimeout(@Nullable Duration blockTimeout) { - if (this.exchangeAdapter instanceof AbstractReactorHttpExchangeAdapter settable) { - settable.setBlockTimeout(blockTimeout); - } - return this; - } - /** * Build the {@link HttpServiceProxyFactory} instance. */ diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java index 6b76db2a7ddf..de5d477f2e96 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java @@ -23,7 +23,6 @@ import org.reactivestreams.Publisher; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; @@ -80,28 +79,6 @@ public ParameterizedTypeReference getBodyPublisherElementType() { return this.bodyElementType; } - /** - * Return the request body as a {@link Publisher}. - *

This is mutually exclusive with {@link #getBodyValue()}. - * Only one of the two or neither is set. - */ - @Override - @SuppressWarnings("removal") - @Nullable - public Publisher getBody() { - return getBodyPublisher(); - } - - /** - * Return the element type for a {@linkplain #getBodyPublisher() body publisher}. - */ - @Override - @SuppressWarnings("removal") - @Nullable - public ParameterizedTypeReference getBodyElementType() { - return getBodyPublisherElementType(); - } - public static Builder builder() { return new Builder(); @@ -211,12 +188,6 @@ public > Builder addRequestPartPublisher( return this; } - @SuppressWarnings("removal") - @Override - public > Builder addRequestPart(String name, P publisher, ResolvableType type) { - return addRequestPartPublisher(name, publisher, ParameterizedTypeReference.forType(type.getType())); - } - /** * {@inheritDoc} *

This is mutually exclusive with and resets any previously set @@ -242,12 +213,6 @@ public > void setBodyPublisher(P body, ParameterizedTy super.setBodyValue(null); } - @SuppressWarnings("removal") - @Override - public > void setBody(P body, ParameterizedTypeReference elementTye) { - setBodyPublisher(body, elementTye); - } - @Override public ReactiveHttpRequestValues build() { return (ReactiveHttpRequestValues) super.build(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/WebClientAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/WebClientAdapter.java index a344bf20a837..03e85490bafa 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/WebClientAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/WebClientAdapter.java @@ -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. @@ -155,16 +155,4 @@ public static WebClientAdapter create(WebClient webClient) { return new WebClientAdapter(webClient); } - /** - * Create a {@link WebClientAdapter} for the given {@code WebClient} instance. - * @param webClient the client to use - * @return the created adapter instance - * @deprecated in favor of {@link #create(WebClient)} aligning with other adapter - * implementations; to be removed in 6.2. - */ - @Deprecated(since = "6.1", forRemoval = true) - public static WebClientAdapter forClient(WebClient webClient) { - return new WebClientAdapter(webClient); - } - } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java index 955381dc164d..43d1b9395470 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java @@ -248,24 +248,9 @@ protected FreeMarkerConfig autodetectConfiguration() throws BeansException { * multiple templates to be rendered into a single view. */ @Override - public boolean checkResourceExists(Locale locale) throws Exception { - try { - // Check that we can get the template, even if we might subsequently get it again. - getTemplate(locale); - return true; - } - catch (FileNotFoundException ex) { - // Allow for ViewResolver chaining... - return false; - } - catch (ParseException ex) { - throw new ApplicationContextException( - "Failed to parse FreeMarker template for URL [" + getUrl() + "]", ex); - } - catch (IOException ex) { - throw new ApplicationContextException( - "Could not load FreeMarker template for URL [" + getUrl() + "]", ex); - } + public boolean checkResourceExists(Locale locale) { + throw new UnsupportedOperationException( + "This should never be called as we override resourceExists returning Mono"); } /** @@ -378,23 +363,6 @@ protected ObjectWrapper getObjectWrapper() { return (ow != null ? ow : new DefaultObjectWrapperBuilder(version).build()); } - /** - * Retrieve the FreeMarker {@link Template} to be rendered by this view, for - * the specified locale and using the {@linkplain #setEncoding(String) configured - * encoding} if set. - *

By default, the template specified by the "url" bean property will be retrieved. - * @param locale the current locale - * @return the FreeMarker template to render - * @deprecated since 6.1, in favor of {@link #lookupTemplate(Locale)}, to be - * removed in 6.2 - */ - @Deprecated(since = "6.1", forRemoval = true) - protected Template getTemplate(Locale locale) throws IOException { - return (getEncoding() != null ? - obtainConfiguration().getTemplate(getUrl(), locale, getEncoding()) : - obtainConfiguration().getTemplate(getUrl(), locale)); - } - /** * Retrieve the FreeMarker {@link Template} to be rendered by this view, for * the specified locale and using the {@linkplain #setEncoding(String) configured diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java index 32926929cc28..620ef77ecacc 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerViewTests.java @@ -91,11 +91,11 @@ void noTemplateName() { } @Test - void checkResourceExists() throws Exception { + void checkResourceExists() { freeMarkerView.setConfiguration(this.freeMarkerConfig); freeMarkerView.setUrl("test.ftl"); - assertThat(freeMarkerView.checkResourceExists(Locale.US)).isTrue(); + assertThat(freeMarkerView.resourceExists(Locale.US).block(Duration.ofSeconds(1))).isTrue(); } @Test