-
Bug
-
Resolution: Fixed
-
Medium
-
5.2
See PLUGWEB-72 for additional context.
The Atlassian Webresource 3.0 release notes recommend that when upgrading, the PageBuilderService is a new component that should be wired by the host application.
When Confluence upgraded to WR 3.0, this was not done, and instead Confluence uses a legacy, backwards-compatible constructor in the WebResourceManager that constructs a new instance of the PageBuilderService in-line.
This is problematic for plugin developers as some parts of the old WebResourceManager API are now only available through the new PageBuilderService API, and the PageBuilderService is currently inaccessible to plugins.
To address this, Confluence's should declare the PageBuilderService as a top-level, plugin-available Spring bean, and change Confluence's WebResourceManager to call the correct WebResourceManagerImpl constructor.
[CONFSERVER-32379] PageBuilderService is not available to plugins since upgrade to Atlassian Plugins Webresource 3.0
Hi mr.chris.kent,
Unfortunately between Confluence 5.2 and Confluence 5.4.2 (inclusive) it is not possible to write plugin code which triggers the consumption of required resources, due to this bug. The only solution is to upgrade to Confluence 5.4.3 or higher.
But that doesn't sound like what you're trying to do?
How do I require my WebResources in a macro without the service?
You should still be able to use the WebResourceManager API to call requireResourcesForContext(contextString) to include arbitrary custom resources in a request. If that's not working, then that is probably a different (perhaps unreported) bug.
Hi,
I am trying to use the PageBuilderService in my plugin. I have a customer on 5.4.2, which gets an error "PageBuilderService" bean unknown. Which is exactly the issue, and fixed in 5.4.3. How do I require my WebResources in a macro without the service? Please help I have been hitting my head against a brick wall for weeks trying to fix this bug?
I have tried using spring to inject the bean in the constructor, obvious fail.
I now use the ContainerManager.getComponent("pageBuilderService") which I thought would work, but that gives the same error...
Thanks in advance
Ok, so not in the current 5.5 EAP, but will be in the next one from now. Thanks.
bob.swift@charter.net - it will be in the next 5.5 release, whatever version/milestone/EAP that ends up being - it's just sitting on the branch waiting to be released.
I see 5.4.3 is out now . Do you know what 5.5 EAP level this will be included in? Thanks.
Here's an example servlet that uses the PageBuilder Service:
package com.atlassian.confluence.test.servlet; import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext; import com.atlassian.confluence.content.render.xhtml.XhtmlException; import com.atlassian.confluence.renderer.PageContext; import com.atlassian.confluence.xhtml.api.XhtmlContent; import com.atlassian.webresource.api.assembler.PageBuilderService; import com.atlassian.webresource.api.assembler.WebResourceSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.stream.XMLStreamException; import java.io.IOException; import java.io.PrintWriter; public class TestRenderServlet extends HttpServlet { private final XhtmlContent xhtmlContent; private final PageBuilderService pageBuilderService; public TestRenderServlet(final XhtmlContent xhtmlContent, final PageBuilderService pageBuilderService) { this.xhtmlContent = xhtmlContent; this.pageBuilderService = pageBuilderService; } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String markupToRender = "<ac:structured-macro ac:name=\"code\"><ac:plain-text-body><![CDATA[public static void main(String[] args) \n" + "{\n" + " System.out.println(\"Hello, World!\");\n" + "}]]></ac:plain-text-body></ac:structured-macro>"; final String renderedMarkup; try { renderedMarkup = xhtmlContent.convertStorageToView(markupToRender, new DefaultConversionContext(new PageContext("ds"))); } catch (XMLStreamException e) { throw new ServletException(e.getMessage(), e); } catch (XhtmlException e) { throw new ServletException(e.getMessage(), e); } // Write out the resource tags required by the markup we rendered WebResourceSet webResourceSet = pageBuilderService.assembler().assembled().drainIncludedResources(); PrintWriter writer = resp.getWriter(); resp.setContentType("text/html"); writer.write("<html><head>"); webResourceSet.writeHtmlTags(writer, com.atlassian.webresource.api.UrlMode.AUTO); writer.write("</head><body>"); writer.write(renderedMarkup); writer.write("</body></html>"); } }
And here's what the HTML output of this servlet looks like:
yeah-yeah:~ jclark$ curl http://localhost:1990/confluence/plugins/servlet/test <html><head><link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/css/batch.css" media="all"> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/css/batch.css?media=print" media="print"> <!--[if lte IE 8]> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/css/batch.css?conditionalComment=lte+IE+8" media="all"> <![endif]--> <!--[if lte IE 9]> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/css/batch.css?conditionalComment=lte+IE+9" media="all"> <![endif]--> <!--[if lt IE 9]> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/css/batch.css?source=webContextStatic&conditionalComment=lt+IE+9" media="all"> <![endif]--> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/shCore.css" media="all"> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/collapseSource.css" media="all"> <link type="text/css" rel="stylesheet" href="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:sh-theme-confluence/shThemeConfluence.css" media="all"> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/js/batch.js" ></script> <!--[if lte IE 8]> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/3/_/download/superbatch/js/batch.js?conditionalComment=lte+IE+8" ></script> <![endif]--> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/shCore.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/collapseSource.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/shLegacy.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter/shInit.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushAppleScript.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushAS3.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushBash.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushColdFusion.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushCpp.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushCSharp.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushCss.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushDelphi.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushDiff.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushErlang.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushGroovy.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushJava.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushJavaFX.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushJScript.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushPerl.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushPhp.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushPlain.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushPowerShell.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushPython.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushRuby.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushSass.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushScala.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushSql.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushVb.js" ></script> <script type="text/javascript" src="/confluence/s/d41d8cd98f00b204e9800998ecf8427e/en_GB-1988229788/4731/NOCACHE1/2.1.3/_/download/resources/com.atlassian.confluence.ext.newcode-macro-plugin:syntaxhighlighter-brushes/shBrushXml.js" ></script> </head><body><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script type="syntaxhighlighter" class="theme: Confluence; brush: java; gutter: false"><![CDATA[public static void main(String[] args) { System.out.println("Hello, World!"); }]]></script>
So, from PLUGWEB-72, we would need to do something like the following to get a WebResourceSet:
pageBuilderService.assembler().assembled().drainIncludedResources()
Yes, that's correct.
How do we get a pageBuilderService from the WebResourceManager?
The PageBuilderService will be an injectable spring component of the type com.atlassian.plugin.webresource.assembler.PageBuilderService
Will this required a compile level change to access?
The PageBuilderService class is new in Atlassian WebResource 3.0, so you will need to compile your plugin against a version of Confluence that bundles it in order to interact with this class. Alternatively you could use ContainerManager.getComponent("pageBuilderService") and then use reflection to late-bind to this class.
Once the change is merged into Confluence I will post some example code for you.
- So, from PLUGWEB-72, we would need to do something like the following to get a WebResourceSet:
pageBuilderService.assembler().assembled().drainIncludedResources()
- How do we get a pageBuilderService from the WebResourceManager?
- Will this required a compile level change to access?
- When would it be possible to get a Confluence version to test with?
Thanks
Hi Joseph,
I had 2 problems, first was this bug above, which I tried to work around and eventually found the old way to load resources as you suggested. This was on Confluence 5.4.2.
The second problem was the resource I was loading was AUI:Dialog2. So you can probably see why I was tearing my hair out. It wasn't until I found a comment on a post by a wise man that eluded me to the fact that AUI and Confluence versions are different and the mapping as to when Dialog2 was introduced was in AUI version 5.3, which I assumed was Confluence version, but only found out a few days ago, that this refers to Confluence 5.5.
Anyway, so I now know that my plugin is not compatible with anything before 5.5 and so my problem disappears. The only issue is that I have users on 5.4.2 who want my new features - oh well
P.S. In the AUI Documentation pages, it would have been (would be) REALLY REALLY helpful to have a link to the mapping of this library to your products... This would have saved me weeks of pain. see https://bitbucket.org/atlassian/aui-adg/wiki/versions/product-version-matrix