08-23-2019 05:57 AM
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?
08-31-2019 08:45 AM
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.
08-27-2019 08:09 AM
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...
08-30-2019 12:20 PM
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
08-31-2019 08:45 AM
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.
08-31-2019 10:03 AM
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.
09-02-2019 06:09 AM
Thanks for the information..!!
Explore our Alfresco products with the links below. Use labels to filter content by product module.