-
Improvement
-
Resolution: Won't Do
-
Neutral
-
None
-
None
-
None
-
None
Steps to reproduce
- Duplicate https://demo.magnolia-cms.com/.magnolia/admincentral#app:groovy:browser;/samples/commands/GroovyMailCommand:null:
- https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:groovy:detail;/samples/commands/GroovyMailCommand0:edit Edit the duplicated script and add this content:
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; } }
- Save changes.
- 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)
- Publish something (e.g. https://demopublic.magnolia-cms.com/.magnolia/admincentral#app:configuration:browser;/modules/publishing-core/commands/default/publish:treeview:)
- 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.
- Try to do the step 3. but this time Publish recursively. (this action is configured to run asynchronously)
- 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
- Rendering engine needs renderingContext from request
- Renderer doesn't check if WebContext is null since
MAGNOLIA-6452 - FreemarkerRenderer doesn't check if WebContext is null since
MAGNOLIA-4165(Magnolia 4.5) - Area element needs WebContext since SCRUM-517 (Magnolia 4.5)
- even assuming all the above is worked around, site renderer still needs request by its nature
- we can't be sure no template script is accessing web context / request / aggregationState...
Acceptance criteria
- caused by
-
MAGNOLIA-6452 Add contentType field to renderers
- Closed
-
MAGNOLIA-4165 rendering: implement new rendering
- Closed
-
MAGNOLIA-7543 Make page editors attributes configurable
- Closed
- links to