Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Connection to JIRA using ZAPI not happening with rest client.

Achu Sasidharan Pillai May 22, 2018

Hi I need to connect to JIRA inorder to create test cycle and update the test status of the test while executing selenium automation.

PFB the code for connection.

public class RESTClient {

static String line = new String();
// static StringBuffer jsonString = new StringBuffer();
static String s = new String();
static BufferedReader rd = null;
static String encoding;
static URL url;
static String urlString = "http://<jiraurl>/rest/zapi/latest/execution?issueId=XXXX";
static String userPassword = "xxxx:xxxxx";

public static void main(String[] args) throws IOException{
try{
// retrieving data from server
url = new URL(urlString);
String payload="{\"lastTestResult\":{ \"executionStatus\": \"1\"}}"; 

byte[] bytesEncoded = Base64.getEncoder().encode(userPassword.getBytes());
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();

urlConnection.setConnectTimeout(15000);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
urlConnection.setDefaultUseCaches(false);
urlConnection.setAllowUserInteraction(true);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty ("Authorization", "Basic " + bytesEncoded);
urlConnection.connect();
OutputStreamWriter writer = new OutputStreamWriter(urlConnection.getOutputStream());
writer.write(payload);
writer.close();

rd = new BufferedReader (new InputStreamReader(urlConnection.getInputStream()));

while ((line = rd.readLine()) != null)
System.out.println(line);

System.out.println(s);

urlConnection.disconnect();
}catch (Exception e){
throw new RuntimeException(e.getMessage());
} }
}

Can anyone help me out please.. I have tried the same url and hit in the browser I was able to get the response. While while running the above code i am not able to.

0 answers

Suggest an answer

Log in or Sign up to answer