How access WebResourceManager from a velocity template in Jira 10?

Hi,

Migrating our app to Jira 10.
It uses a velocity template and a servlet to launch our frontend.

In the velocity template we have something like (which works in Jira 9):

<script type="text/javascript" src="$webResourceManager.getStaticPluginResource("org.example.app:javascript", $theAppJSFile)"></script>

but this doesn’t work in Jira 10.

The $theAppJSFile is provide by a TemplateRenderer context set in the servlet, e.g.:

templateRenderer.render("templates/theApp.vm", context, response.getWriter());

Running this in Jira 10 fails with nothing returned or rather the template rendering doesn’t seem to expand the $webResourceManager.getStaticPluginResource… part.

So guessing that there’s something that’s been moved around / replaced but hard to find the info in the sea of distributed info about Jira 10 and platform 7…

Greatly appreciate any pointers!

Thanks,
Fredrik

Hi @freatt,

That might be related to the removal of deprecated methods of WebResourceManager which were replaced mostly with methods from WebResourceUrlProvider. You can find a replacement method in the UPGRADE guide Bitbucket.

WebResourceManager#getStaticPluginResourceWebResourceUrlProvider#getStaticPluginResourceUrl

Hope that helps solve your problem

1 Like

Hi @FilipNowakowski,

Thanks that got me further and up and running!

I replaced the calls as described but at first it still failed.
The cause for this was that we in the old code (prior to Jira 10) called $webResourceManager#getStaticPluginResourceUrl(...) in the template file.

Simply replacing that with a call to $webResourceUrlProvider.getStaticPluginResourceUrl(...) in the template doesn’t work. So instead, I moved this into the Java code and add it to the context for the template renderer.

Voilà - up and running again!

So something like:

  @Inject
  public TheAppServlet(
      ...
      @ComponentImport final TemplateRenderer templateRenderer,
      @ComponentImport final WebResourceUrlProvider webResourceUrlProvider,
      ...) { 
    // <snip>
    this.templateRenderer = templateRenderer;
    this.webResourceUrlProvider = webResourceUrlProvider;
  }

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
      throws IOException, NumberFormatException {
  <snip>
    // Jira10 - Place our resources into the context here to make them available in the template:
   String theAppJsPath = 
      webResourceUrlProvider.getStaticPluginResourceUrl("se.findout.plugin.dependency-map:javascript", "theAppFile.js", UrlMode.RELATIVE);
   context.put("theAppJsPath", theAppJsPath);
    
   templateRenderer.render("templates/theApp.vm", context, response.getWriter());

and then in theApp.vm just used the context variables:

<script type="text/javascript" src="$theAppJsPath)"></script>

Thanks,
Fredrik