Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-8658

Programmatic rendering

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Won't Do
    • Neutral
    • None
    • None
    • None
    • None

    Description

      Steps to reproduce

      1. Duplicate https://demo.magnolia-cms.com/.magnolia/admincentral#app:groovy:browser;/samples/commands/GroovyMailCommand:null:
      2. https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:groovy:detail;/samples/commands/GroovyMailCommand0:edit Edit the duplicated script and add this content:
      3. package samples.commands;
        
        import info.magnolia.rendering.engine.*;
        import info.magnolia.rendering.context.*;
        import info.magnolia.objectfactory.Components;
        import info.magnolia.commands.CommandsManager;
        import info.magnolia.commands.impl.*;
        import org.apache.commons.lang3.text.StrBuilder;
        
        public class ProgrammaticRenderCommand extends BaseRepositoryCommand {
        
            @Override
            public boolean execute(Context context) throws Exception {
        
                def node = context.getJCRSession("website").getNode("/travel/about");
        
                final StrBuilder out = new StrBuilder();
                AppendableOnlyOutputProvider outputProvider = new AppendableOnlyOutputProvider(out);
        
                RenderingEngine renderingEngine = Components.getComponent(RenderingEngine.class);
                renderingEngine.render(node, outputProvider);
                
                def resources = context.getJCRSession("resources");
                def rendered = NodeUtil.createPath(resources.getRootNode(), "rendered", "mgnl:content");
                rendered.setProperty("text", out.toString());
                resources.save();
                return true;
            }
        }
        
      1. Save changes.
      2. Set https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:configuration:browser;/modules/publishing-core/commands/default/publish@class:treeview: to samples.commands.ProgrammaticRenderCommand (we misuse the publication command for simplicity but we are on public instance so the command shouldn't be used)
      3. Publish something (e.g. https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:configuration:browser;/modules/publishing-core/commands/default/publish:treeview:)
      4. The page is rendered and saved to the resources workspace. This is working fine as we reuse the request created when clicking the action. See https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:resources:view;/rendered:edit.
      5. Try to do the step 3. but this time Publish recursively. (this action  is configured to run asynchronously)
      6. This fails with NullPointerException as rendering misses a request.

      Expected results

      I can render content without a web request (asynchronously).

      Actual results

      The process fails on missing web context.

      Workaround

      Programmatically create http request with all that information against Magnolia and capture rendered content.

      Development notes

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                Unassigned Unassigned
                rkovarik Roman Kovařík
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Task DoD