Restaasy Bean Verification not called

Background problem

I have a Restaasy service that uses Spring through Resteasy SpringContextLoaderListener . It is built on Resteasy version 3.0-beta-6 .

I would like to use bean validation for incoming requests, but I cannot force Restaasy to call the validator. It acts as if verification is not configured and simply passes the method to an invalid input object.

Question

  • How to enable bean check in Resteasy?

What i tried

I have done the following:

  • Annotated resource class with @ValidateRequest
  • Annotated method parameter using @Valid
  • Annotated restrictions on my input class.
  • resteasy-hibernatevalidator-provider dependency added

Resource:

 @Named @Path("users") @ValidateRequest public class UserResource { /** * * @param user * * curl -x POST http://localhost:7016/api/1.0/users * */ @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public Response createUser(@Valid User user) { //User creation logic here. } } 

POJO user:

 @JsonPropertyOrder({ "user_id", "user_name", "email" }) public class User { @JsonProperty("user_id") private Long userId; @JsonProperty("user_name") @NotNull(message = "Username must be provided") private String username; @Email(message = "Invalid email address.") private String email; //Getters and Setters Removed for Brevity } 

POM record to check:

  <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-hibernatevalidator-provider</artifactId> <version>${resteasy.version}</version> </dependency> 

The resteasy-hibernatevalidator-provider dependency contains a HibernateValidatorContextResolver and its associated HibernateValidatorAdapter .


Update (6/18/2013):

I returned the Resteasy version in my pom so that 2.3.5.Final and bean checking started working without any code changes.

+7
source share
3 answers

You did it:

Providing ValidatorAdapter for RESTEasy

RESTEasy will try to get the implementation of the ValidatorAdapter through the ContextResolver provider in the classpath. We can provide a RESTEasy implementation, for example:

 @Provider public class MyValidatorContextResolver implements ContextResolver<ValidatorAdapter> { @Override public ValidatorAdapter getContext(Class<?> type) { return new MyValidator(); } } 
0
source

Make sure META-INF / services / javax.ws.rs.Providers is defined in your war.

You can use the sleep mode validator provided with resteasy-3.0.

Mark chapter 48 of the recovery documentation:

http://docs.jboss.org/resteasy/docs/3.0.0.Final/userguide/html_single/index.html#JBoss AS 6

0
source

Work with Resteasy '3.0.6.Final' and Spring '4.1.0.RELEASE'.

"resteasy-hibernatevalidator-provider" does not evaluate the annotated @Valid parameters. Using "resteasy-validator-provider-11" makes everything work, and the Hiberbate "5.0.1.Final" validator is used as a bonus instead of using the Hibernate version 4 validator when using "resteasy-hibernatevalidator-provider".

0
source

All Articles