mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Polish "Remove APIs that were deprecated for removal in 4.2"
See gh-50955
This commit is contained in:
+2
-15
@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
||||
@@ -36,8 +37,6 @@ class OperationMethodParameterTests {
|
||||
|
||||
private final Method example = findMethod("example", String.class, String.class);
|
||||
|
||||
private final Method exampleSpringNullable = findMethod("exampleSpringNullable", String.class, String.class);
|
||||
|
||||
private final Method exampleAnnotation = findMethod("exampleAnnotation", String.class);
|
||||
|
||||
@Test
|
||||
@@ -64,14 +63,6 @@ class OperationMethodParameterTests {
|
||||
assertThat(parameter.isMandatory()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated(since = "4.0.0")
|
||||
void isMandatoryWhenSpringNullableAnnotationShouldReturnFalse() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name",
|
||||
this.exampleSpringNullable.getParameters()[1]);
|
||||
assertThat(parameter.isMandatory()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAnnotationShouldReturnAnnotation() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name",
|
||||
@@ -87,11 +78,7 @@ class OperationMethodParameterTests {
|
||||
return method;
|
||||
}
|
||||
|
||||
void example(String one, @org.jspecify.annotations.Nullable String two) {
|
||||
}
|
||||
|
||||
@Deprecated(since = "4.0.0")
|
||||
void exampleSpringNullable(String one, @org.springframework.lang.Nullable String two) {
|
||||
void example(String one, @Nullable String two) {
|
||||
}
|
||||
|
||||
void exampleAnnotation(@Selector(match = Match.ALL_REMAINING) String allRemaining) {
|
||||
|
||||
+1
-14
@@ -25,7 +25,6 @@ import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.configuration.support.JdbcDefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.repository.ExecutionContextSerializer;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
@@ -91,23 +90,19 @@ public final class BatchJdbcAutoConfiguration {
|
||||
|
||||
private final @Nullable ExecutionContextSerializer executionContextSerializer;
|
||||
|
||||
private final @Nullable JobParametersConverter jobParametersConverter;
|
||||
|
||||
SpringBootBatchJdbcConfiguration(DataSource dataSource,
|
||||
@BatchDataSource ObjectProvider<DataSource> batchDataSource,
|
||||
PlatformTransactionManager transactionManager,
|
||||
@BatchTransactionManager ObjectProvider<PlatformTransactionManager> batchTransactionManager,
|
||||
@BatchTaskExecutor ObjectProvider<TaskExecutor> batchTaskExecutor, BatchJdbcProperties properties,
|
||||
ObjectProvider<BatchConversionServiceCustomizer> batchConversionServiceCustomizers,
|
||||
ObjectProvider<ExecutionContextSerializer> executionContextSerializer,
|
||||
ObjectProvider<JobParametersConverter> jobParametersConverter) {
|
||||
ObjectProvider<ExecutionContextSerializer> executionContextSerializer) {
|
||||
this.dataSource = batchDataSource.getIfAvailable(() -> dataSource);
|
||||
this.transactionManager = batchTransactionManager.getIfAvailable(() -> transactionManager);
|
||||
this.taskExecutor = batchTaskExecutor.getIfAvailable();
|
||||
this.properties = properties;
|
||||
this.batchConversionServiceCustomizers = batchConversionServiceCustomizers.orderedStream().toList();
|
||||
this.executionContextSerializer = executionContextSerializer.getIfAvailable();
|
||||
this.jobParametersConverter = jobParametersConverter.getIfAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,14 +147,6 @@ public final class BatchJdbcAutoConfiguration {
|
||||
: super.getExecutionContextSerializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
protected JobParametersConverter getJobParametersConverter() {
|
||||
return (this.jobParametersConverter != null) ? this.jobParametersConverter
|
||||
: super.getJobParametersConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskExecutor getTaskExecutor() {
|
||||
return (this.taskExecutor != null) ? this.taskExecutor : super.getTaskExecutor();
|
||||
|
||||
-28
@@ -31,9 +31,6 @@ import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JsonJobParametersConverter;
|
||||
import org.springframework.batch.core.job.AbstractJob;
|
||||
import org.springframework.batch.core.job.Job;
|
||||
import org.springframework.batch.core.job.JobExecution;
|
||||
@@ -514,31 +511,6 @@ class BatchJdbcAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
void customJobParametersConverterIsUsed() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withBean(JobParametersConverter.class, JsonJobParametersConverter::new)
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(JsonJobParametersConverter.class);
|
||||
assertThat(context.getBean(SpringBootBatchJdbcConfiguration.class).getJobParametersConverter())
|
||||
.isInstanceOf(JsonJobParametersConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
void defaultJobParametersConverterIsUsed() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(JobParametersConverter.class);
|
||||
assertThat(context.getBean(SpringBootBatchJdbcConfiguration.class).getJobParametersConverter())
|
||||
.isInstanceOf(DefaultJobParametersConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
private JobLauncherApplicationRunner createInstance(String... registeredJobNames) {
|
||||
JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobOperator.class));
|
||||
JobRegistry jobRegistry = mock(JobRegistry.class);
|
||||
|
||||
+1
-14
@@ -20,7 +20,6 @@ import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
@@ -49,20 +48,8 @@ public final class BatchAutoConfiguration {
|
||||
|
||||
private final @Nullable TaskExecutor taskExecutor;
|
||||
|
||||
private final @Nullable JobParametersConverter jobParametersConverter;
|
||||
|
||||
SpringBootBatchDefaultConfiguration(@BatchTaskExecutor ObjectProvider<TaskExecutor> batchTaskExecutor,
|
||||
ObjectProvider<JobParametersConverter> jobParametersConverter) {
|
||||
SpringBootBatchDefaultConfiguration(@BatchTaskExecutor ObjectProvider<TaskExecutor> batchTaskExecutor) {
|
||||
this.taskExecutor = batchTaskExecutor.getIfAvailable();
|
||||
this.jobParametersConverter = jobParametersConverter.getIfAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
protected JobParametersConverter getJobParametersConverter() {
|
||||
return (this.jobParametersConverter != null) ? this.jobParametersConverter
|
||||
: super.getJobParametersConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-25
@@ -25,9 +25,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
|
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JsonJobParametersConverter;
|
||||
import org.springframework.batch.core.job.Job;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
@@ -135,28 +132,6 @@ class BatchAutoConfigurationTests {
|
||||
.withMessage("No job found with name 'three'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
void customJobParametersConverterIsUsed() {
|
||||
this.contextRunner.withBean(JobParametersConverter.class, JsonJobParametersConverter::new).run((context) -> {
|
||||
assertThat(context).hasSingleBean(JsonJobParametersConverter.class);
|
||||
assertThat(context.getBean(SpringBootBatchDefaultConfiguration.class).getJobParametersConverter())
|
||||
.isInstanceOf(JsonJobParametersConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
void defaultJobParametersConverterIsUsed() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(JobParametersConverter.class);
|
||||
assertThat(context.getBean(SpringBootBatchDefaultConfiguration.class).getJobParametersConverter())
|
||||
.isInstanceOf(DefaultJobParametersConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
private JobLauncherApplicationRunner createInstance(String... registeredJobNames) {
|
||||
JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(mock(JobOperator.class));
|
||||
JobRegistry jobRegistry = mock(JobRegistry.class);
|
||||
|
||||
+10
-22
@@ -18,41 +18,29 @@ package org.springframework.boot.http.converter.autoconfigure;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverters.ClientBuilder;
|
||||
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class DefaultClientHttpMessageConvertersCustomizer implements ClientHttpMessageConvertersCustomizer {
|
||||
|
||||
private final @Nullable HttpMessageConverters legacyConverters;
|
||||
|
||||
private final Collection<HttpMessageConverter<?>> converters;
|
||||
|
||||
DefaultClientHttpMessageConvertersCustomizer(@Nullable HttpMessageConverters legacyConverters,
|
||||
Collection<HttpMessageConverter<?>> converters) {
|
||||
this.legacyConverters = legacyConverters;
|
||||
DefaultClientHttpMessageConvertersCustomizer(Collection<HttpMessageConverter<?>> converters) {
|
||||
this.converters = converters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ClientBuilder builder) {
|
||||
if (this.legacyConverters != null) {
|
||||
this.legacyConverters.forEach(builder::addCustomConverter);
|
||||
}
|
||||
else {
|
||||
builder.registerDefaults();
|
||||
this.converters.forEach((converter) -> {
|
||||
if (converter instanceof KotlinSerializationJsonHttpMessageConverter) {
|
||||
builder.withKotlinSerializationJsonConverter(converter);
|
||||
}
|
||||
else {
|
||||
builder.addCustomConverter(converter);
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.registerDefaults();
|
||||
this.converters.forEach((converter) -> {
|
||||
if (converter instanceof KotlinSerializationJsonHttpMessageConverter) {
|
||||
builder.withKotlinSerializationJsonConverter(converter);
|
||||
}
|
||||
else {
|
||||
builder.addCustomConverter(converter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-23
@@ -18,42 +18,29 @@ package org.springframework.boot.http.converter.autoconfigure;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverters.ServerBuilder;
|
||||
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class DefaultServerHttpMessageConvertersCustomizer implements ServerHttpMessageConvertersCustomizer {
|
||||
|
||||
private final @Nullable HttpMessageConverters legacyConverters;
|
||||
|
||||
private final Collection<HttpMessageConverter<?>> converters;
|
||||
|
||||
DefaultServerHttpMessageConvertersCustomizer(@Nullable HttpMessageConverters legacyConverters,
|
||||
Collection<HttpMessageConverter<?>> converters) {
|
||||
|
||||
this.legacyConverters = legacyConverters;
|
||||
DefaultServerHttpMessageConvertersCustomizer(Collection<HttpMessageConverter<?>> converters) {
|
||||
this.converters = converters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ServerBuilder builder) {
|
||||
if (this.legacyConverters != null) {
|
||||
this.legacyConverters.forEach(builder::addCustomConverter);
|
||||
}
|
||||
else {
|
||||
builder.registerDefaults();
|
||||
this.converters.forEach((converter) -> {
|
||||
if (converter instanceof KotlinSerializationJsonHttpMessageConverter) {
|
||||
builder.withKotlinSerializationJsonConverter(converter);
|
||||
}
|
||||
else {
|
||||
builder.addCustomConverter(converter);
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.registerDefaults();
|
||||
this.converters.forEach((converter) -> {
|
||||
if (converter instanceof KotlinSerializationJsonHttpMessageConverter) {
|
||||
builder.withKotlinSerializationJsonConverter(converter);
|
||||
}
|
||||
else {
|
||||
builder.addCustomConverter(converter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-262
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.boot.http.converter.autoconfigure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
/**
|
||||
* Bean used to manage the {@link HttpMessageConverter}s used in a Spring Boot
|
||||
* application. Provides a convenient way to add and merge additional
|
||||
* {@link HttpMessageConverter}s to a web application.
|
||||
* <p>
|
||||
* An instance of this bean can be registered with specific
|
||||
* {@link #HttpMessageConverters(HttpMessageConverter...) additional converters} if
|
||||
* needed, otherwise default converters will be used.
|
||||
* <p>
|
||||
* NOTE: The default converters used are the same as standard Spring MVC (see
|
||||
* {@link WebMvcConfigurationSupport}) with some slight re-ordering to put XML converters
|
||||
* at the back of the list.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @since 4.0.0
|
||||
* @see #HttpMessageConverters(HttpMessageConverter...)
|
||||
* @see #HttpMessageConverters(Collection)
|
||||
* @see #getConverters()
|
||||
* @deprecated since 4.0.0 for removal in 4.2.0 in favor of
|
||||
* {@link ClientHttpMessageConvertersCustomizer} and
|
||||
* {@link ServerHttpMessageConvertersCustomizer}.
|
||||
*/
|
||||
@Deprecated(since = "4.0.0")
|
||||
public class HttpMessageConverters implements Iterable<HttpMessageConverter<?>> {
|
||||
|
||||
private static final List<Class<?>> NON_REPLACING_CONVERTERS;
|
||||
|
||||
static {
|
||||
List<Class<?>> nonReplacingConverters = new ArrayList<>();
|
||||
addClassIfExists(nonReplacingConverters,
|
||||
"org.springframework.hateoas.server.mvc.TypeConstrainedJacksonJsonHttpMessageConverter");
|
||||
NON_REPLACING_CONVERTERS = Collections.unmodifiableList(nonReplacingConverters);
|
||||
}
|
||||
|
||||
private static final MultiValueMap<Class<?>, Class<?>> EQUIVALENT_CONVERTERS;
|
||||
|
||||
static {
|
||||
MultiValueMap<Class<?>, Class<?>> equivalentConverters = new LinkedMultiValueMap<>();
|
||||
putIfExists(equivalentConverters, "org.springframework.http.converter.json.JacksonJsonHttpMessageConverter",
|
||||
"org.springframework.http.converter.json.MappingJackson2HttpMessageConverter",
|
||||
"org.springframework.http.converter.json.GsonHttpMessageConverter",
|
||||
"org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter");
|
||||
putIfExists(equivalentConverters, "org.springframework.http.converter.json.MappingJackson2HttpMessageConverter",
|
||||
"org.springframework.http.converter.json.GsonHttpMessageConverter",
|
||||
"org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter");
|
||||
EQUIVALENT_CONVERTERS = CollectionUtils.unmodifiableMultiValueMap(equivalentConverters);
|
||||
}
|
||||
|
||||
private final List<HttpMessageConverter<?>> converters;
|
||||
|
||||
/**
|
||||
* Create a new {@link HttpMessageConverters} instance with the specified additional
|
||||
* converters.
|
||||
* @param additionalConverters additional converters to be added. Items are added just
|
||||
* before any default converter of the same type (or at the front of the list if no
|
||||
* default converter is found). The {@link #postProcessConverters(List)} method can be
|
||||
* used for further converter manipulation.
|
||||
*/
|
||||
public HttpMessageConverters(HttpMessageConverter<?>... additionalConverters) {
|
||||
this(Arrays.asList(additionalConverters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link HttpMessageConverters} instance with the specified additional
|
||||
* converters.
|
||||
* @param additionalConverters additional converters to be added. Items are added just
|
||||
* before any default converter of the same type (or at the front of the list if no
|
||||
* default converter is found). The {@link #postProcessConverters(List)} method can be
|
||||
* used for further converter manipulation.
|
||||
*/
|
||||
public HttpMessageConverters(Collection<HttpMessageConverter<?>> additionalConverters) {
|
||||
this(true, additionalConverters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link HttpMessageConverters} instance with the specified converters.
|
||||
* @param addDefaultConverters if default converters should be added
|
||||
* @param converters converters to be added. Items are added just before any default
|
||||
* converter of the same type (or at the front of the list if no default converter is
|
||||
* found). The {@link #postProcessConverters(List)} method can be used for further
|
||||
* converter manipulation.
|
||||
*/
|
||||
public HttpMessageConverters(boolean addDefaultConverters, Collection<HttpMessageConverter<?>> converters) {
|
||||
List<HttpMessageConverter<?>> combined = getCombinedConverters(converters,
|
||||
addDefaultConverters ? getDefaultConverters() : Collections.emptyList());
|
||||
combined = postProcessConverters(combined);
|
||||
this.converters = Collections.unmodifiableList(combined);
|
||||
}
|
||||
|
||||
private List<HttpMessageConverter<?>> getCombinedConverters(Collection<HttpMessageConverter<?>> converters,
|
||||
List<HttpMessageConverter<?>> defaultConverters) {
|
||||
List<HttpMessageConverter<?>> combined = new ArrayList<>();
|
||||
List<HttpMessageConverter<?>> processing = new ArrayList<>(converters);
|
||||
for (HttpMessageConverter<?> defaultConverter : defaultConverters) {
|
||||
Iterator<HttpMessageConverter<?>> iterator = processing.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
HttpMessageConverter<?> candidate = iterator.next();
|
||||
if (isReplacement(defaultConverter, candidate)) {
|
||||
combined.add(candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
combined.add(defaultConverter);
|
||||
if (defaultConverter instanceof AllEncompassingFormHttpMessageConverter allEncompassingConverter) {
|
||||
configurePartConverters(allEncompassingConverter, converters);
|
||||
}
|
||||
}
|
||||
combined.addAll(0, processing);
|
||||
return combined;
|
||||
}
|
||||
|
||||
private boolean isReplacement(HttpMessageConverter<?> defaultConverter, HttpMessageConverter<?> candidate) {
|
||||
for (Class<?> nonReplacingConverter : NON_REPLACING_CONVERTERS) {
|
||||
if (nonReplacingConverter.isInstance(candidate)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Class<?> converterClass = defaultConverter.getClass();
|
||||
if (ClassUtils.isAssignableValue(converterClass, candidate)) {
|
||||
return true;
|
||||
}
|
||||
List<Class<?>> equivalentClasses = EQUIVALENT_CONVERTERS.get(converterClass);
|
||||
return (equivalentClasses != null) && equivalentClasses.stream()
|
||||
.anyMatch((equivalentClass) -> equivalentClass != null
|
||||
&& ClassUtils.isAssignableValue(equivalentClass, candidate));
|
||||
}
|
||||
|
||||
private void configurePartConverters(AllEncompassingFormHttpMessageConverter formConverter,
|
||||
Collection<HttpMessageConverter<?>> converters) {
|
||||
List<HttpMessageConverter<?>> partConverters = formConverter.getPartConverters();
|
||||
List<HttpMessageConverter<?>> combinedConverters = getCombinedConverters(converters, partConverters);
|
||||
combinedConverters = postProcessPartConverters(combinedConverters);
|
||||
formConverter.setPartConverters(combinedConverters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that can be used to post-process the {@link HttpMessageConverter} list
|
||||
* before it is used.
|
||||
* @param converters a mutable list of the converters that will be used.
|
||||
* @return the final converts list to use
|
||||
*/
|
||||
protected List<HttpMessageConverter<?>> postProcessConverters(List<HttpMessageConverter<?>> converters) {
|
||||
return converters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that can be used to post-process the {@link HttpMessageConverter} list
|
||||
* before it is used to configure the part converters of
|
||||
* {@link AllEncompassingFormHttpMessageConverter}.
|
||||
* @param converters a mutable list of the converters that will be used.
|
||||
* @return the final converts list to use
|
||||
*/
|
||||
protected List<HttpMessageConverter<?>> postProcessPartConverters(List<HttpMessageConverter<?>> converters) {
|
||||
return converters;
|
||||
}
|
||||
|
||||
private List<HttpMessageConverter<?>> getDefaultConverters() {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
if (ClassUtils.isPresent("org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport",
|
||||
null)) {
|
||||
converters.addAll(new WebMvcConfigurationSupport() {
|
||||
|
||||
public List<HttpMessageConverter<?>> defaultMessageConverters() {
|
||||
return super.getMessageConverters();
|
||||
}
|
||||
|
||||
}.defaultMessageConverters());
|
||||
}
|
||||
else {
|
||||
converters.addAll(new RestTemplate().getMessageConverters());
|
||||
}
|
||||
reorderXmlConvertersToEnd(converters);
|
||||
return converters;
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private void reorderXmlConvertersToEnd(List<HttpMessageConverter<?>> converters) {
|
||||
List<HttpMessageConverter<?>> xml = new ArrayList<>();
|
||||
for (Iterator<HttpMessageConverter<?>> iterator = converters.iterator(); iterator.hasNext();) {
|
||||
HttpMessageConverter<?> converter = iterator.next();
|
||||
if ((converter instanceof AbstractXmlHttpMessageConverter)
|
||||
|| (converter instanceof org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)) {
|
||||
xml.add(converter);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
converters.addAll(xml);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<HttpMessageConverter<?>> iterator() {
|
||||
return getConverters().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an immutable list of the converters in the order that they will be
|
||||
* registered.
|
||||
* @return the converters
|
||||
*/
|
||||
public List<HttpMessageConverter<?>> getConverters() {
|
||||
return this.converters;
|
||||
}
|
||||
|
||||
private static void addClassIfExists(List<Class<?>> list, String className) {
|
||||
try {
|
||||
list.add(Class.forName(className));
|
||||
}
|
||||
catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
private static void putIfExists(MultiValueMap<Class<?>, Class<?>> map, String keyClassName,
|
||||
String... valueClassNames) {
|
||||
for (String valueClassName : valueClassNames) {
|
||||
try {
|
||||
map.add(Class.forName(keyClassName), Class.forName(valueClassName));
|
||||
}
|
||||
catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+2
-8
@@ -69,22 +69,16 @@ public final class HttpMessageConvertersAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
@SuppressWarnings("deprecation")
|
||||
ClientHttpMessageConvertersCustomizer clientConvertersCustomizer(
|
||||
ObjectProvider<HttpMessageConverters> legacyConverters,
|
||||
ObjectProvider<HttpMessageConverter<?>> converters) {
|
||||
return new DefaultClientHttpMessageConvertersCustomizer(legacyConverters.getIfAvailable(),
|
||||
converters.orderedStream().toList());
|
||||
return new DefaultClientHttpMessageConvertersCustomizer(converters.orderedStream().toList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
@SuppressWarnings("deprecation")
|
||||
ServerHttpMessageConvertersCustomizer serverConvertersCustomizer(
|
||||
ObjectProvider<HttpMessageConverters> legacyConverters,
|
||||
ObjectProvider<HttpMessageConverter<?>> converters) {
|
||||
return new DefaultServerHttpMessageConvertersCustomizer(legacyConverters.getIfAvailable(),
|
||||
converters.orderedStream().toList());
|
||||
return new DefaultServerHttpMessageConvertersCustomizer(converters.orderedStream().toList());
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
-192
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.boot.http.converter.autoconfigure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.ResourceHttpMessageConverter;
|
||||
import org.springframework.http.converter.ResourceRegionHttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.cbor.JacksonCborHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.GsonHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.JacksonXmlHttpMessageConverter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpMessageConverters}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class HttpMessageConvertersTests {
|
||||
|
||||
@Test
|
||||
void containsDefaults() {
|
||||
HttpMessageConverters converters = new HttpMessageConverters();
|
||||
List<Class<?>> converterClasses = new ArrayList<>();
|
||||
for (HttpMessageConverter<?> converter : converters) {
|
||||
converterClasses.add(converter.getClass());
|
||||
}
|
||||
assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class,
|
||||
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
|
||||
ResourceRegionHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class,
|
||||
KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class,
|
||||
JacksonCborHttpMessageConverter.class, JacksonXmlHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addBeforeExistingConverter() {
|
||||
JacksonJsonHttpMessageConverter converter1 = new JacksonJsonHttpMessageConverter();
|
||||
JacksonJsonHttpMessageConverter converter2 = new JacksonJsonHttpMessageConverter();
|
||||
HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2);
|
||||
assertThat(converters.getConverters()).contains(converter1);
|
||||
assertThat(converters.getConverters()).contains(converter2);
|
||||
List<JacksonJsonHttpMessageConverter> httpConverters = new ArrayList<>();
|
||||
for (HttpMessageConverter<?> candidate : converters) {
|
||||
if (candidate instanceof JacksonJsonHttpMessageConverter jsonConverter) {
|
||||
httpConverters.add(jsonConverter);
|
||||
}
|
||||
}
|
||||
// The existing converter is still there, but with a lower priority
|
||||
assertThat(httpConverters).hasSize(3);
|
||||
assertThat(httpConverters.indexOf(converter1)).isZero();
|
||||
assertThat(httpConverters.indexOf(converter2)).isOne();
|
||||
assertThat(converters.getConverters().indexOf(converter1)).isNotZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void addBeforeExistingEquivalentConverter() {
|
||||
GsonHttpMessageConverter converter1 = new GsonHttpMessageConverter();
|
||||
HttpMessageConverters converters = new HttpMessageConverters(converter1);
|
||||
Stream<Class<?>> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass);
|
||||
assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class,
|
||||
GsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addBeforeExistingAnotherEquivalentConverter() {
|
||||
KotlinSerializationJsonHttpMessageConverter converter1 = new KotlinSerializationJsonHttpMessageConverter();
|
||||
HttpMessageConverters converters = new HttpMessageConverters(converter1);
|
||||
Stream<Class<?>> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass);
|
||||
assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class,
|
||||
JacksonJsonHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addBeforeExistingMultipleEquivalentConverters() {
|
||||
GsonHttpMessageConverter converter1 = new GsonHttpMessageConverter();
|
||||
KotlinSerializationJsonHttpMessageConverter converter2 = new KotlinSerializationJsonHttpMessageConverter();
|
||||
HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2);
|
||||
Stream<Class<?>> converterClasses = converters.getConverters().stream().map(HttpMessageConverter::getClass);
|
||||
assertThat(converterClasses).containsSequence(KotlinSerializationJsonHttpMessageConverter.class,
|
||||
GsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addNewConverters() {
|
||||
HttpMessageConverter<?> converter1 = mock(HttpMessageConverter.class);
|
||||
HttpMessageConverter<?> converter2 = mock(HttpMessageConverter.class);
|
||||
HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2);
|
||||
assertThat(converters.getConverters().get(0)).isEqualTo(converter1);
|
||||
assertThat(converters.getConverters().get(1)).isEqualTo(converter2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertersAreAddedToFormPartConverter() {
|
||||
HttpMessageConverter<?> converter1 = mock(HttpMessageConverter.class);
|
||||
HttpMessageConverter<?> converter2 = mock(HttpMessageConverter.class);
|
||||
List<HttpMessageConverter<?>> converters = new HttpMessageConverters(converter1, converter2).getConverters();
|
||||
List<HttpMessageConverter<?>> partConverters = extractFormPartConverters(converters);
|
||||
assertThat(partConverters.get(0)).isEqualTo(converter1);
|
||||
assertThat(partConverters.get(1)).isEqualTo(converter2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void postProcessConverters() {
|
||||
HttpMessageConverters converters = new HttpMessageConverters() {
|
||||
|
||||
@Override
|
||||
protected List<HttpMessageConverter<?>> postProcessConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.removeIf(JacksonXmlHttpMessageConverter.class::isInstance);
|
||||
return converters;
|
||||
}
|
||||
|
||||
};
|
||||
List<Class<?>> converterClasses = new ArrayList<>();
|
||||
for (HttpMessageConverter<?> converter : converters) {
|
||||
converterClasses.add(converter.getClass());
|
||||
}
|
||||
assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class,
|
||||
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
|
||||
ResourceRegionHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class,
|
||||
KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class,
|
||||
JacksonCborHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void postProcessPartConverters() {
|
||||
HttpMessageConverters converters = new HttpMessageConverters() {
|
||||
|
||||
@Override
|
||||
protected List<HttpMessageConverter<?>> postProcessPartConverters(
|
||||
List<HttpMessageConverter<?>> converters) {
|
||||
converters.removeIf(JacksonXmlHttpMessageConverter.class::isInstance);
|
||||
return converters;
|
||||
}
|
||||
|
||||
};
|
||||
List<Class<?>> converterClasses = new ArrayList<>();
|
||||
for (HttpMessageConverter<?> converter : extractFormPartConverters(converters.getConverters())) {
|
||||
converterClasses.add(converter.getClass());
|
||||
}
|
||||
assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class,
|
||||
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
|
||||
KotlinSerializationJsonHttpMessageConverter.class, JacksonJsonHttpMessageConverter.class,
|
||||
JacksonCborHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
private List<HttpMessageConverter<?>> extractFormPartConverters(List<HttpMessageConverter<?>> converters) {
|
||||
AllEncompassingFormHttpMessageConverter formConverter = findFormConverter(converters);
|
||||
assertThat(formConverter).isNotNull();
|
||||
return formConverter.getPartConverters();
|
||||
}
|
||||
|
||||
private @Nullable AllEncompassingFormHttpMessageConverter findFormConverter(
|
||||
Collection<HttpMessageConverter<?>> converters) {
|
||||
for (HttpMessageConverter<?> converter : converters) {
|
||||
if (converter instanceof AllEncompassingFormHttpMessageConverter allEncompassingConverter) {
|
||||
return allEncompassingConverter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
-9
@@ -27,15 +27,6 @@ import org.springframework.context.SmartLifecycle;
|
||||
*/
|
||||
public final class WebServerGracefulShutdownLifecycle implements SmartLifecycle {
|
||||
|
||||
/**
|
||||
* {@link SmartLifecycle#getPhase() SmartLifecycle phase} in which graceful shutdown
|
||||
* of the web server is performed.
|
||||
* @deprecated as of 4.0.0 in favor of
|
||||
* {@link WebServerApplicationContext#GRACEFUL_SHUTDOWN_PHASE}
|
||||
*/
|
||||
@Deprecated(since = "4.0.0", forRemoval = true)
|
||||
public static final int SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024;
|
||||
|
||||
private final WebServer webServer;
|
||||
|
||||
private volatile boolean running;
|
||||
|
||||
Reference in New Issue
Block a user