use of uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse in project verify-hub by alphagov.
the class HealthCheckSoapRequestClient method makeSoapRequestForHealthCheck.
public HealthCheckResponse makeSoapRequestForHealthCheck(Element requestElement, URI uri) {
LOG.info(MessageFormat.format("Making SOAP request to: {0}", uri));
SoapResponse response;
try {
response = makePost(uri, requestElement);
} catch (ProcessingException e) {
throw ApplicationException.createUnauditedException(ExceptionType.NETWORK_ERROR, UUID.randomUUID(), e);
} catch (SOAPRequestError e) {
throw ApplicationException.createUnauditedException(ExceptionType.REMOTE_SERVER_ERROR, UUID.randomUUID(), e);
}
return new HealthCheckResponse(response.getBody(), Optional.fromNullable(response.getHeaders().getFirst(MSA_VERSION_HTTP_HEADER)));
}
use of uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse in project verify-hub by alphagov.
the class MatchingServiceHealthCheckClientTest method sendHealthCheckRequest_shouldReturnSuccessResponseWithVersionNumber.
@Test
public void sendHealthCheckRequest_shouldReturnSuccessResponseWithVersionNumber() {
String expectedVersion = "someVersion";
HealthCheckResponse responseMessageThatHasAVersion = aHealthCheckResponse().withElement(healthCheckResponseElement).withVersionNumber(expectedVersion).build();
when(soapRequestClient.makeSoapRequestForHealthCheck(healthCheckRequest, healthCheckUri)).thenReturn(responseMessageThatHasAVersion);
final MatchingServiceHealthCheckResponseDto matchingServiceHealthCheckResponseDto = matchingServiceHealthCheckClient.sendHealthCheckRequest(healthCheckRequest, healthCheckUri);
assertThat(matchingServiceHealthCheckResponseDto.getVersionNumber()).isEqualTo(Optional.of(expectedVersion));
}
use of uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse 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.empty());
} finally {
context.stop();
}
return new MatchingServiceHealthCheckResponseDto(Optional.of(XmlUtils.writeToString(healthCheckResponse.getResponseElement())));
}
use of uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse 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