Upgrade to Spring Framework 6.1.0-M1

Closes gh-35977
Closes gh-35980
pull/35986/head
Andy Wilkinson 1 year ago
parent 4dc0b26eea
commit ca5bd37e81

@ -14,15 +14,10 @@ new File(new File("$projectDir").parentFile, "gradle.properties").withInputStrea
def properties = new Properties()
properties.load(it)
ext.set("kotlinVersion", properties["kotlinVersion"])
ext.set("springFrameworkVersion", properties["springFrameworkVersion"])
if (properties["springFrameworkVersion"].contains("-")) {
repositories {
maven { url "https://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/snapshot" }
}
}
}
ext.set("springFrameworkVersion", "6.0.10")
sourceCompatibility = 17
targetCompatibility = 17

@ -6,7 +6,7 @@ org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
kotlinVersion=1.8.22
nativeBuildToolsVersion=0.9.23
springFrameworkVersion=6.0.10
springFrameworkVersion=6.1.0-M1
tomcatVersion=10.1.10
kotlin.stdlib.default.dependency=false

@ -28,6 +28,7 @@ import org.springframework.web.filter.reactive.ServerHttpObservationFilter;
*
* @author Moritz Halbritter
*/
@SuppressWarnings({ "deprecation", "removal" })
class OrderedServerHttpObservationFilter extends ServerHttpObservationFilter implements OrderedWebFilter {
private final int order;

@ -1021,9 +1021,6 @@ public class TestRestTemplate {
if (settings.connectTimeout() != null) {
setConnectTimeout((int) settings.connectTimeout().toMillis());
}
if (settings.bufferRequestBody() != null) {
setBufferRequestBody(settings.bufferRequestBody());
}
}
private HttpClient createHttpClient(Duration readTimeout, boolean ssl) {

@ -255,7 +255,7 @@ class SpringBootContextLoaderTests {
private Map<String, Object> getMergedContextConfigurationProperties(Class<?> testClass) {
TestContext context = new ExposedTestContextManager(testClass).getExposedTestContext();
MergedContextConfiguration config = (MergedContextConfiguration) ReflectionTestUtils.getField(context,
"mergedContextConfiguration");
"mergedConfig");
return TestPropertySourceUtils.convertInlinedPropertiesToMap(config.getPropertySourceProperties());
}

@ -110,7 +110,7 @@ class SpringBootTestContextBootstrapperTests {
}
private MergedContextConfiguration getMergedContextConfiguration(TestContext context) {
return (MergedContextConfiguration) ReflectionTestUtils.getField(context, "mergedContextConfiguration");
return (MergedContextConfiguration) ReflectionTestUtils.getField(context, "mergedConfig");
}
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)

@ -14,6 +14,11 @@ configurations.all {
if (dependency.requested.group.startsWith("com.fasterxml.jackson")) {
dependency.useVersion("2.14.2")
}
// Downgrade Spring Framework as Gradle cannot cope with 6.1.0-M1's
// multi-version jar files with bytecode in META-INF/versions/21
if (dependency.requested.group.equals("org.springframework")) {
dependency.useVersion("6.0.10")
}
}
}
}

@ -23,6 +23,11 @@ configurations {
if (dependency.requested.group.startsWith("com.fasterxml.jackson")) {
dependency.useVersion("2.14.2")
}
// Downgrade Spring Framework as Gradle cannot cope with 6.1.0-M1's
// multi-version jar files with bytecode in META-INF/versions/21
if (dependency.requested.group.equals("org.springframework")) {
dependency.useVersion("6.0.10")
}
}
}
}

@ -17,6 +17,17 @@ configurations {
extendsFrom dependencyManagement
transitive = false
}
all {
resolutionStrategy {
eachDependency { dependency ->
// Downgrade Spring Framework as Gradle cannot cope with 6.1.0-M1's
// multi-version jar files with bytecode in META-INF/versions/21
if (dependency.requested.group.equals("org.springframework")) {
dependency.useVersion("6.0.10")
}
}
}
}
}
dependencies {

@ -151,7 +151,6 @@ public final class ClientHttpRequestFactories {
settings.sslBundle());
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(settings::connectTimeout).asInt(Duration::toMillis).to(requestFactory::setConnectTimeout);
map.from(settings::bufferRequestBody).to(requestFactory::setBufferRequestBody);
return requestFactory;
}
@ -187,8 +186,6 @@ public final class ClientHttpRequestFactories {
static class OkHttp {
static OkHttp3ClientHttpRequestFactory get(ClientHttpRequestFactorySettings settings) {
Assert.state(settings.bufferRequestBody() == null,
() -> "OkHttp3ClientHttpRequestFactory does not support request body buffering");
OkHttp3ClientHttpRequestFactory requestFactory = createRequestFactory(settings.sslBundle());
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(settings::connectTimeout).asInt(Duration::toMillis).to(requestFactory::setConnectTimeout);
@ -227,7 +224,6 @@ public final class ClientHttpRequestFactories {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(settings::readTimeout).asInt(Duration::toMillis).to(requestFactory::setReadTimeout);
map.from(settings::connectTimeout).asInt(Duration::toMillis).to(requestFactory::setConnectTimeout);
map.from(settings::bufferRequestBody).to(requestFactory::setBufferRequestBody);
return requestFactory;
}
@ -274,8 +270,6 @@ public final class ClientHttpRequestFactories {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(settings::connectTimeout).to((connectTimeout) -> setConnectTimeout(unwrapped, connectTimeout));
map.from(settings::readTimeout).to((readTimeout) -> setReadTimeout(unwrapped, readTimeout));
map.from(settings::bufferRequestBody)
.to((bufferRequestBody) -> setBufferRequestBody(unwrapped, bufferRequestBody));
}
private static ClientHttpRequestFactory unwrapRequestFactoryIfNecessary(
@ -305,11 +299,6 @@ public final class ClientHttpRequestFactories {
invoke(factory, method, timeout);
}
private static void setBufferRequestBody(ClientHttpRequestFactory factory, boolean bufferRequestBody) {
Method method = findMethod(factory, "setBufferRequestBody", boolean.class);
invoke(factory, method, bufferRequestBody);
}
private static Method findMethod(ClientHttpRequestFactory requestFactory, String methodName,
Class<?>... parameters) {
Method method = ReflectionUtils.findMethod(requestFactory.getClass(), methodName, parameters);

@ -69,7 +69,6 @@ class ClientHttpRequestFactoriesRuntimeHints implements RuntimeHintsRegistrar {
Class<? extends ClientHttpRequestFactory> requestFactoryType) {
registerMethod(hints, requestFactoryType, "setConnectTimeout", int.class);
registerMethod(hints, requestFactoryType, "setReadTimeout", int.class);
registerMethod(hints, requestFactoryType, "setBufferRequestBody", boolean.class);
}
private void registerMethod(ReflectionHints hints, Class<? extends ClientHttpRequestFactory> requestFactoryType,

@ -26,7 +26,6 @@ import org.springframework.http.client.ClientHttpRequestFactory;
*
* @param connectTimeout the connect timeout
* @param readTimeout the read timeout
* @param bufferRequestBody if request body buffering is used
* @param sslBundle the SSL bundle providing SSL configuration
* @author Andy Wilkinson
* @author Phillip Webb
@ -34,8 +33,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
* @since 3.0.0
* @see ClientHttpRequestFactories
*/
public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody,
SslBundle sslBundle) {
public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, SslBundle sslBundle) {
/**
* Use defaults for the {@link ClientHttpRequestFactory} which can differ depending on
@ -48,15 +46,29 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
* Create a new {@link ClientHttpRequestFactorySettings} instance.
* @param connectTimeout the connection timeout
* @param readTimeout the read timeout
* @param bufferRequestBody the bugger request body
* @param sslBundle the ssl bundle
* @since 3.1.0
* @param bufferRequestBody if request body buffering is used
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
* removed in Spring Framework 6.1
*/
public ClientHttpRequestFactorySettings {
@Deprecated(since = "3.2.0", forRemoval = true)
public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody) {
this(connectTimeout, readTimeout, (SslBundle) null);
}
public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody) {
this(connectTimeout, readTimeout, bufferRequestBody, null);
/**
* Create a new {@link ClientHttpRequestFactorySettings} instance.
* @param connectTimeout the connection timeout
* @param readTimeout the read timeout
* @param bufferRequestBody if request body buffering is used
* @param sslBundle the ssl bundle
* @since 3.1.0
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
* removed in Spring Framework 6.1
*/
@Deprecated(since = "3.2.0", forRemoval = true)
public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody,
SslBundle sslBundle) {
this(connectTimeout, readTimeout, sslBundle);
}
/**
@ -66,8 +78,7 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
* @return a new {@link ClientHttpRequestFactorySettings} instance
*/
public ClientHttpRequestFactorySettings withConnectTimeout(Duration connectTimeout) {
return new ClientHttpRequestFactorySettings(connectTimeout, this.readTimeout, this.bufferRequestBody,
this.sslBundle);
return new ClientHttpRequestFactorySettings(connectTimeout, this.readTimeout, this.sslBundle);
}
/**
@ -78,19 +89,19 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
*/
public ClientHttpRequestFactorySettings withReadTimeout(Duration readTimeout) {
return new ClientHttpRequestFactorySettings(this.connectTimeout, readTimeout, this.bufferRequestBody,
this.sslBundle);
return new ClientHttpRequestFactorySettings(this.connectTimeout, readTimeout, this.sslBundle);
}
/**
* Return a new {@link ClientHttpRequestFactorySettings} instance with an updated
* buffer request body setting.
* Has no effect as support for buffering has been removed in Spring Framework 6.1.
* @param bufferRequestBody the new buffer request body setting
* @return a new {@link ClientHttpRequestFactorySettings} instance
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
* removed in Spring Framework 6.1
*/
@Deprecated(since = "3.2.0", forRemoval = true)
public ClientHttpRequestFactorySettings withBufferRequestBody(Boolean bufferRequestBody) {
return new ClientHttpRequestFactorySettings(this.connectTimeout, this.readTimeout, bufferRequestBody,
this.sslBundle);
return this;
}
/**
@ -101,8 +112,18 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
* @since 3.1.0
*/
public ClientHttpRequestFactorySettings withSslBundle(SslBundle sslBundle) {
return new ClientHttpRequestFactorySettings(this.connectTimeout, this.readTimeout, this.bufferRequestBody,
sslBundle);
return new ClientHttpRequestFactorySettings(this.connectTimeout, this.readTimeout, sslBundle);
}
/**
* Returns whether request body buffering is used.
* @return whether request body buffering is used
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
* removed in Spring Framework 6.1
*/
@Deprecated(since = "3.2.0", forRemoval = true)
public Boolean bufferRequestBody() {
return null;
}
}

@ -440,19 +440,18 @@ public class RestTemplateBuilder {
}
/**
* Sets if the underlying {@link ClientHttpRequestFactory} should buffer the
* {@linkplain ClientHttpRequest#getBody() request body} internally.
* Has no effect as support for buffering has been removed in Spring Framework 6.1.
* @param bufferRequestBody value of the bufferRequestBody parameter
* @return a new builder instance.
* @since 2.2.0
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
* removed in Spring Framework 6.1
* @see SimpleClientHttpRequestFactory#setBufferRequestBody(boolean)
* @see HttpComponentsClientHttpRequestFactory#setBufferRequestBody(boolean)
*/
@Deprecated(since = "3.2.0", forRemoval = true)
public RestTemplateBuilder setBufferRequestBody(boolean bufferRequestBody) {
return new RestTemplateBuilder(this.requestFactorySettings.withBufferRequestBody(bufferRequestBody),
this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory,
this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders,
this.customizers, this.requestCustomizers);
return this;
}
/**

@ -113,7 +113,7 @@ public class HttpWebServiceMessageSenderBuilder {
private ClientHttpRequestFactory getRequestFactory() {
ClientHttpRequestFactorySettings settings = new ClientHttpRequestFactorySettings(this.connectTimeout,
this.readTimeout, null, this.sslBundle);
this.readTimeout, this.sslBundle);
return (this.requestFactory != null) ? this.requestFactory.apply(settings)
: ClientHttpRequestFactories.get(settings);
}

@ -27,7 +27,6 @@ import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link ClientHttpRequestFactories} when OkHttp 3 is the predominant HTTP
@ -50,12 +49,6 @@ class ClientHttpRequestFactoriesOkHttp3Tests
.startsWith("okhttp-3.");
}
@Test
void getFailsWhenBufferRequestBodyIsEnabled() {
assertThatIllegalStateException().isThrownBy(() -> ClientHttpRequestFactories
.get(ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(true)));
}
@Override
protected long connectTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).connectTimeoutMillis();

@ -26,7 +26,6 @@ import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link ClientHttpRequestFactories} when OkHttp 4 is the predominant HTTP
@ -48,12 +47,6 @@ class ClientHttpRequestFactoriesOkHttp4Tests
.startsWith("okhttp-4.");
}
@Test
void getFailsWhenBufferRequestBodyIsEnabled() {
assertThatIllegalStateException().isThrownBy(() -> ClientHttpRequestFactories
.get(ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(true)));
}
@Override
protected long connectTimeout(OkHttp3ClientHttpRequestFactory requestFactory) {
return ((OkHttpClient) ReflectionTestUtils.getField(requestFactory, "client")).connectTimeoutMillis();

@ -59,12 +59,6 @@ class ClientHttpRequestFactoriesRuntimeHintsTests {
assertThat(reflection
.onMethod(method(HttpComponentsClientHttpRequestFactory.class, "setConnectTimeout", int.class)))
.accepts(hints);
assertThat(
reflection.onMethod(method(HttpComponentsClientHttpRequestFactory.class, "setReadTimeout", int.class)))
.accepts(hints);
assertThat(reflection
.onMethod(method(HttpComponentsClientHttpRequestFactory.class, "setBufferRequestBody", boolean.class)))
.accepts(hints);
}
@Test
@ -88,9 +82,6 @@ class ClientHttpRequestFactoriesRuntimeHintsTests {
.accepts(hints);
assertThat(reflection.onMethod(method(SimpleClientHttpRequestFactory.class, "setReadTimeout", int.class)))
.accepts(hints);
assertThat(reflection
.onMethod(method(SimpleClientHttpRequestFactory.class, "setBufferRequestBody", boolean.class)))
.accepts(hints);
}
private static Method method(Class<?> target, String name, Class<?>... parameterTypes) {

@ -100,14 +100,6 @@ class ClientHttpRequestFactoriesTests {
.isEqualTo(Duration.ofSeconds(90).toMillis());
}
@Test
void getOfUnknownTypeWithBodyBufferingCreatesFactoryAndConfiguresBodyBuffering() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(TestClientHttpRequestFactory.class,
ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(true));
assertThat(requestFactory).isInstanceOf(TestClientHttpRequestFactory.class);
assertThat(((TestClientHttpRequestFactory) requestFactory).bufferRequestBody).isTrue();
}
@Test
void getOfUnconfigurableTypeWithConnectTimeoutThrows() {
assertThatIllegalStateException()
@ -124,14 +116,6 @@ class ClientHttpRequestFactoriesTests {
.withMessageContaining("suitable setReadTimeout method");
}
@Test
void getOfUnconfigurableTypeWithBodyBufferingThrows() {
assertThatIllegalStateException()
.isThrownBy(() -> ClientHttpRequestFactories.get(UnconfigurableClientHttpRequestFactory.class,
ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(true)))
.withMessageContaining("suitable setBufferRequestBody method");
}
@Test
void getOfTypeWithDeprecatedConnectTimeoutThrowsWithConnectTimeout() {
assertThatIllegalStateException()
@ -148,14 +132,6 @@ class ClientHttpRequestFactoriesTests {
.withMessageContaining("setReadTimeout method marked as deprecated");
}
@Test
void getOfTypeWithDeprecatedBufferRequestBodyThrowsWithBufferRequestBody() {
assertThatIllegalStateException()
.isThrownBy(() -> ClientHttpRequestFactories.get(DeprecatedMethodsClientHttpRequestFactory.class,
ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(false)))
.withMessageContaining("setBufferRequestBody method marked as deprecated");
}
@Test
void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
@ -176,25 +152,12 @@ class ClientHttpRequestFactoriesTests {
assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 1234);
}
@Test
void bufferRequestBodyCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
BufferingClientHttpRequestFactory result = ClientHttpRequestFactories.get(
() -> new BufferingClientHttpRequestFactory(requestFactory),
ClientHttpRequestFactorySettings.DEFAULTS.withBufferRequestBody(false));
assertThat(result).extracting("requestFactory").isSameAs(requestFactory);
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", false);
}
public static class TestClientHttpRequestFactory implements ClientHttpRequestFactory {
private int connectTimeout;
private int readTimeout;
private boolean bufferRequestBody;
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
throw new UnsupportedOperationException();
@ -208,10 +171,6 @@ class ClientHttpRequestFactoriesTests {
this.readTimeout = timeout;
}
public void setBufferRequestBody(boolean bufferRequestBody) {
this.bufferRequestBody = bufferRequestBody;
}
}
public static class UnconfigurableClientHttpRequestFactory implements ClientHttpRequestFactory {

@ -39,7 +39,6 @@ class ClientHttpRequestFactorySettingsTests {
ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS;
assertThat(settings.connectTimeout()).isNull();
assertThat(settings.readTimeout()).isNull();
assertThat(settings.bufferRequestBody()).isNull();
assertThat(settings.sslBundle()).isNull();
}
@ -49,7 +48,6 @@ class ClientHttpRequestFactorySettingsTests {
.withConnectTimeout(ONE_SECOND);
assertThat(settings.connectTimeout()).isEqualTo(ONE_SECOND);
assertThat(settings.readTimeout()).isNull();
assertThat(settings.bufferRequestBody()).isNull();
assertThat(settings.sslBundle()).isNull();
}
@ -59,17 +57,6 @@ class ClientHttpRequestFactorySettingsTests {
.withReadTimeout(ONE_SECOND);
assertThat(settings.connectTimeout()).isNull();
assertThat(settings.readTimeout()).isEqualTo(ONE_SECOND);
assertThat(settings.bufferRequestBody()).isNull();
assertThat(settings.sslBundle()).isNull();
}
@Test
void withBufferRequestBodyReturnsInstanceWithUpdatedBufferRequestBody() {
ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS
.withBufferRequestBody(true);
assertThat(settings.connectTimeout()).isNull();
assertThat(settings.readTimeout()).isNull();
assertThat(settings.bufferRequestBody()).isTrue();
assertThat(settings.sslBundle()).isNull();
}
@ -79,7 +66,6 @@ class ClientHttpRequestFactorySettingsTests {
ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS.withSslBundle(sslBundle);
assertThat(settings.connectTimeout()).isNull();
assertThat(settings.readTimeout()).isNull();
assertThat(settings.bufferRequestBody()).isNull();
assertThat(settings.sslBundle()).isSameAs(sslBundle);
}

@ -19,6 +19,11 @@ configurations {
if (dependency.requested.group.startsWith("com.fasterxml.jackson")) {
dependency.useVersion("2.14.2")
}
// Downgrade Spring Framework as Gradle cannot cope with 6.1.0-M1's
// multi-version jar files with bytecode in META-INF/versions/21
if (dependency.requested.group.equals("org.springframework")) {
dependency.useVersion("6.0.10")
}
}
}
}

Loading…
Cancel
Save