users@jersey.java.net

[Jersey] ambiguous resource method for HTTP method

From: Javi Moran <fjmoranrua_at_gmail.com>
Date: Tue, 10 Mar 2009 17:51:42 +0100

Hello,

I am a newcomer to the jersey project, I am playing with the resources
and I have the following question/problem.

I have a class which is a resource and I added to it two methods with
the annotation @GET. I wanted one of them was the one invoked when in
the http request URL I had a paramater paramA and a second method to be
invoked when the http request I received had a parameter paramB. The
code is:

"
 @GET
    public String getParamA(@QueryParam("paramA") String paramA) {

        if (paramA == null) {
            throw new
WebApplicationException(Response.Status.PRECONDITION_FAILED);
        }

        return "Echo " + paramA;
    }

    @GET
    public String getParamB(@QueryParam("paramB") String paramB) {


        if (paramB == null) {
            throw new
WebApplicationException(Response.Status.PRECONDITION_FAILED);
        }
        return "Echo " + paramB;

    }
"

When I run this I get the runtime error:

GRAVE: A resource, class org.masterswl.rest.HelloWorldResource, has
ambiguous resource method for HTTP method GET and output mime-type:
text/plain. The problematic mime-type sets (as defined by @Produces
annotation at Java methods getParamA and getParamB) are [text/plain] and
[text/plain]
10-mar-2009 17:40:47
com.sun.jersey.server.impl.application.WebApplicationImpl
newResourceClass

com.sun.jersey.api.container.ContainerException: Fatal issues found at
class org.masterswl.rest.HelloWorldResource. See logs for more details.
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.newResourceClass(WebApplicationImpl.java:286)

So, the question is ?

   (*) Is there an error in jersey or in my installation or isn't
there ?
   (*) If there isn't an error, cannot you design the things in the way
I did ?

---
Javier Moran Rua