use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto 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()));
}
}
use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnOptionalAbsentIfNoResponseReceived.
@Test
public void sendHealthCheckRequest_shouldReturnOptionalAbsentIfNoResponseReceived() {
when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenThrow(ApplicationException.createUnauditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID()));
final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
assertThat(matchingServiceHealthCheckResponseDto.getResponse()).isEqualTo(Optional.<String>absent());
}
use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckerTest method prepareForResponse.
private void prepareForResponse(MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto, MatchingServiceIdaStatus status, Optional<String> msaVersion) {
when(samlEngineProxy.generateHealthcheckAttributeQuery(any())).thenReturn(new SamlMessageDto("<saml/>"));
final MatchingServiceHealthCheckerResponseDto inboundResponseFromMatchingServiceDto = anInboundResponseFromMatchingServiceDto().withStatus(status).build();
when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(), eq(matchingServiceConfigEntityDataDto.getUri()))).thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of("<saml/>"), msaVersion));
when(samlEngineProxy.translateHealthcheckMatchingServiceResponse(any())).thenReturn(inboundResponseFromMatchingServiceDto);
}
use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckClient method sendHealthCheckRequest.
public MatchingServiceHealthCheckResponseDto sendHealthCheckRequest(final Element matchingServiceHealthCheckRequest, final URI matchingServiceUri) {
// Use a custom timer so that we get separate metrics for each matching service
final String scope = matchingServiceUri.toString().replace(':', '_').replace('/', '_');
final Timer timer = metricsRegistry.timer(MetricRegistry.name(MatchingServiceHealthCheckClient.class, "sendHealthCheckRequest", scope));
final Timer.Context context = timer.time();
HealthCheckResponse healthCheckResponse;
try {
healthCheckResponse = client.makeSoapRequestForHealthCheck(matchingServiceHealthCheckRequest, matchingServiceUri);
} catch (ApplicationException ex) {
final String errorMessage = MessageFormat.format("Failed to complete matching service health check to {0}.", matchingServiceUri);
LOG.warn(errorMessage, ex);
return new MatchingServiceHealthCheckResponseDto(Optional.<String>absent(), Optional.<String>absent());
} finally {
context.stop();
}
return new MatchingServiceHealthCheckResponseDto(Optional.of(XmlUtils.writeToString(healthCheckResponse.getResponseElement())), healthCheckResponse.getVersionNumber());
}
use of uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto in project verify-hub by alphagov.
the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnTrueIfResponseReceived.
@Test
public void sendHealthCheckRequest_shouldReturnTrueIfResponseReceived() {
HealthCheckResponse healthCheckResponse = aHealthCheckResponse().withElement(healthCheckResponseElement).build();
when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenReturn(healthCheckResponse);
final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
assertThat(matchingServiceHealthCheckResponseDto.getResponse()).isEqualTo(Optional.of(XmlUtils.writeToString(healthCheckResponseElement)));
}
Aggregations