I want to export a page to PDF through the Java API. I cannot use the REST api of e.g Scroll PDF because, the event listener that should trigger the export also modifies a custom active object earlier. This change to the custom AO is however not reflected during the REST export. If I understand the docs correctly this is due the way Confluence handles sessions and transactions. A REST call is in a separate session and therefore cannot see the changes. If I would export through the Java API, it should be in the same session.
Scroll PDF Exporter does not expose any Java API to other plugins, so there is no way you could invoke it.
Furthermore exports are usually performed in a separate worker thread, which would not run in the scope of your transaction anyway.
Your best option would probably be to defer the export action until the transaction your event handler is running in has been commited.
AFAIK there still are no 'run-after-commit' event handlers so you would need to implement this on your own.
This is not trivial.
You could for example in your event handler submit sort of an export task along with the page revision from the event into an ExecutorService's queue, then when the task executes periodically (in individual transactions) poll the page manager for the page and check if it already returns your expected revision. Then launch the export by performing a REST API call. You'd also need to preserve the user context somehow so the REST API call is performed for the correct user.
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
Hi Community, Jessica here from the Confluence Product Marketing team! July’s community challenge is all about sharing pictures — and as an extension of our first post on what ...
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!
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