if (exTypesInHeaders == null) {
LOG.debug("No " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + " provided");
return null;
}
final SyncopeClientCompositeErrorException compException = new SyncopeClientCompositeErrorException(
org.springframework.http.HttpStatus.valueOf(statusCode));
final Set<String> handledExceptions = new HashSet<String>();
for (Object exceptionTypeValue : exTypesInHeaders) {
final String exTypeAsString = (String) exceptionTypeValue;
SyncopeClientExceptionType exceptionType = null;
try {
exceptionType = SyncopeClientExceptionType.getFromHeaderValue(exTypeAsString);
} catch (IllegalArgumentException e) {
LOG.error("Unexpected value of " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + ": "
+ exTypeAsString, e);
}
if (exceptionType != null) {
handledExceptions.add(exTypeAsString);
final SyncopeClientException clientException = new SyncopeClientException();
clientException.setType(exceptionType);
if (response.getHeaders().get(exceptionType.getElementHeaderName()) != null
&& !response.getHeaders().get(exceptionType.getElementHeaderName()).isEmpty()) {
// TODO update clientException to support list of objects
final List<Object> elObjectList = response.getHeaders().get(exceptionType.getElementHeaderName());
final List<String> elStringList = new ArrayList<String>();
for (Object elementObject : elObjectList) {
if (elementObject instanceof String) {
elStringList.add((String) elementObject);
}
}
clientException.setElements(elStringList);
}
compException.addException(clientException);
}
}
exTypesInHeaders.removeAll(handledExceptions);
if (!exTypesInHeaders.isEmpty()) {
LOG.error("Unmanaged exceptions: " + exTypesInHeaders);
}
if (compException.hasExceptions()) {
return compException;
}
return null;
}