This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!