Peter Harrison
2015-09-01 02:28:27 UTC
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;
}
}
------------------------------------------------------------------------------
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;
}
}
------------------------------------------------------------------------------