private ResponseBuilder builder(final ClientExceptionType hType, final String msg) { ResponseBuilder builder = Response.status(hType.getResponseStatus()). header(RESTHeaders.ERROR_CODE, hType.name()). header(RESTHeaders.ERROR_INFO, hType.getInfoHeaderValue(msg)); ErrorTO error = new ErrorTO(); error.setStatus(hType.getResponseStatus().getStatusCode()); error.setType(hType); error.getElements().add(msg); return builder.entity(error); }
public SyncopeClientException getException(final ClientExceptionType exceptionType) { boolean found = false; SyncopeClientException syncopeClientException = null; for (Iterator<SyncopeClientException> itor = exceptions.iterator(); itor.hasNext() && !found;) { syncopeClientException = itor.next(); if (syncopeClientException.getType().equals(exceptionType)) { found = true; } } return found ? syncopeClientException : null; }
public static ClientExceptionType fromHeaderValue(final String exceptionTypeHeaderValue) { ClientExceptionType result = null; for (ClientExceptionType type : values()) { if (exceptionTypeHeaderValue.equals(type.name())) { result = type; } } if (result == null) { throw new IllegalArgumentException("Unexpected header value: " + exceptionTypeHeaderValue); } return result; }
} else { try { exType = ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName()); } catch (IllegalArgumentException e) { builder.header(RESTHeaders.ERROR_CODE, exType.name()); error.setStatus(exType.getResponseStatus().getStatusCode()); error.setType(exType); for (EntityViolationType violationType : violation.getValue()) { builder.header(RESTHeaders.ERROR_INFO, exType.getInfoHeaderValue(violationType.name() + ": " + violationType.getMessage())); error.getElements().add(violationType.name() + ": " + violationType.getMessage());
ClientExceptionType exceptionType = null; try { exceptionType = ClientExceptionType.fromHeaderValue(exTypeAsString); } catch (IllegalArgumentException e) { LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": " + exTypeAsString, e); if (exInfos != null && !exInfos.isEmpty()) { for (String element : exInfos) { if (element.startsWith(exceptionType.name())) { clientException.getElements().add(StringUtils.substringAfter(element, ":"));
public String getInfoHeaderValue(final String value) { // HTTP header values cannot contain CR / LF return (name() + ":" + value).replaceAll("(\\r|\\n)", " "); }
ClientExceptionType exceptionType = null; try { exceptionType = ClientExceptionType.fromHeaderValue(exTypeAsString); } catch (IllegalArgumentException e) { LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": " + exTypeAsString, e); if (exInfos != null && !exInfos.isEmpty()) { for (String element : exInfos) { if (element.startsWith(exceptionType.name())) { clientException.getElements().add(StringUtils.substringAfter(element, ":"));
public String getInfoHeaderValue(final String value) { // HTTP header values cannot contain CR / LF return (name() + ":" + value).replaceAll("(\\r|\\n)", " "); }
private ResponseBuilder getSyncopeClientExceptionResponse(final SyncopeClientException ex) { ResponseBuilder builder = Response.status(ex.getType().getResponseStatus()); builder.header(RESTHeaders.ERROR_CODE, ex.getType().name()); ErrorTO error = new ErrorTO(); error.setStatus(ex.getType().getResponseStatus().getStatusCode()); error.setType(ex.getType()); ex.getElements().forEach(element -> { builder.header(RESTHeaders.ERROR_INFO, ex.getType().getInfoHeaderValue(element)); error.getElements().add(element); }); return builder.entity(error); }
public static ClientExceptionType fromHeaderValue(final String exceptionTypeHeaderValue) { ClientExceptionType result = null; for (ClientExceptionType type : values()) { if (exceptionTypeHeaderValue.equals(type.name())) { result = type; } } if (result == null) { throw new IllegalArgumentException("Unexpected header value: " + exceptionTypeHeaderValue); } return result; }
public SyncopeClientException getException(final ClientExceptionType exceptionType) { boolean found = false; SyncopeClientException syncopeClientException = null; for (Iterator<SyncopeClientException> itor = exceptions.iterator(); itor.hasNext() && !found;) { syncopeClientException = itor.next(); if (syncopeClientException.getType().equals(exceptionType)) { found = true; } } return found ? syncopeClientException : null; }
private ResponseBuilder getSyncopeClientCompositeExceptionResponse(final SyncopeClientCompositeException ex) { if (ex.getExceptions().size() == 1) { return getSyncopeClientExceptionResponse(ex.getExceptions().iterator().next()); } ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST); List<ErrorTO> errors = new ArrayList<>(); ex.getExceptions().stream().map(sce -> { builder.header(RESTHeaders.ERROR_CODE, sce.getType().name()); ErrorTO error = new ErrorTO(); error.setStatus(sce.getType().getResponseStatus().getStatusCode()); error.setType(sce.getType()); sce.getElements().forEach(element -> { builder.header(RESTHeaders.ERROR_INFO, sce.getType().getInfoHeaderValue(element)); error.getElements().add(element); }); return error; }).collect(Collectors.toList()); return builder.entity(errors); }
header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.name()). header(RESTHeaders.ERROR_INFO, ClientExceptionType.RESTValidation.getInfoHeaderValue( ExceptionUtils.getRootCauseMessage(ex))); error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode()); error.setType(ClientExceptionType.RESTValidation); error.getElements().add(ExceptionUtils.getRootCauseMessage(ex)); header(RESTHeaders.ERROR_INFO, ClientExceptionType.Unknown.getInfoHeaderValue( ExceptionUtils.getRootCauseMessage(ex)));