...
Code Block | ||||
---|---|---|---|---|
| ||||
private void validateProperty (String propertyValue, String authorization) throws HookException {
//Validate property with catalogue entry
if (propertyValue != null) {
if (!propertyValue.isBlank()) {
String url = "http://catalog/api/catalogs/" + catalogueName + "/" + propertyValue;
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", authorization);
HttpEntity requestEntity = new HttpEntity<>(null, headers);
try {
ResponseEntity<Void> response =
this.restTemplate.exchange(url, HttpMethod.HEAD, requestEntity, Void.class);
if (HttpStatus.OK.equals(response.getStatusCode())) {
LOGGER.debug("Property [" + propertyValue + "] validation was successful");
}
} catch (HttpStatusCodeException e) {
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
throw new HookException("Catalogue [" + catalogueName + "] does not exist or property [" + propertyValue + "] does not match any catalogue entry.");
} else {
//Error handling
throw new HookException("Something went wrong.");
}
}
} else {
throw new HookException("The property [" + propertyId + "] is empty.");
}
} else {
LOGGER.debug("This object does not have the property: " + propertyId);
}
} |
On a failed response the service throws a custom HookException.
...