Skip to content

Commit

Permalink
MET-5875: normalize URI to avoid '//' in dereference client.
Browse files Browse the repository at this point in the history
  • Loading branch information
jochen-vermeulen committed Mar 29, 2024
1 parent 2c58bf6 commit 6524d36
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ public List<Vocabulary> getAllVocabularies() {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final Vocabulary[] result = restTemplate.exchange(hostUrl + RestEndpoints.VOCABULARIES,
final String uriString = hostUrl + RestEndpoints.VOCABULARIES;
final URI uri;
try {
// Normalize to remove double '/' between host and path.
uri = new URI(uriString).normalize();
} catch (URISyntaxException e) {
// Cannot really happen.
LOGGER.warn("URL [{}] is not valid.", uriString, e);
throw new IllegalStateException("Could not contact dereference service.");
}
final Vocabulary[] result = restTemplate.exchange(uri,
HttpMethod.GET, entity, Vocabulary[].class).getBody();
return Optional.ofNullable(result).map(Arrays::asList).orElseGet(Collections::emptyList);
}
Expand Down Expand Up @@ -75,16 +85,16 @@ public EnrichmentResultList dereference(String resourceId) {
return null;
}

// Compile the dereference URI.
// Compile the dereference URI (normalize to remove double '/' between host and path).
final String dereferenceUrlString =
hostUrl + RestEndpoints.DEREFERENCE + "?uri=" + resourceString;
URI dereferenceUrl;
try {
dereferenceUrl = new URI(hostUrl + RestEndpoints.DEREFERENCE + "?uri=" + resourceString);
dereferenceUrl = new URI(dereferenceUrlString).normalize();
} catch (URISyntaxException e) {
// Cannot really happen.
LOGGER.warn("URL [{}] is not valid.", dereferenceUrlString, e);
return null;
throw new IllegalStateException("Could not contact dereference service.", e);
}

// Execute the dereference call.
Expand Down

0 comments on commit 6524d36

Please sign in to comment.