Package org.apache.syncope.common.reqres

Examples of org.apache.syncope.common.reqres.ErrorTO


                    ? getSyncopeClientCompositeExceptionResponse(sce.asComposite())
                    : getSyncopeClientExceptionResponse(sce);
        } else if (ex instanceof WebApplicationException) {
            Response response = ((WebApplicationException) ex).getResponse();

            ErrorTO error = new ErrorTO();
            error.setStatus(response.getStatus());
            error.setType(ClientExceptionType.Unknown);
            error.getElements().add(getExMessage(ex));

            builder = JAXRSUtils.fromResponse(response).entity(error);
        } else if (ex instanceof AccessDeniedException) {
            builder = Response.status(Response.Status.UNAUTHORIZED).
                    header(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM_UNAUTHORIZED);
        } else if (ex instanceof UnauthorizedRoleException) {
            builder = builder(Response.Status.UNAUTHORIZED, ClientExceptionType.UnauthorizedRole, getExMessage(ex));
        } else if (ex instanceof EntityExistsException) {
            builder = builder(Response.Status.CONFLICT, ClientExceptionType.EntityExists, getExMessage(ex));
        } else if (ex instanceof DataIntegrityViolationException) {
            builder = builder(Response.Status.CONFLICT, ClientExceptionType.DataIntegrityViolation, getExMessage(ex));
        } else {
            builder = processNotFoundExceptions(ex);
            if (builder == null) {
                builder = processInvalidEntityExceptions(ex);
                if (builder == null) {
                    builder = processBadRequestExceptions(ex);
                }
                // process JAX-RS validation errors
                if (builder == null && ex instanceof ValidationException) {
                    builder = JAXRSUtils.fromResponse(validationEM.toResponse((ValidationException) ex)).
                            header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.getHeaderValue()).
                            header(RESTHeaders.ERROR_INFO,
                                    ClientExceptionType.RESTValidation.getInfoHeaderValue(getExMessage(ex)));

                    ErrorTO error = new ErrorTO();
                    error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
                    error.setType(ClientExceptionType.RESTValidation);
                    error.getElements().add(getExMessage(ex));
                    builder.entity(error);
                }
                // ...or just report as InternalServerError
                if (builder == null) {
                    builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).
                            header(RESTHeaders.ERROR_INFO,
                                    ClientExceptionType.Unknown.getInfoHeaderValue(getExMessage(ex)));

                    ErrorTO error = new ErrorTO();
                    error.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
                    error.setType(ClientExceptionType.Unknown);
                    error.getElements().add(getExMessage(ex));
                    builder.entity(error);
                }
            }
        }
View Full Code Here


    private ResponseBuilder getSyncopeClientExceptionResponse(final SyncopeClientException ex) {
        ResponseBuilder builder = Response.status(ex.getType().getResponseStatus());
        builder.header(RESTHeaders.ERROR_CODE, ex.getType().getHeaderValue());

        ErrorTO error = new ErrorTO();
        error.setStatus(ex.getType().getResponseStatus().getStatusCode());
        error.setType(ex.getType());

        for (String element : ex.getElements()) {
            builder.header(RESTHeaders.ERROR_INFO, ex.getType().getInfoHeaderValue(element));
            error.getElements().add(element);
        }

        return builder.entity(error);
    }
View Full Code Here

        List<ErrorTO> errors = new ArrayList<ErrorTO>();
        for (SyncopeClientException sce : ex.getExceptions()) {
            builder.header(RESTHeaders.ERROR_CODE, sce.getType().getHeaderValue());

            ErrorTO error = new ErrorTO();
            error.setStatus(sce.getType().getResponseStatus().getStatusCode());
            error.setType(sce.getType());

            for (String element : sce.getElements()) {
                builder.header(RESTHeaders.ERROR_INFO, ex.getType().getInfoHeaderValue(element));
                error.getElements().add(element);
            }

            errors.add(error);
        }
View Full Code Here

                    : ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName());

            ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
            builder.header(RESTHeaders.ERROR_CODE, exType.getHeaderValue());

            ErrorTO error = new ErrorTO();
            error.setStatus(exType.getResponseStatus().getStatusCode());
            error.setType(exType);

            for (Map.Entry<Class<?>, Set<EntityViolationType>> violation : iee.getViolations().entrySet()) {
                for (EntityViolationType violationType : violation.getValue()) {
                    builder.header(RESTHeaders.ERROR_INFO,
                            exType.getInfoHeaderValue(violationType.name() + ": " + violationType.getMessage()));
                    error.getElements().add(violationType.name() + ": " + violationType.getMessage());
                }
            }

            return builder;
        }
View Full Code Here

    private ResponseBuilder builder(final Response.Status status, final ClientExceptionType hType, final String msg) {
        ResponseBuilder builder = Response.status(status).
                header(RESTHeaders.ERROR_CODE, hType.getHeaderValue()).
                header(RESTHeaders.ERROR_INFO, hType.getInfoHeaderValue(msg));

        ErrorTO error = new ErrorTO();
        error.setStatus(status.getStatusCode());
        error.setType(hType);
        error.getElements().add(msg);

        return builder.entity(error);
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.common.reqres.ErrorTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.