use of javax.ws.rs.client.ResponseProcessingException in project verify-hub by alphagov.
the class AttributeQueryRequestClient method sendSingleQuery.
private Optional<Element> sendSingleQuery(Element serialisedQuery, String messageId, SessionId sessionId, URI matchingServiceUri) {
try {
externalCommunicationEventLogger.logMatchingServiceRequest(messageId, sessionId, matchingServiceUri);
// Use a custom timer so that we get separate metrics for each matching service
final String scope = matchingServiceUri.toString().replace(':', '_').replace('/', '_');
// TODO: remove this timer once we're happy the prometheus Histogram works properly
final Timer timer = metricsRegistry.timer(MetricRegistry.name(AttributeQueryRequestClient.class, "sendSingleQuery", scope));
final Timer.Context context = timer.time();
Summary.Timer prometheusTimer = msaRequestDuration.labels(matchingServiceUri.toString()).startTimer();
try {
return Optional.ofNullable(soapRequestClient.makeSoapRequest(serialisedQuery, matchingServiceUri));
} finally {
context.stop();
prometheusTimer.observeDuration();
}
} catch (SOAPRequestError e) {
if (e.getEntity().isPresent()) {
final String responseBody = e.getEntity().get();
LOG.info(format("Error received from MSA (URI ''{0}'') following HTTP response {1}; response body:\n{2}", matchingServiceUri, e.getResponseStatus(), responseBody));
// to split out these errors. See https://trello.com/c/N7edPMiO/
if (responseBody.startsWith("uk.gov.ida.exceptions.ApplicationException")) {
throw new MatchingServiceException(format("Unknown internal Matching Service error from {0} with status {1} ", matchingServiceUri, e.getResponseStatus()), e);
}
}
throw new MatchingServiceException(format("Matching Service response from {0} was status {1}", matchingServiceUri, e.getResponseStatus()), e);
} catch (ResponseProcessingException e) {
LOG.error(format("Matching service attribute query to {0} failed during response processing ({1})", matchingServiceUri, e.getMessage()), e);
throw new MatchingServiceException("Request to Matching Service Failed during response processing", e);
} catch (ProcessingException e) {
LOG.error(format("Matching service attribute query to {0} experienced a connection level failure ({1})", matchingServiceUri, e.getMessage()), e);
throw new MatchingServiceException("Request to Matching Service Failed At Http Layer", e);
} catch (Exception e) {
throw new MatchingServiceException(format("The matching service attribute query to {0} failed for an unknown reason ({1}).", matchingServiceUri, e.getMessage()), e);
}
}
Aggregations