JAX-RS validation of params
phhoef opened this issue · comments
Hi all,
I am sorry to bother you again, but I ran into another problem and I am stuck.
As some of you know, I am building a OSGi enRoute R7 based application. One bundle provides a rest service that relies on the HTTP whiteboard pattern.
The service will be registered and has two @QueryParam
s - this is working.
So, calling this url is working as expected:
http://localhost:8080/serverInfo?repoName=ZC
But now I would like to do some validation of the params.
My understand of JAX-RS is, that I can add the @NotNull
annotation of the javax.validation.constraints
package.
So, I added the maven dependency and the annotation to both params.
But when I call the service without providing these params, the method will be executed.
My expectation was, that the method will not be invoked, as the params were both null and the condition is not met.
I double checked and the following URL results in null
values for the variables.
http://localhost:8080/serverInfo
I extended my small sample application to show what I did.
You can find my rest bundle implementation here.
Is the validation not support by the whiteboard pattern or do I miss something?
Thanks
Is the validation not support by the whiteboard pattern or do I miss something?
Support for validation is an optional addition to the JAX-RS specification available when you have a validation provider installed. The JAX-RS whiteboard is therefore silent on the subject because it doesn't relate to JAX-RS, but to the Java EE validation specification.
If you want to use validation then you will need to have a validation provider available to your whiteboard implementation. Adding this would be an implementation specific task, and is therefore best asked on the mailing list for the implementation. In this case that's the Aries JAX-RS whiteboard.
thanks for your explanation @timothyjward.
If I understood you right, it is quite a big deal to implement the validation provider?
So, probably the easiest solution would be to check the params by myself with some if statements
.
Something like this:
if(repoName == null) throw new BadRequestException("repoName is missing");
If I understood you right, it is quite a big deal to implement the validation provider?
Yes, it's a full Java EE specification (just like JAX-RS). The reference implementation is provided by Hibernate. Integrating it with JAX-RS would involve plugging the validation provider into the JAX-RS container, which is why I say that it would be implementation specific. Each whiteboard implementation needs to plug validation into their JAX-RS provider using internal method calls/configuration.
So, probably the easiest solution would be to check the params by myself with some if statements.
Something like this:
if(repoName == null) throw new BadRequestException("repoName is missing");
That would certainly be quick and easy.
thanks, I'll do it myself :-)