Issue
I'm trying to fetch issues from JIRA through the Jira Rest Api. When I use curl it's no problem, and I get the issues I want. The problem is that I want to do this through Java code (I use the maven changes plugin, with some small modifications), but the plugin doesn't find the issues. I get 200 status response, but the response doesn't contain any issues.
Here is a snippet from the Java code (the authentication is done in the setup):
WebClient client = setupWebClient(jiraUrl);
doSessionAuth(client);
client.replacePath("/rest/api/2/search");
client.type(MediaType.APPLICATION_JSON_TYPE);
client.accept(MediaType.APPLICATION_JSON_TYPE);
client.query("key", "<Issue-key>");
Response res = client.get();
This gives me a 200 response with this JSON:
{"startAt":0,"maxResults":50,"total":0,"issues":[]}
This is my curl request which gives me the expected ressult:
curl -u user:password -X GET -H "Content-Type:application/json" https://bankid.atlassian.net/rest/api/2/search?key=<Issue-key>&maxResults=10
I've also tried with using POST and a JSON query:
WebClient client = setupWebClient(jiraUrl);
doSessionAuth(client);
String jqlQuery = new JqlQueryBuilder(log).urlEncode(false).filter(filter).build();
StringWriter searchParamStringWriter = new StringWriter()
JsonGenerator gen = jsonFactory.createGenerator(searchParamStringWriter);
gen.writeStartObject();
gen.writeStringField("jql", jqlQuery);
gen.writeNumberField("maxResults", nbEntriesMax);
gen.writeArrayFieldStart("fields");
gen.writeString("*all");
gen.writeEndArray();
gen.writeEndObject();
gen.close();
client.replacePath("/rest/api/2/search");
client.type(MediaType.APPLICATION_JSON_TYPE);
client.accept(MediaType.APPLICATION_JSON_TYPE);
log.debug("JQL query [" + searchParamStringWriter.toString() + "]");
Response searchResponse = client.post(searchParamStringWriter.toString());
It's the same here. The corresponding curl gives me the expected result (one issue), but this returns a 200 response but with no issues.
I can't seem to find out what's wrong. Any pointers? Also, is it possible to see exactly which path the client sends the request to (to make sure there isn't anything wrong with my set-up)? I've read through the API but haven't found anything.
Solution
Is that Apache CXF that you use to send the REST call?
In general if you notice a difference between what you try manually and what your code does, it helps to enable logging, so you can compare whether your code really does the same thing (probably not).
For Apache CXF, how to enable logging is described here:
Even if that does not help you immediately, it can be useful to add those logs to your question here to make it easier for other people to spot the problem.
Answered By - GlennV Answer Checked By - Dawn Plyler (WPSolving Volunteer)