Search in sources :

Example 1 with ConstraintDeclarationException

use of jakarta.validation.ConstraintDeclarationException in project resteasy by resteasy.

the class ResteasyViolationExceptionMapper method toResponse.

public Response toResponse(ValidationException exception) {
    if (exception instanceof ConstraintDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ConstraintDeclarationException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof GroupDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ResteasyViolationException) {
        ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
        Exception e = resteasyViolationException.getException();
        if (e != null) {
            return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
        } else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
            return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
        } else {
            return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
        }
    }
    return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
Also used : GroupDefinitionException(jakarta.validation.GroupDefinitionException) ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) ResteasyViolationException(org.jboss.resteasy.api.validation.ResteasyViolationException) ResteasyViolationException(org.jboss.resteasy.api.validation.ResteasyViolationException) ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) ConstraintDefinitionException(jakarta.validation.ConstraintDefinitionException) ValidationException(jakarta.validation.ValidationException) GroupDefinitionException(jakarta.validation.GroupDefinitionException) ConstraintDefinitionException(jakarta.validation.ConstraintDefinitionException)

Example 2 with ConstraintDeclarationException

use of jakarta.validation.ConstraintDeclarationException in project hibernate-validator by hibernate.

the class MostSpecificValueExtractorTest method parallelValueExtractorDefinitionsCausesException.

@Test
@TestForIssue(jiraKey = "HV-1306")
public void parallelValueExtractorDefinitionsCausesException() throws Exception {
    Validator validator = Validation.byProvider(HibernateValidator.class).configure().addValueExtractor(new IWrapper21ValueExtractor()).addValueExtractor(new IWrapper211ValueExtractor()).addValueExtractor(new IWrapper212ValueExtractor()).addValueExtractor(new IWrapper22ValueExtractor()).addValueExtractor(new IWrapper221ValueExtractor()).buildValidatorFactory().getValidator();
    try {
        validator.validate(new Entity2(null));
        fail("An exception should have been thrown");
    } catch (ConstraintDeclarationException e) {
        String message = e.getMessage();
        assertThat(message).startsWith("HV000219");
        assertThat(message).contains(Wrapper2.class.getName());
        assertThat(message).contains(IWrapper21ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper211ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper212ValueExtractor.class.getName());
        assertThat(message).contains(IWrapper22ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper221ValueExtractor.class.getName());
    }
}
Also used : ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) Entity2(org.hibernate.validator.test.internal.engine.valueextraction.model.Entity2) Validator(jakarta.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

ConstraintDeclarationException (jakarta.validation.ConstraintDeclarationException)2 ConstraintDefinitionException (jakarta.validation.ConstraintDefinitionException)1 GroupDefinitionException (jakarta.validation.GroupDefinitionException)1 ValidationException (jakarta.validation.ValidationException)1 Validator (jakarta.validation.Validator)1 HibernateValidator (org.hibernate.validator.HibernateValidator)1 Entity2 (org.hibernate.validator.test.internal.engine.valueextraction.model.Entity2)1 TestForIssue (org.hibernate.validator.testutil.TestForIssue)1 ResteasyViolationException (org.jboss.resteasy.api.validation.ResteasyViolationException)1 Test (org.testng.annotations.Test)1