Re: Working in a Unit Test, not in Application

Evangelia Dendramis <[email protected]> Mon, 31 Aug 2015 20:39:18 -0700
Newsgroups gmane.comp.web.freemarker.user
Message-ID <CACZMt7zVWBHRWu+rj8MTWg9FXoj3VEAnUN4g_qmKfqpvF_o0+w@mail.gmail.com>
--===============7722421051281453207==
Content-Type: multipart/alternative; boundary=089e01161070821101051ea74b25

--089e01161070821101051ea74b25
Content-Type: text/plain; charset=UTF-8

Are there any errors in the Tomcat log?

On Monday, August 31, 2015, Peter Harrison <[email protected]>
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] <javascript:;>
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--089e01161070821101051ea74b25
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Are there any errors in the Tomcat log?<span></span>=C2=A0<br><br>On Monday=
, August 31, 2015, Peter Harrison &lt;<a href=3D"mailto:peter.harrison@call=
plus.co.nz">[email protected]</a>&gt; wrote:<br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex">I&#39;ve written a wrapper around Freemarker for use in my =
application. My<br>
unit test runs the following template:<br>
<br>
&lt;#assign hello=3D&quot;Goodbye cruel world&quot;&gt;<br>
${hello}<br>
<br>
And you get &quot;Goodbye cruel world&quot; as you would expect.<br>
<br>
But in my application, which runs inside Tomcat, the same template<br>
results in nothing. Nada. Exactly the same code, two different outcomes.<br=
>
Obviously something environmental, but I have no idea what.<br>
<br>
public class TemplatePlugin implements Plugin {<br>
<br>
=C2=A0 =C2=A0 =C2=A0@Autowired<br>
=C2=A0 =C2=A0 =C2=A0private ResourceController resourceController;<br>
<br>
=C2=A0 =C2=A0 =C2=A0@Override<br>
=C2=A0 =C2=A0 =C2=A0public Map&lt;String,Object&gt; process( Action action,=
<br>
Map&lt;String,Object&gt; context ) throws Exception{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0String resource =3D<br>
getResourceController().getResource(action.getResource());<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Configuration configuration =3D new Confi=
guration();<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0configuration.setDefaultEncoding(&quot;UT=
F-8&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Template template =3D new Template(action=
.getResource(), new<br>
StringReader(resource), configuration);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Writer output =3D new StringWriter();<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0template.process(context, output);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0String result =3D output.toString();<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context.put(action.getResponse(), result)=
;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return context;<br>
=C2=A0 =C2=A0 =C2=A0}<br>
<br>
}<br>
<br>
---------------------------------------------------------------------------=
---<br>
_______________________________________________<br>
FreeMarker-user mailing list<br>
<a href=3D"javascript:;" onclick=3D"_e(event, &#39;cvml&#39;, &#39;FreeMark=
[email protected]&#39;)">[email protected]<=
/a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/freemarker-user" ta=
rget=3D"_blank">https://lists.sourceforge.net/lists/listinfo/freemarker-use=
r</a><br>
</blockquote>

--089e01161070821101051ea74b25--


--===============7722421051281453207==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============7722421051281453207==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user

--===============7722421051281453207==--