diff options
| author | Paul-Christian Volkmer | 2025-11-07 09:58:37 +0100 |
|---|---|---|
| committer | Paul-Christian Volkmer | 2025-11-07 10:50:47 +0100 |
| commit | ee85f58aad5543eceaf88810e94d94d7e2f92bc5 (patch) | |
| tree | a2648df6680a4e638753eed115af22d0c4dbb941 /src | |
| parent | ae3c9b8a9d9bfb0e2436f4964baaee430e6071d5 (diff) | |
fix: use ..hc.core5.net.URIBuilder for URI (#187)
(cherry picked from commit 43e86eeac2f3211aa275e1934d17adf29f1cd6e1)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java | 27 | ||||
| -rw-r--r-- | src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java | 25 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java index 95e8e8f..cc0491d 100644 --- a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java +++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.parser.DataFormatException; import dev.dnpm.etl.processor.config.AppFhirConfig; import dev.dnpm.etl.processor.config.GIcsConfigProperties; import org.apache.commons.lang3.StringUtils; +import org.apache.hc.core5.net.URIBuilder; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; import org.jetbrains.annotations.NotNull; @@ -18,9 +19,9 @@ import org.springframework.retry.TerminatedRetryException; import org.springframework.retry.support.RetryTemplate; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; +import java.net.URISyntaxException; import java.util.Date; /** @@ -118,9 +119,21 @@ public class GicsConsentService implements IConsentService { return result; } - private URI endpointUri(String endpoint) { - assert this.gIcsConfigProperties.getUri() != null; - return UriComponentsBuilder.fromUriString(this.gIcsConfigProperties.getUri()).path(endpoint).build().toUri(); + private URI endpointUri(String endpoint) throws URISyntaxException { + if (null == this.gIcsConfigProperties.getUri()) { + throw new URISyntaxException("null", "URI must not be null"); + } + var gPasUrl1 = this.gIcsConfigProperties.getUri(); + if (this.gIcsConfigProperties.getUri().lastIndexOf("/") + == this.gIcsConfigProperties.getUri().length() - 1) { + gPasUrl1 = + this.gIcsConfigProperties + .getUri() + .substring(0, this.gIcsConfigProperties.getUri().length() - 1); + } + var urlBuilder = new URIBuilder(new URI(gPasUrl1)).appendPath(endpoint); + + return urlBuilder.build(); } private HttpHeaders headersWithHttpBasicAuth() { @@ -169,7 +182,11 @@ public class GicsConsentService implements IConsentService { terminatedRetryException.getMessage()); log.error(msg); return null; - } + } catch (URISyntaxException e) { + var msg = String.format("Invalid URI for consents status request: '%s", e.getMessage()); + log.error(msg); + return null; + } } @Override diff --git a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java index 6fa8f08..c5b269d 100644 --- a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java +++ b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import dev.dnpm.etl.processor.config.AppConfiguration; import dev.dnpm.etl.processor.config.AppFhirConfig; import dev.dnpm.etl.processor.config.GIcsConfigProperties; +import org.apache.hc.core5.net.URIBuilder; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.r4.model.OperationOutcome.IssueType; @@ -20,9 +21,11 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import java.net.URI; import java.time.Instant; import java.util.Date; +import static dev.dnpm.etl.processor.consent.GicsConsentService.IS_CONSENTED_ENDPOINT; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError; @@ -44,7 +47,11 @@ class GicsConsentServiceTest { GicsConsentService gicsConsentService; - @BeforeEach + static URI expectedGicsConsentedEndpoint() throws Exception { + return new URIBuilder(URI.create(GICS_BASE_URI)).appendPath(IS_CONSENTED_ENDPOINT).build(); + } + + @BeforeEach void setUp( @Autowired AppFhirConfig appFhirConfig, @Autowired GIcsConfigProperties gIcsConfigProperties @@ -64,7 +71,7 @@ class GicsConsentServiceTest { } @Test - void shouldReturnTtpBroadConsentStatus() { + void shouldReturnTtpBroadConsentStatus() throws Exception { final Parameters consentedResponse = new Parameters() .addParameter( new ParametersParameterComponent() @@ -75,7 +82,7 @@ class GicsConsentServiceTest { mockRestServiceServer .expect( requestTo( - "http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT) + expectedGicsConsentedEndpoint()) ) .andRespond( withSuccess( @@ -89,7 +96,7 @@ class GicsConsentServiceTest { } @Test - void shouldReturnRevokedConsent() { + void shouldReturnRevokedConsent() throws Exception { final Parameters revokedResponse = new Parameters() .addParameter( new ParametersParameterComponent() @@ -100,7 +107,7 @@ class GicsConsentServiceTest { mockRestServiceServer .expect( requestTo( - "http://localhost:8090/ttp-fhir/fhir/gics" + GicsConsentService.IS_CONSENTED_ENDPOINT) + expectedGicsConsentedEndpoint()) ) .andRespond( withSuccess( @@ -114,7 +121,7 @@ class GicsConsentServiceTest { @Test - void shouldReturnInvalidParameterResponse() { + void shouldReturnInvalidParameterResponse() throws Exception { final OperationOutcome responseWithErrorOutcome = new OperationOutcome() .addIssue( new OperationOutcomeIssueComponent() @@ -125,7 +132,7 @@ class GicsConsentServiceTest { mockRestServiceServer .expect( - requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT) + requestTo(expectedGicsConsentedEndpoint()) ) .andRespond( withSuccess( @@ -139,10 +146,10 @@ class GicsConsentServiceTest { } @Test - void shouldReturnRequestError() { + void shouldReturnRequestError() throws Exception { mockRestServiceServer .expect( - requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT) + requestTo(expectedGicsConsentedEndpoint()) ) .andRespond( withServerError() |
