Update MockRestServiceServer bufferContent

Connect the existing bufferContent option to the new RestClient and
RestTemplate equivalent feature.

See gh-33785
This commit is contained in:
rstoyanchev
2025-01-10 14:39:11 +00:00
parent 39bb751546
commit 2561a60968

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -244,6 +244,10 @@ public final class MockRestServiceServer {
return this;
}
protected boolean shouldBufferContent() {
return this.bufferContent;
}
@Override
public MockRestServiceServer build() {
if (this.ignoreExpectOrder) {
@@ -258,9 +262,6 @@ public final class MockRestServiceServer {
public MockRestServiceServer build(RequestExpectationManager manager) {
MockRestServiceServer server = new MockRestServiceServer(manager);
ClientHttpRequestFactory factory = server.new MockClientHttpRequestFactory();
if (this.bufferContent) {
factory = new BufferingClientHttpRequestFactory(factory);
}
injectRequestFactory(factory);
return server;
}
@@ -281,6 +282,9 @@ public final class MockRestServiceServer {
@Override
protected void injectRequestFactory(ClientHttpRequestFactory requestFactory) {
if (shouldBufferContent()) {
this.restClientBuilder.bufferContent((uri, httpMethod) -> true);
}
this.restClientBuilder.requestFactory(requestFactory);
}
}
@@ -297,6 +301,9 @@ public final class MockRestServiceServer {
@Override
protected void injectRequestFactory(ClientHttpRequestFactory requestFactory) {
if (shouldBufferContent()) {
this.restTemplate.setBufferingPredicate((uri, httpMethod) -> true);
}
this.restTemplate.setRequestFactory(requestFactory);
}
}