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
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.