users@jersey.java.net

[Jersey] Re: How to catch the response in case of an invalid query paramter

From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
Date: Fri, 15 Apr 2011 04:12:53 +0200

Or 400 BAD REQUEST, the problem is with the client, not the server.

2011/4/15 Rob - <skyscrapper666_at_hotmail.com>

> I'd declare "age" as a string and handle the validation myself. If error
> then return a 500 status code.
>
> No real benefits having "age" declared as integer (to my eyes).
>
> > Date: Thu, 14 Apr 2011 12:42:57 +0200
> > From: pengfei.di_at_match2blue.com
> > To: users_at_jersey.java.net
> > Subject: [Jersey] How to catch the response in case of an invalid query
> paramter
>
> >
> > Hello,
> >
> > I have a very simple GET REST API, which returns something only based on
> > the query parameter. For example:
> > @GET
> > @Path("get")
> > public MyClass getSomething ( @QueryParam("age") Integer age);
> >
> > As listed above, I specify the parameter type as Integer. However,
> > problem occurs when the given parameter cannot be parse to an integer.
> > For an instance: if the parameter is set as "age=one" instead of
> > "age=1", Jersey server will say "HTTP status 404 - Not Found."
> >
> > What I want to do is to specify the response by myself, but I have no
> > idea where I can do it. Shouldn't Jersey throw an
> > NumberFormatException. In fact, it doesn't. :(
> >
> > Thanks for any hint
> > Pengfei
> >
> >
>