jql works from browser but not from java

Scott Patterson January 26, 2018

I have a simple jql query that works from the browser but fails from java.  The java will return populated results for other queries but not the simple "key=" query.  If I take the url for the simple query and paste it into a browser, it will return the expected, populated json.  For the simple query it returns:

{"total":0,"maxResults":50,"issues":[],"startAt":0}

 

Uncommenting either of the other "Sting jql=" lines they will return values in the json.

Have to assume this is something simple but I do not see it or find it in the doc.

 

Code snippet from simple demo app

//***************************

// String jql = "type = bug and updatedDate >= startOfMonth()";

// String jql = "project = DEMO AND type = bug AND updatedDate >= startOfDay()";

String jql = "issueKey=DEMO-28940";

 

String url = "https://jira.myco.com/rest/api/latest/search?jql=" + URLEncoder.encode (jql, "UTF-8");

//**the output of this println pasted into a browser returns the expected, populated json.

System.out.println(url);

 

HttpClient httpClient = HttpClientBuilder.create().build();

HttpGet getRequest = new HttpGet(url);

getRequest.setHeader("Authorization", "Basic " + hashedAuth);

getRequest.addHeader("accept", "application/json");

 try {

HttpResponse response = httpClient.execute(getRequest);

int statusCode = response.getStatusLine().getStatusCode();

 

System.out.println(response.getStatusLine().getStatusCode());

//** statusCode is 200

if (statusCode == 200) {

BufferedReader br = new BufferedReader(

                        new InputStreamReader((response.getEntity().getContent())));

 

JSONParser parser = new JSONParser();

Object replyObj = parser.parse(br);

JSONObject jsonObject = (JSONObject) replyObj;

System.out.println(jsonObject.toString());

//** prints    {"total":0,"maxResults":50,"issues":[],"startAt":0}

 

4 answers

1 accepted

0 votes
Answer accepted
Scott Patterson January 28, 2018

I do not understand the underlaying issue, however it has to do with privileges.  Granting the user specific rights to the project enabled "issueKey=".

1 vote
Scott Patterson January 10, 2019

We were able to address the issue by adjusting Jira privileges for the querying user.  

0 votes
fatma January 10, 2019

did you get any answer .

appears i have the same issue.

2.6.0.0

0 votes
Sebastian Kleinholz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2018

A good point how to start debugging is using a REST Client. I can recommend the "Rest Client" Extension for Firefox - but there are many others out there.

Then copy the Jira request 1:1 to the REST Bowser and see what happens. And vice versa.

Scott Patterson January 28, 2018

Thanks for the reply.  Reproduced identical results via postman.

I do not believe this is a client side issue per se.  The service returns a response and a 200 status.  

Appears any working query starts to fail if the issueKey=DEMO-28940 phrase is added to a REST call.  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events