How to get resource and REST API urls in Jira?

Vilx- March 14, 2017

I'm trying to write a basic report plugin but the incomplete documentation is giving me serious trouble. I'll continue looking but also post a question here in case I can get an answer here faster.

Note - I'm new to Java, but I've been developing ASP.NET webpages for over 10 years now so I'm not a newbie programmer.

In my plugin I need the URLs for two things - a web resource and the REST API. I need them in my velocity view, although if I'd prefer to get them in Java.

One method that worked for the resource was:

$webResourceManager.getStaticPluginResource("com.my.plugin:my-report", "path/to/web/resource")

However I now read that WebResourceManager is on its way out, so I need a more modern alternative. I haven't found one.

The other thing is the REST API - that I cannot find anywhere. I suspect that I should just get some application base URL and then slap /rest/api/2/... but where can I get the base URL? Or should I assume that the application will always be hosted at /jira?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Vilx- March 14, 2017

OK, I think I finally came up with a way. Perhaps it's not the best way - comment then.

ComponentAccessor.getWebResourceUrlProvider().getStaticPluginResourceUrl ("com.my.plugin:my-report", "path/to/web/resource", UrlMode.AUTO );
 
ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);

The second one doesn't give a direct REST URL, however it gives a JIRA base url, so you can take it from there. I'm going to just keep the path part and create a relative URL from it.

As I understand, it should also be possible to inject these components into my plugin class via the constructor, but somehow that doesn't work for me - JIRA complains at runtime that such a component cannot be found. I'm probably doing something wrong, but I don't know what. However this approach works perfectly.

TAGS
AUG Leaders

Atlassian Community Events