users@jersey.java.net

[Jersey] Re: Bean validation with Jersey 1.2

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 15 Mar 2017 15:41:18 +0100

Sajin, Nasir,

Jersey 1.x has a class called "RequestDispatcher [1], registrable by
registering provider ResourceMethodCustomInvokerDispatchProvider", which
is invoked before the actual resource method invocation happens. It has
access to java.lang.reflect.Method and AbstractResourceMethod (part of
Jersey model), and I believe that you could be able to relatively easily
plugin BV into your chain by implementing that.

[1]
https://github.com/jersey/jersey-1.x/blob/b73951e9186fb540675eac62aed622946be781ff/jersey-server/src/main/java/com/sun/jersey/spi/dispatch/RequestDispatcher.java
[2]
https://github.com/jersey/jersey-1.x/blob/b73951e9186fb540675eac62aed622946be781ff/jersey-server/src/main/java/com/sun/jersey/spi/container/ResourceMethodCustomInvokerDispatchProvider.java

Regards,
Pavel

On 15/03/2017 14:17, Nasir Rasul wrote:
> Hi Sajin
> You should be able to simply include the jar, use the annotation and
> call the validate method. It does require an extra call and not as
> convenient as using @Valid.
>
> I haven't tried doing, so not sure if you may run in dependency issues.
>
> Regards
> Nasir
>
> - Nasir
>
> On Sun, Mar 12, 2017 at 3:08 PM, Sajin Balakrishnan
> <sajin.balakrishnan_at_gmail.com <mailto:sajin.balakrishnan_at_gmail.com>>
> wrote:
>
> Thanks Pavel.
> Is there any alternative in Jersey 1.x to achieve bean validation
> before POST or PUT happens?
>
> On 12-Mar-2017 9:04 PM, "Pavel Bucek" <pavel.bucek_at_oracle.com
> <mailto:pavel.bucek_at_oracle.com>> wrote:
>
> Hi Sajin,
>
> Jersey 1.2 does not support bean validation.
>
> I was curious myself whether that could be possible; Jersey
> 1.2 was released on May 20th, 2010 and Bean validation API
> 1.0.0 on Oct 2009, so it is, unfortunately the first
> integration I know of was for JAX-RS 2.0, released as part of
> Java EE 7.
>
> You could try to port related code from Jersey 2.x to Jersey
> 1.x, but migrating your app to supported Java version seems
> like better time/money better spent.
>
> Regards,
> Pavel
>
>
> On 11/03/2017 12:14, Sajin Balakrishnan wrote:
>
> For one of our legacy java 1.5 application we are stuck
> with Jersey 1.2.
>
> Does jersey 1.2 support JSR-303 bean validation.
> If not how to provide bean validations?
>
>
>