Skip to content

Fix rendering outside a web request in non TEST env (#60) - #61

Open
billgonemad wants to merge 5 commits into
7.0.xfrom
fix/60-render-outside-web-request
Open

billgonemad wants to merge 5 commits into
7.0.xfrom
fix/60-render-outside-web-request

Conversation

@billgonemad

Copy link
Copy Markdown
Collaborator

Fixes #60

Problem

Since 364bd4e, RenderEnvironment only bound a web request in the TEST environment. In production/development, rendering off-request (jobs, async tasks, BootStrap) NPE'd as soon as a template used a taglib.

Fix

  • No request bound: binds a GrailsWebRequest over Grails' servlet-free PageRenderer stubs (the same ones groovyPageRenderer uses). It uses the real context path and runs request-scoped cleanup.
  • Request already bound: reuses the caller's request, so session, flash, params and request attributes keep working. Only out, the locale resolver and WrappedResponseHolder are swapped, and they are restored afterwards.
  • The caller's request state is always restored, including on exceptions and nested renders.

Behaviour change

Off-request, session, without grails.serverURLthrow UnsupportedOperationExceptionin all environments. They already NPE'd in production on 7.0.x, but in TEST they used to work, so downstream test suites may notice. Setgrails.serverURL`.

Testing

New integration specs force grails.env=production, since TEST hid the bug. 14 of the 18 new tests fail against 7.0.x. ./gradlew check build docs :example:integrationTest: 90 tests, 0 failures.

…#60)

RenderEnvironment only bound a request in the TEST environment and relied on spring-test mocks, so rendering from jobs/async tasks in production NPE'd in taglibs. Use PageRenderer's request/response proxies in every environment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rendering outside of web requests not working anymore

1 participant