Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes Rest jersey client passing json string to GET method for filter output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Rest jersey client passing json string to GET method for filter output" Watch "Rest jersey client passing json string to GET method for filter output" New topic
Author

Rest jersey client passing json string to GET method for filter output

aditya sam
Greenhorn

Joined: Jun 12, 2014
Posts: 1
Hi,
I want to pass string {"filters":{"keyword":"abc"}} in this format as filter or search parameter to GET method for REST api url.

I want to convert curl parameters to get method to jersey rest call, the inline curl when executed from linux box works for me
curl -i -H "accept: application/json" -H "Content-type: application/json" -X GET -d '{ "filters": { "keyword":"xyz" } }' ../v1/users?token=[api_token] .

I tried using the inline code but with less luck
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response2 = null;
MultivaluedMap<String, String> queryParams;
List<String> list = new ArrayList<String>();
list = Arrays.asList(new String[]{"{keyword:xyz}"});
String lst = (list.toString()).substring(1, list.toString().length()-1);
queryParams.add("filters", lst);
response2 = webResource.queryParams(queryParams).header("Content-Type", "application/json;charset=UTF-8").get(ClientResponse.class);
System.out.println("Response Code = "+response2.getStatus());
outputFilter = response2.getEntity(String.class);

Is there another way from where i can pass string as input paramters to GET method and retrieve the associated result Please suggest if there is any technique from where i can pass the above mentioned string to GET method and retrieve data as per filter applied
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rest jersey client passing json string to GET method for filter output