I’m trying to do a parametrized get (aka search). I’m not sure why this is not working. We use the latest jersey dependencies (1.14) and so far all REST interfaces did work just fine.
Simple REST:
@Path("/some/path")
@Component
public class SomeRest {
@GET
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_JSON })
public Response getAll(MultivaluedMap<String, String> queryParams) {
// extract params, do search, return response as JSON
// (Using ObjectMapper.writeValue() to convert object to JSON String)
}
}
The workings of the method are not important I think, as the error states clearly it cannot enter it in the first place due to some unsupported Media type (when I enter my path in the browser):
HTTP Status 415 - Unsupported Media Type
Output is:
SEVERE: A message body reader for Java class javax.ws.rs.core.MultivaluedMap, and Java type javax.ws.rs.core.MultivaluedMap<java.lang.String, java.lang.String>, and MIME media type application/octet-stream was not found.
The registered message body readers compatible with the MIME media type are:
....
Anyone has an idea?
Thanks!
edit:
My goal is to implement a search by using query params with the GET resource. So that when I call /some/path I get all results, but if I call some/path?limit=10&offset=10 I get the second set of 10. I could solve that specific problem with query params but I also want to be able to define where clause params like name=foo in the same parameter map. And those parameters should be dynamic as I want to create a generic getAll method that can take any map of parameters on a GET call.
So the question I guess is: how do I implement dynamic query params?
I think you are confusing query parameters which are in the actual url:
someurl/resource?param1=value1¶m2=value2
form url encoded information is same format but the parameters are in the body. Since a GET request does not take a body, you either mean that you want to do a POST, or that you want to use query parameters instead of x-www-form-urlencoded.
Good luck!
EDIT:
You want to use either @QueryParam then if you know exactly what parameters are coming in, or @Context UriInfo if you are not sure how many/what query parameters are going to be expected in the URL.