1
votes

I'm trying to evaluate a GSP file without a real http request. I'm trying this:

String compileGsp(File input) {
        def text = ''
        try{
            text = groovyPagesTemplateEngine.createTemplate(input).make().toString()
        }
        catch( Exception e ){
            StackTraceUtils.sanitize(e).printStackTrace()
        }

        return text
    }

but this throws an exception and yields this:

java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

How can I evaluate GSPs without a request? If I use SimpleTemplateEngine, I get some functionality, but I lose all of the taglibs, which include request-void tags like <g:each>

1

1 Answers

1
votes

I guess you can mock the web request. This posting is probably what you are looking for.