Skip to content

Commit

Permalink
MAT-7471: Disable auto-encode on FhirTerminologyServiceWebClient with…
Browse files Browse the repository at this point in the history
… a custom UriBuilderFactory.

Our config of the `FhirTerminologyServiceWebClient` enabled auto-encoding of String uri values by setting the `WebClient.Builder baseUrl()`. Effectively a shortcut to use the default `UriBuilderFactory`, which encodes uri Strings by default.

When a URI object is passed to the WebClient request chain, the `UriBuilderFactory` is not used. Instead, the WebClient uses the supplied URI as is, which also means it doesn't use baseUrl configured on the WebClient builder as the underlying UriBuilderFactory is also not used.

See: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/function/client/WebClient.Builder.html#baseUrl(java.lang.String)

See: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/DefaultUriBuilderFactory.html#setEncodingMode(org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode)
  • Loading branch information
jkotanchik-SB committed Jul 16, 2024
1 parent 63624f4 commit 9fee360
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ public ValueSetSearchResult searchValueSets(String apiKey, Map<String, String> q
}
log.info("valueSetList {}", valueSetList);
});
return ValueSetSearchResult.builder().valueSets(valueSetList).resultBundle(responseString).build();
return ValueSetSearchResult.builder()
.valueSets(valueSetList)
.resultBundle(responseString)
.build();
}

public List<CodeSystem> getAllCodeSystems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -42,9 +43,12 @@ public FhirTerminologyServiceWebClient(
@Value("${client.fhir-terminology-service.code-lookups}") String codeLookupsUrl,
@Value("${client.default_profile}") String defaultProfile,
@Value("${client.search_value_set_endpoint}") String searchValueSetEndpoint) {
DefaultUriBuilderFactory uriBuilderFactory =
new DefaultUriBuilderFactory(fhirTerminologyServiceBaseUrl);
uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
fhirTerminologyWebClient =
WebClient.builder()
.baseUrl(fhirTerminologyServiceBaseUrl)
.uriBuilderFactory(uriBuilderFactory)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.codecs(
clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs().maxInMemorySize(-1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ void testSearchValueSets() {
Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn(TEST_USER);
when(vsacService.verifyUmlsAccess(anyString())).thenReturn(umlsUser);
when(fhirTerminologyService.searchValueSets(any(), any())).thenReturn(ValueSetSearchResult.builder().valueSets(mockValueSets).build());
when(fhirTerminologyService.searchValueSets(any(), any()))
.thenReturn(ValueSetSearchResult.builder().valueSets(mockValueSets).build());
Map<String, String> queryParams = new HashMap<>();
queryParams.put("param1", "value1");
queryParams.put("param2", "value2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientResponseException;
Expand All @@ -31,7 +30,7 @@ class FhirTerminologyServiceWebClientTest {

private ValueSetsSearchCriteria.ValueSetParams testValueSetParams;

@InjectMocks FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient;
FhirTerminologyServiceWebClient fhirTerminologyServiceWebClient;

@BeforeAll
static void setUp() throws IOException {
Expand Down

0 comments on commit 9fee360

Please sign in to comment.