0

The required URL should be something like this :

http://<host>:<port>/path/item?<arguments>

The arguments key and value supposed to be multiple and dynamic, so I cannot use @BeanParam or @QueryParam. Also I can only call this interface without implementation.

My current code is something like this :

public interface RestService {

    @GET
    @Path("/path/item")
    @Produces(MediaType.APPLICATION_JSON)
    public JsonNode method(@QueryParam("params") String params);
}

Example of arguments that I want to pass : brand=myBrand&price=myPrice

Is there any way to do something like this ?

My References :

  1. REST Web Service - Dynamic Query Parameters
  2. Passing indefinite Query Parameters with RESTful URL and reading them in RESTEasy
Community
  • 1
  • 1
Mrye
  • 699
  • 3
  • 10
  • 31

1 Answers1

0

Use UriInfo.getQueryParameters(), as following:

@GET
@Path("/path/item")
@Produces(MediaType.APPLICATION_JSON)
public JsonNode method(@Context UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
    ...
}

It returns a MultivaluedMap. Then just iterate over it.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
  • Thanks but currently I can only use interface. Is it possible to pass `Map` that contain each parameter name/value? But anyway I didn't use this method anymore. Seems like I cant send dynamic parameters. – Mrye Oct 11 '16 at 15:41