users@jersey.java.net

[Jersey] Re: Adding grammar to the resources

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 30 Jul 2013 13:39:11 +0200

Hi Nick,

Cam is right, JAX-RS dispatch algorithm could not tell which
resource method to invoke.

What you can do instead is something like:

@GET
@Produces({MediaType.APPLICATION_JSON})
public List<Wine> findByName(@QueryParam("name") String name) {
  if (name != null) {
    return findByName(name);
  } else {
    return findAll();
  }

// removed JAX-RS annotations
public List<Wine> findAll() {…}

@Path("{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Wine findById(@PathParam("id") String id) {
  …
}

HTH,

~Jakub

On Jul 30, 2013, at 1:21 PM, Cameron Jones <cmhjones_at_gmail.com> wrote:

> Hi Nick,
>
> JAX-RS doesn't dispatch based on only differences in query parameters...see this bug which has been marked as WONTFIX:
>
> http://java.net/jira/browse/JAX_RS_SPEC-33
>
> Thanks,
> Cam
>
>
> On Tue, Jul 30, 2013 at 1:58 AM, Nick Khamis <symack_at_gmail.com> wrote:
> When I remove the @Path, I am getting the following error:
>
> These two methods produces and consumes exactly the same mime-types and
> therefore their invocation as a resource methods will always fail.
>
> I have:
>
> @Path("/wines")
> public class WineResource
>
> @GET
> @Produces({MediaType.APPLICATION_JSON})
> public List<Wine> findAll()
>
> @GET
> @Produces({MediaType.APPLICATION_JSON})
> public List<Wine> findByName(@QueryParam("name") String name)
>
> @GET
> @Produces({MediaType.APPLICATION_JSON})
> public Wine findById(@QueryParam("id") String id)
>
> Thanks in Advance,
>
> Nick.
>