Search in sources :

Example 1 with HealthCheckResponse

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)));
}
Also used : SoapResponse(uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse) HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with HealthCheckResponse

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));
}
Also used : HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) HealthCheckResponseBuilder.aHealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.builders.HealthCheckResponseBuilder.aHealthCheckResponse) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.Test)

Example 3 with HealthCheckResponse

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())));
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) Timer(com.codahale.metrics.Timer) HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)

Example 4 with HealthCheckResponse

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)));
}
Also used : HealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse) HealthCheckResponseBuilder.aHealthCheckResponse(uk.gov.ida.hub.samlsoapproxy.builders.HealthCheckResponseBuilder.aHealthCheckResponse) MatchingServiceHealthCheckResponseDto(uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto) Test(org.junit.jupiter.api.Test)

Aggregations

HealthCheckResponse (uk.gov.ida.hub.samlsoapproxy.rest.HealthCheckResponse)4 MatchingServiceHealthCheckResponseDto (uk.gov.ida.hub.samlsoapproxy.domain.MatchingServiceHealthCheckResponseDto)3 HealthCheckResponseBuilder.aHealthCheckResponse (uk.gov.ida.hub.samlsoapproxy.builders.HealthCheckResponseBuilder.aHealthCheckResponse)2 Timer (com.codahale.metrics.Timer)1 ProcessingException (javax.ws.rs.ProcessingException)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1 SoapResponse (uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse)1