You can Edit Jira issue by writing your Json to OutputStream and check for the response code. If it is 401 then your jira issue will be successfully edited.
public String getAuthantication(String username, String password) {
String auth = new String(Base64.encode(username + ":" + password));
return auth;
}
public static HttpURLConnection urlConnection(URL url, String encoding) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
connection.setRequestProperty("Content-Type", "application/json");
return connection;
}
public void updateJiraIssue(JiraCQCredential jiraCq) throws IOException {
String summary = "Edit Jira Issue";
String description = "Testing of Jira Edit";
String assigne = "Any name who has jira account";
String issueType = "Bug";
String encodedAuthorizedUser = getAuthantication("pass your username", "pass your password");
URL url = new URL("http://bmh1060149:8181/rest/api/2/issue/WFM-90");
HttpURLConnection httpConnection = urlConnection(url, encodedAuthorizedUser);
httpConnection.setRequestMethod("PUT");
String jsonData = "{\"fields\" : {\"summary\":" + "\"" + summary + "\"" + ",\"description\": " + "\""
+ description + "\"" + " ," + "\"issuetype\": {\"name\": " + "\"" + issueType + "\""
+ " },\"assignee\": {\"name\":" + "\"" + assigne + "\"" + ",\"emailAddress\": \"abc@gmail.com\"}}}";
byte[] outputBytes = jsonData.getBytes("UTF-8");
httpConnection.setDoOutput(true);
OutputStream out = httpConnection.getOutputStream();
out.write(outputBytes);
int responseCode = httpConnection.getResponseCode();
if(responseCode == 401){
System.out.println("Issue updated successfully with the mentioned fields");
}
}
you can't pass your Json directly to httpConnection. So convert it to byte array and then write to OutputStream.