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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,865 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot