Authorization Error 401 occur if calling a Rest Api from Jira Gadget Rest Resource Edited

I am writing a Jira Gadget. For that i have added a rest resource. I have passed oAuth for the currentUser to the gadget and thats working fine when i fetch the projects/issues (using the same oAuth, i have passed to). but when i need to call some tempo rest api's methods in Rest Resource, it throws 401 Authorization error. when i add basic authorization, it works perfect. My problem is that i can not know basic authorization of current user.  My xml for gadget is 

baseUrl: "__ATLASSIAN_BASE_URL__",
useOauth: "/rest/gadget/1.0/currentUser",
view: {
//somexml
}

 

My code in rest resource looks something like below (thats working perfect.)

 

JqlQueryBuilder jqlBuilder = JqlQueryBuilder.newBuilder();
JqlClauseBuilder clauseBuilder = JqlQueryBuilder.newClauseBuilder();
clauseBuilder = jqlBuilder.where().project(projectid);

final SearchResults results = searchProvider.search(appUser,clauseBuilder.buildQuery(), PagerFilter.getUnlimitedFilter());

 

Following is the problemetic area 

 

String formatedURL = baseURL + "/rest/tempo-planning/1/allocation?startDate=" + StartPlannedDate + "&endDate=" + EndPlannedDate + "&planItemId=" + Long.toString(plan_item_id);

URL url = new URL(formatedURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//When i un-comment below authorization line; it gives me results, but when i comment below authorization line, it throws 401 error.

//conn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

if (conn.getResponseCode() != 200) {
log.warn("code forecasted 200");
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
else
{
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;

while ((output = br.readLine()) != null) {

//some code here

}

1 answer

0 votes

Hi! This looks like a developer question, so it would be better to post it at community.developer.atlassian.com that's where our developer community hangs out :)

Regards,

Ana

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

26,531 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you