Need help I am trying to connect to XRAY JIRA using Rest API and want to execute a case but getting 400 error response at step inputStream=new InputStreamReader(con.getInputStream(),"UTF-8")
java.io.IOException: Server returned HTTP response code: 400 for URL:
My Code is below:
*HttpURLConnection con=null;
InputStreamReader inputStream=null;
URL jira_API_URL=new URL("https://jira.abc.com/rest/raven/latest/import/execution");
String encodeCredentials=Base64.getEncoder().encodeToString(
"kkris:testjira@234".getBytes("UTF-8"));
con=(HttpURLConnection)jira_API_URL.openConnection();
con.setRequestMethod("POST"); con.setDoOutput(true);
con.setRequestProperty("Autherization", "Basic "+encodeCredentials);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("X-Atlassian-Token", "nocheck");
try(OutputStream os=con.getOutputStream()){
byte[] input=json.toString().getBytes("UTF-8");
os.write(input,0,input.length);
}
inputStream=new InputStreamReader(con.getInputStream(),"UTF-8");*
Note :Would like to add that I am able to hit this RestAPI using postman and Restassured & able to execute testcase in XRAYJIRA successfully
Well, first of all we need to clarify if you have Xray on Jira server/datacenter or Xray on Jira cloud, as they are different products and the APIs are also slightly different. From your example, it seems that you're targetting Xray on Jira server/datacenter, and that you aim to import results using the Xray JSON format and respective endpoint as detailed here . The endpoint URL in that case should either be <jira_base_url>/rest/raven/1.0/import/execution or <jira_base_url>/rest/raven/2.0/import/execution
Also, please make sure the Xray JSON content you submit follows this syntax .
Note: you may want to have a look at this repo which contains some sample code for submiting results in Java and other languages, including a proof-of-concept client api .
The response body content may show you clues about what's wrong. You can start by using curl
utility first as shown here and then implement the java code.
curl -H "Content-Type: application/json" -X POST -u admin:admin --data @data.json http://yourserver/rest/raven/1.0/import/execution
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.