Re: Working in a Unit Test, not in Application
Daniel Dekany <[email protected]> Tue, 1 Sep 2015 08:38:27 +0200
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Have you checked if the `result` variable is indeed empty (like with
logging it or something direct)?
Have you checked what's in the `template` variable, if you toString
it?
Otherwise, JavaCC has this terrible habit of silently ending parsing
on I/O errors (which is also a problem in Velocity for example, not
just in FreeMarker). In 2.3.24 I have worked that around. So as a last
resort, try if with
http://freemarker.org/builds/2.3.24-nightly/freemarker.jar you get an
exception.
Tuesday, September 1, 2015, 4:28:27 AM, Peter Harrison wrote:
> I've written a wrapper around Freemarker for use in my application. My
> unit test runs the following template:
>
> <#assign hello="Goodbye cruel world">
> ${hello}
>
> And you get "Goodbye cruel world" as you would expect.
>
> But in my application, which runs inside Tomcat, the same template
> results in nothing. Nada. Exactly the same code, two different outcomes.
> Obviously something environmental, but I have no idea what.
>
> public class TemplatePlugin implements Plugin {
>
> @Autowired
> private ResourceController resourceController;
>
> @Override
> public Map<String,Object> process( Action action,
> Map<String,Object> context ) throws Exception{
> String resource =
> getResourceController().getResource(action.getResource());
>
> Configuration configuration = new Configuration();
> configuration.setDefaultEncoding("UTF-8");
>
> Template template = new Template(action.getResource(), new
> StringReader(resource), configuration);
> Writer output = new StringWriter();
> template.process(context, output);
> String result = output.toString();
> context.put(action.getResponse(), result);
> return context;
> }
>
> }
>
> ------------------------------------------------------------------------------
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
--
Thanks,
Daniel Dekany
------------------------------------------------------------------------------