Guest User

Untitled

a guest
Mar 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.net.URI;
  5. import java.net.URL;
  6. import java.net.URLDecoder;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.Map;
  11.  
  12. import javax.ws.rs.client.Client;
  13. import javax.ws.rs.client.ClientBuilder;
  14. import javax.ws.rs.client.Entity;
  15. import javax.ws.rs.client.Invocation;
  16. import javax.ws.rs.client.WebTarget;
  17. import javax.ws.rs.core.Form;
  18. import javax.ws.rs.core.GenericType;
  19. import javax.ws.rs.core.MediaType;
  20. import javax.ws.rs.core.MultivaluedHashMap;
  21. import javax.ws.rs.core.MultivaluedMap;
  22. import javax.ws.rs.core.Response;
  23. import javax.ws.rs.core.MediaType;
  24. import javax.ws.rs.PUT;
  25. import javax.ws.rs.Consumes;
  26.  
  27. import org.apache.log4j.Logger;
  28. import org.json.simple.JSONArray;
  29. import org.json.simple.JSONObject;
  30. import org.json.simple.parser.JSONParser;
  31.  
  32. void updateComments (String CommentToUpdate)
  33.  
  34. {
  35.  
  36. String url = "http://host:port/<appl>/rest/resourceupdate";
  37. //I am building a JSON object
  38.  
  39. JSONObject inputObj = new JSONObject();
  40.  
  41. //Add all the Inputs
  42. inputObj.put("ids", id);
  43. inputObj.put("name", name);
  44.  
  45. //we need add the comments as a List
  46.  
  47. JSONObject commentObj = new JSONObject();
  48.  
  49. commentObj.put("comment", CommentToUpdate);
  50.  
  51.  
  52. SONArray list = new JSONArray();
  53. list.add(commentObj);
  54.  
  55. inputObj.put("comment", list);
  56.  
  57. Client client = ClientBuilder.newClient()
  58.  
  59. WebTarget base = client.target(url);
  60.  
  61. //But I am unable to figureout how I can send the above JSON object to the
  62. //put method
  63.  
  64. Response response = base.request().put();
  65.  
  66. }
Add Comment
Please, Sign In to add comment