facebook

REST Tutorial Error

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #298883 Reply

    Using the REST Tutorial, I’m trying to figure out how to create a second @GET method that also takes a parameter.

    I’ve modified the CustomersResource file to include this method, but get the following error. The point here is not that I need another method to return the same data. But how to have a second @GET method that also uses a parameter like the default one in the sample.

    @GET
    @Path(“{anotherId}”)
    public Customer getCustomerAnotherId(@PathParam(“anotherId”) int cId) {
    return customerMap.get(cId);
    }

    Error when starting MyEclipse Tomcat Server:

    SEVERE: A resource, class com.myeclipseide.ws.CustomersResource, has ambiguous sub-resource method for HTTP method GET, URI path template {id}, and output mime-type: application/xml. The problematic mime-type sets (as defined by @Produces annotation at Java methods getCustomer and getCustomerAnotherId) are [application/xml] and [application/xml]

    Thank you

    #298905 Reply

    Brian Fernandes
    Moderator

    kayak,

    Since your second @GET is identical to the first in terms of the path, input and output it produces, there is no way in which the framework can distinguish between the existing @GET method and the one you added. If you want exactly the same output from another method, can you tell me why you are creating a second method at all?
    If you change the input or the output slightly (like add @Produces(“application/json”)) then the problem will no longer exist since the framework will examine the requested mime type and use that to determine which method to call. Another option would be for you to change @Path(“{anotherId}”) to @Path(“newmethod/{anotherId}”) to make the 2nd method available at a different path.

    Hope this helps.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: REST Tutorial Error

You must be logged in to post in the forum log in