Re: JAX-RS and @ValidateOnExecution

Gunnar Morling

2017-06-20 9:34 GMT+02:00 Pavel Bucek <pavel.bucek@...>:
Do we have BeanValidation expert here? ;) Gunnar?

I believe the implementation should skip the method validation when

@ValidateOnExecution(type = ExecutableType.NONE)

is on the method / class.
That's right. So if Jersey still is executing the validation in this
case, it seems to be a bug.

But what about when

@ValidateOnExecution(type = ExecutableType.CONSTRUCTORS)

is on the resource method?
Using this on a method (as opposed to a constructor) equals to
disabling validation as the method isn't a constructor. That setting
doesn't make too much sense on a method, rather one would use
@ValidateOnExecution(type = ExecutableType.CONSTRUCTORS) on a the
class-level or within validation.xml.

Seems like Jersey (and sorry for bringing implementation details here, but I
believe it is relevant) was using @ValidateOnExecution only for deciding
whether to validate return value of that method. When I fixed it, other
tests are not passing and I'm not sure what should be the correct behavior
in that case.
It definitely should validate both parameter and return value
constraints, or neither, based on the @ValidateOnExecution setting.
But there's no setting for having only method return values validated
but not their parameters.

Thanks and regards,

On 20/06/2017 07:48, Pavel Bucek wrote:

Hi Christian,

seems to be a Jersey bug.


On 19/06/2017 20:39, Christian Kaltepoth wrote:

Hey everyone,

I've a question regarding JAX-RS and @ValidateOnExecution. Please have a
look at the following code:

@ValidateOnExecution(type = ExecutableType.NONE)
public String method( @QueryParam("q") @NotNull String query ) {
return "Resource method was invoked!";

What is the expected outcome for a request which doesn't contain any query
parameter and therefore violates the @NotNull constraint?

From my understanding the use of @ValidateOnExecution disables validation
and therefore the resource method must be called even if there is no query
parameter in the request URL. That's how RESTEasy handles this case.

But Jersey seems to completely ignore the @ValidateOnExecution annotation in
this example. Therefore Jersey validates the query parameter and returns
"400 Bad Request" without invoking the resource method.

Any thoughts on this?


Christian Kaltepoth

Join to automatically receive all group messages.