users@jersey.java.net

[Jersey] Re: Adding grammar to the resources

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 1 Aug 2013 16:12:12 +0200

Hi Nick,

Please see inline…

On Aug 1, 2013, at 2:34 AM, Nick Khamis <symack_at_gmail.com> wrote:

> On Tue, Jul 30, 2013 at 7:39 AM, Jakub Podlesak <jakub.podlesak_at_oracle.com> wrote:
> 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
>
>
>
> Hello Guys,
>
> Thank you so much for your response. Not sure how elegant this hack would be as we keep adding search

Then rather than injecting individual query parameters, just inject the standard UriInfo
into your resource/resource method.

Please see the javadoc here:
https://jersey.java.net/apidocs/latest/jersey/javax/ws/rs/core/UriInfo.html

getQueryParameters is the method you need.

> criteria, (ie, search by type, region, date, etc...). Is there a better solution? The bug in the dispatching algorithm
> is a WONTFIX?

It is not really a bug IMHO. I would say things were designed that way.

~Jakub

>
> Kind Regards,
>
> Nick.