use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.
the class TimeoutEvaluator method hasAttributeQueryTimedOut.
public void hasAttributeQueryTimedOut(AttributeQueryContainerDto queryContainerDto) {
DateTime timeout = queryContainerDto.getAttributeQueryClientTimeOut();
DateTime timeOfCheck = DateTime.now();
if (timeout.isBefore(timeOfCheck)) {
Duration duration = new Duration(timeout, timeOfCheck);
throw new AttributeQueryTimeoutException(MessageFormat.format("Attribute Query timed out by {0} seconds.", duration.getStandardSeconds()));
}
}
use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.
the class AttributeQueryRequestRunnable method run.
@Override
public void run() {
counter.dec();
// see https://github.com/google/guice/wiki/CustomScopes for details on this work
addSessionIdToLoggingContext(sessionId);
try {
timeoutEvaluator.hasAttributeQueryTimedOut(attributeQueryContainerDto);
} catch (AttributeQueryTimeoutException e) {
auditAndLogTimeoutException(sessionId, attributeQueryContainerDto, e, "Matching service attribute timed out before even being sent.");
return;
}
try {
Element response = executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
timeoutEvaluator.hasAttributeQueryTimedOut(attributeQueryContainerDto);
final String base64EncodedSamlResponse = Base64.encodeAsString(XmlUtils.writeToString(response).getBytes());
hubMatchingServiceResponseReceiverProxy.notifyHubOfAResponseFromMatchingService(sessionId, base64EncodedSamlResponse);
} catch (AttributeQueryTimeoutException e) {
auditAndLogTimeoutException(sessionId, attributeQueryContainerDto, e, "Matching service attribute query has timed out, therefore not sending failure notification to saml engine.");
} catch (Exception e) {
logAndAuditMessageError(e, attributeQueryContainerDto, sessionId);
checkTimeoutAndForwardErrorResponse(sessionId, attributeQueryContainerDto);
}
}
use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.
the class AttributeQueryRequestRunnableTest method run_shouldSayIfTimeoutWasBeforeSendingMessage.
@Test
public void run_shouldSayIfTimeoutWasBeforeSendingMessage() throws Exception {
final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
attributeQueryRequestRunnable.run();
final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
verify(eventEmitter).record(emitterLoggedHubEvent.capture());
assertThat(loggedHubEvent.getValue().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
assertThat(emitterLoggedHubEvent.getValue().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
}
Aggregations