Skip to content

Commit

Permalink
Upgrade to Spring Framework 6.1.0-M1
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jun 19, 2023
1 parent 4dc0b26 commit ca5bd37
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 129 deletions.
9 changes: 2 additions & 7 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author Moritz Halbritter
*/
@SuppressWarnings({ "deprecation", "removal" })
class OrderedServerHttpObservationFilter extends ServerHttpObservationFilter implements OrderedWebFilter {

private final int order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,6 @@ public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClien
if (settings.connectTimeout() != null) {
setConnectTimeout((int) settings.connectTimeout().toMillis());
}
if (settings.bufferRequestBody() != null) {
setBufferRequestBody(settings.bufferRequestBody());
}
}

private HttpClient createHttpClient(Duration readTimeout, boolean ssl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private String[] getActiveProfiles(Class<?> testClass) {
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private TestContext buildTestContext(Class<?> testClass) {
}

private MergedContextConfiguration getMergedContextConfiguration(TestContext context) {
return (MergedContextConfiguration) ReflectionTestUtils.getField(context, "mergedContextConfiguration");
return (MergedContextConfiguration) ReflectionTestUtils.getField(context, "mergedConfig");
}

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ static HttpComponentsClientHttpRequestFactory get(ClientHttpRequestFactorySettin
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;
}

Expand Down Expand Up @@ -187,8 +186,6 @@ private static HttpClient createHttpClient(Duration readTimeout, SslBundle sslBu
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);
Expand Down Expand Up @@ -227,7 +224,6 @@ static SimpleClientHttpRequestFactory get(ClientHttpRequestFactorySettings setti
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;
}

Expand Down Expand Up @@ -274,8 +270,6 @@ private static void configure(ClientHttpRequestFactory requestFactory,
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(
Expand Down Expand Up @@ -305,11 +299,6 @@ private static void setReadTimeout(ClientHttpRequestFactory factory, Duration re
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private void registerReflectionHints(ReflectionHints hints,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
*
* @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
* @author Scott Frederick
* @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
Expand All @@ -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);
}

/**
Expand All @@ -66,8 +78,7 @@ public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTi
* @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);
}

/**
Expand All @@ -78,19 +89,19 @@ public ClientHttpRequestFactorySettings withConnectTimeout(Duration connectTimeo
*/

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;
}

/**
Expand All @@ -101,8 +112,18 @@ public ClientHttpRequestFactorySettings withBufferRequestBody(Boolean bufferRequ
* @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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,18 @@ public RestTemplateBuilder setReadTimeout(Duration readTimeout) {
}

/**
* 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public WebServiceMessageSender build() {

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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
Expand All @@ -50,12 +49,6 @@ void okHttp3IsBeingUsed() {
.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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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
Expand All @@ -48,12 +47,6 @@ void okHttp4IsBeingUsed() {
.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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ void shouldRegisterHttpComponentHints() {
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
Expand All @@ -88,9 +82,6 @@ void shouldRegisterSimpleHttpHints() {
.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) {
Expand Down
Loading

0 comments on commit ca5bd37

Please sign in to comment.