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

From: Ryan Stewart <>
Date: Mon, 18 Apr 2011 10:02:09 -0500

On Mon, Apr 18, 2011 at 1:30 AM, Jason Erickson <>wrote:

> Contrary to what Ryan says, you can use a query parameter to choose
> between two resources. In fact, in a way, thatís always what youíre doing
> if the query parameter actually affects what gets returned.
> Semantically, what you say is true. I was referring to a situation like
this in a resource class:
    public Foo getFoo(@QueryParam("x") int x) {

    public Foo getFoo(@QueryParam("y") String y) {

In the two versions of Jersey I've used--1.2 and 1.4--that doesn't work
because you're trying to bind two different methods to the same request
signature, so to speak. You get an error message like this:
INFO: Initiating Jersey application, version 'Jersey: 1.4 09/11/2010 10:30
Apr 18, 2011 9:45:47 AM com.sun.jersey.spi.inject.Errors
SEVERE: The following errors and warnings have been detected with resource
and/or provider classes:
  SEVERE: Producing media type conflict. The resource methods public and public can produce the same media type

Has something changed to allow that to work?

> Ryan,
> It is what it is. You build an application with the JAX-RS implementation
> you have, not the one you wish you had. Have you thought about using an
> ExceptionMapper? It doesnít sound like quite the fit you are looking for,
> but maybe itís close enough to work.
> But what exception would you map? Is it an exception that's eligible for
mapping that causes the 404 to be returned? That would be fine with me. Like
the OP, I just don't know how or where to trap this error and prevent the
404 from going out.