ReactiveElasticsearchOperations indexName is encoded twice.

Original Pull Request #1666 
Closes #1665
This commit is contained in:
Peter-Josef Meisch 2021-01-25 21:33:25 +01:00 committed by GitHub
parent 1a02c1e05a
commit 4829b07e53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.Builder;
import org.springframework.web.util.DefaultUriBuilderFactory;
/**
* Default {@link WebClientProvider} that uses cached {@link WebClient} instances per {@code hostAndPort}.
@ -155,8 +156,13 @@ class DefaultWebClientProvider implements WebClientProvider {
String baseUrl = String.format("%s://%s:%d%s", this.scheme, socketAddress.getHostString(), socketAddress.getPort(),
pathPrefix == null ? "" : '/' + pathPrefix);
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(baseUrl);
// the template will already be encoded by the RequestConverters methods
uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
builder.uriBuilderFactory(uriBuilderFactory); //
WebClient webClient = builder //
.baseUrl(baseUrl) //
.filter((request, next) -> next.exchange(request) //
.doOnError(errorListener)) //
.build(); //

View File

@ -32,6 +32,8 @@ import java.lang.Boolean;
import java.lang.Long;
import java.lang.Object;
import java.net.ConnectException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -1031,6 +1033,32 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
assertThat(searchHits.getSearchHits().size()).isEqualTo(5);
}).verifyComplete();
}
@Test // #1665
@DisplayName("should be able to process date-math-index names")
void shouldBeAbleToProcessDateMathIndexNames() {
String indexName = "foo-" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy.MM"));
String dateMathIndexName = "<foo-{now/M{yyyy.MM}}>";
template.indexOps(IndexCoordinates.of(dateMathIndexName)) //
.create() //
.as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete(); //
template.indexOps(IndexCoordinates.of(indexName)) //
.exists() //
.as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete(); //
template.indexOps(IndexCoordinates.of(dateMathIndexName)) //
.delete() //
.as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete(); //
}
// endregion
// region Helper functions
@ -1128,5 +1156,6 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
@Id private String id;
@Version private Long version;
}
// endregion
}