users@jersey.java.net

[Jersey] Re: validating query param inputs

From: phil swenson <phil.swenson_at_gmail.com>
Date: Tue, 21 Jan 2014 14:39:35 -0700

I’ve been unsuccessful in getting the bean validator configured properly.
 We are using our own (terrible) servlet container, so I have to manually
configure this support.

I already have configuration like so to register the JerseyServlet:

Config config = new Config("rest",
"org.glassfish.jersey.servlet.ServletContainer”);
config.addInitParameter("jersey.config.server.provider.packages",
"com.webmethods.optimize.service.rest”);

I tried adding in other settings like so:

config.addInitParameter("jersey.config.beanValidation.enableOutputValidationErrorEntity.server",
"true");

config.addInitParameter("jersey.config.server.resource.validation.disable",
"false");

config.addInitParameter("jersey.config.beanValidation.disable.validateOnExecutableCheck.server",
"false");

config.addInitParameter("jersey.config.server.resource.validation.ignoreErrors",
"false");

But I see no effect. If I put a @NotNull on a param a null can still get
through….

Any hints/ideas?

thanks




On Mon, Jan 20, 2014 at 3:02 PM, phil swenson <phil.swenson_at_gmail.com>wrote:

> thanks! turns I do have the bean validator in my proj, I suspect I just
> don’t have my build/config set up properly.
>
>
> On Mon, Jan 20, 2014 at 2:46 PM, Michal Gajdos <michal.gajdos_at_oracle.com>wrote:
>
>> If you're using GF 4.0 you have bean validation in Jersey out-of-the-box.
>> If you're using something else (Jetty, Tomcat, ...) you need to add
>> jersey-bean-validation module to your dependencies.
>>
>> You can find more information in our User Guide, Bean Validation Support
>> section - https://jersey.java.net/documentation/latest/bean-
>> validation.html
>>
>> Michal
>>
>>
>> On 20.01.2014, 22:33 , phil swenson wrote:
>>
>>> here is an example service I wrote:
>>>
>>> @GET
>>> @Path("/ProcessMetricData")
>>> @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML})
>>> public ProcessMetricData getProcessMetricData(@QueryParam("processModelId")
>>> String modelId, @QueryParam("startTime") long startTime,
>>> @QueryParam("endTime") long endTime, @NotNull @QueryParam("statsInterval")
>>> long statsInterval) {
>>>
>>> I want to validate that each query param is set by the client….
>>>
>>> Best I can tell there is no built in validation support in jersey (using
>>> 2.0)… can someone confirm?
>>>
>>> thanks,
>>> phil
>>>
>>
>>
>