Guest User

Untitled

a guest
Feb 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public class JiraBug {
  2.  
  3. @SuppressWarnings({ "unchecked", "rawtypes", "resource", "deprecation" })
  4. public static String makeRequest(String path, JSONObject holder)
  5. throws Exception {
  6.  
  7. DefaultHttpClient httpclient = new DefaultHttpClient();
  8. HttpPost httpost = new HttpPost(path);
  9.  
  10. StringEntity se = new StringEntity(holder.toString());
  11. httpost.setEntity(se);
  12. httpost.setHeader("Accept", "application/json");
  13. httpost.setHeader("Content-type", "application/json");
  14.  
  15. ResponseHandler responseHandler = new BasicResponseHandler();
  16. String response = httpclient.execute(httpost, responseHandler);
  17. return response;
  18. }
  19. public static void main(String[] args){
  20. try {
  21. JSONObject jsonobj = new JSONObject();
  22. File jsonFile = new File("JiraBug.json");
  23. if (jsonFile.exists()){
  24. InputStream is = new FileInputStream("JiraBug.json");
  25. String jsonTxt = IOUtils.toString(is, "UTF-8");
  26. jsonobj = new JSONObject(jsonTxt);
  27. }
  28. makeRequest("https://*<<Our_Company_JIRA_Server>>*/rest/api/2/issue",jsonobj);
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32. }
  33.  
  34. {
  35. "fields": {
  36. "project":
  37. {
  38. "key": "TRAINING"
  39. },
  40. "summary": "Test Summary",
  41. "description": "Test Description",
  42. "issuetype": {
  43. "name": "Bug"
  44. },
  45. "priority": {
  46. "id":"2"
  47. }
  48.  
  49. org.apache.http.client.HttpResponseException: Bad Request
  50. at org.apache.http.impl.client.AbstractResponseHandler.handleResponse(AbstractResponseHandler.java:69)
  51. at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:65)
  52. at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:51)
  53. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)
  54. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
  55. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
  56. at Jira.Auto_Defect.JiraBug.makeRequest(JiraBug.java:58)
  57. at Jira.Auto_Defect.JiraBug.main(JiraBug.java:70)
Add Comment
Please, Sign In to add comment