use of uk.gov.ida.hub.samlsoapproxy.contract.MatchingServiceHealthCheckerRequestDto in project verify-hub by alphagov.
the class MatchingServiceHealthChecker method performHealthCheck.
public MatchingServiceHealthCheckResult performHealthCheck(final MatchingServiceConfigEntityDataDto configEntity) {
MatchingServiceHealthCheckerRequestDto matchingServiceHealthCheckerRequestDto = new MatchingServiceHealthCheckerRequestDto(configEntity.getTransactionEntityId(), configEntity.getEntityId());
MatchingServiceHealthCheckResponseDto response;
try {
SamlMessageDto samlMessageDto = samlEngineProxy.generateHealthcheckAttributeQuery(matchingServiceHealthCheckerRequestDto);
final Element matchingServiceHealthCheckRequest = XmlUtils.convertToElement(samlMessageDto.getSamlMessage());
validateRequestSignature(matchingServiceHealthCheckRequest);
response = matchingServiceHealthCheckClient.sendHealthCheckRequest(matchingServiceHealthCheckRequest, configEntity.getUri());
if (response.getResponse().isPresent()) {
final Optional<String> msaVersion = extractVersionFromResponseId(response.getResponse().get());
if (msaVersion.isPresent()) {
// if we have conflicting return values, lets trust the one from the ID a little bit more
response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
if (!response.getVersionNumber().get().equals(msaVersion.get())) {
response = new MatchingServiceHealthCheckResponseDto(response.getResponse(), msaVersion);
LOG.warn("MSA healthcheck response with two version numbers: {0} & {1}", response.getVersionNumber().get(), msaVersion.get());
}
}
}
} catch (ApplicationException e) {
final String message = format("Saml-engine was unable to generate saml to send to MSA: {0}", e);
eventLogger.logException(e, message);
return logAndCreateUnhealthyResponse(configEntity, message);
} catch (ParserConfigurationException | SAXException | IOException e) {
final String message = format("Unable to convert saml request to XML element: {0}", e);
return logAndCreateUnhealthyResponse(configEntity, message);
}
if (isHealthyResponse(response, configEntity.getUri())) {
return healthy(generateHealthCheckDescription("responded successfully", configEntity.getUri(), response.getVersionNumber(), configEntity.isOnboarding()));
} else {
return unhealthy(generateHealthCheckFailureDescription(response, configEntity.getUri(), configEntity.isOnboarding()));
}
}
Aggregations