users@jersey.java.net

[Jersey] Re: validating query param inputs

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Wed, 22 Jan 2014 09:02:42 +0100

Hi Phil,

nope. org.glassfish.hk2:bean-validator is repackaged (and OSGi-fied)
hibernate-validator that is used in GlassFish. You need
org.glassfish.jersey.ext:jersey-bean-validation that brings BV to Jersey
(and have transitive dependency on hibernate-validator & validation-api
so this one dependency should be enough).

HTH,
Michal

On 22.01.2014, 01:58 , phil swenson wrote:
> I believe so... here is the dependency: supplementalCompile(group:
> 'org.glassfish.hk2', name: 'bean-validator', version: '5.0.0')
>
>
>
> On Tue, Jan 21, 2014 at 3:34 PM, Michal Gajdos
> <michal.gajdos_at_oracle.com <mailto:michal.gajdos_at_oracle.com>> wrote:
>
> Do you have jersey-bean-validation module on the class-path of the
> server?
>
> Michal
>
>
> On 21.01.2014, 22:39 , phil swenson wrote:
>> 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 <mailto: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 <mailto: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
>>
>>
>>
>>
>
>