Hello,
I wrote up a repo webscript which uses some Java logic to pass data to the Freemarker template.
Everything works great when I use I on the Alfresco Community Edition 6.1.2 on Docker.
However, when I try to apply my webscript (using .amp files) to the Alfresco Community Edition 6.1.2 without Docker, webscript returns data with bad encoding. (it looks like it is using Windows-1250 instead of the casual UTF ).
Thus, I suppose it is a problem with the installation.
Does anyone have any idea could it can be solved?
Solved! Go to Solution.
Java always uses Unicode internally, BUT if you read / write from/to files and do not explicitly specify the file encodings as part of that read / write, then it will use the system encoding by default, unless configured via the -D flag you mentioned. Even though my development environment runs on Windows, I have ensured that all files I read / write during development or Alfresco runtime are properly maintained and accessed using UTF-8 even without that -D parameter.
I have never seen this kind of behaviour as web scripts backed by Freemarker templates typically stream in the in-memory String result of said web script, and since Java uses Unicode internally, that has always been UTF-8 for me - and I have been using Windows-based systems for development extensively, until recently.
Are you by any chance using temporary file storage as a buffer for the template output, e.g. streaming the result from the locally stored file instead from the in-memory String? That way I could imagine the Windows encoding could creep in somehow...
Strange, but Java indeed was the case. I also thought it uses UTF-8 by default but it seems like it was not. I had to add Java parameter
-Dfile.encoding=UTF-8
Java always uses Unicode internally, BUT if you read / write from/to files and do not explicitly specify the file encodings as part of that read / write, then it will use the system encoding by default, unless configured via the -D flag you mentioned. Even though my development environment runs on Windows, I have ensured that all files I read / write during development or Alfresco runtime are properly maintained and accessed using UTF-8 even without that -D parameter.
Alright, thank you for the advice. Just like you said, previously I forgot to specify the file encodings while reading a file. Specifying it, also solved the issue.
Thanks for the information..!!
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.