Encoding issues with webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
upforsin
Senior Member

Encoding issues with webscript

Jump to solution

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 Win­dows­-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?

howkymike
Alfresco Developer
1 Solution

Accepted Solutions
afaust
Master

Re: Encoding issues with webscript

Jump 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.

View solution in original post

5 Replies
afaust
Master

Re: Encoding issues with webscript

Jump to solution

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...

upforsin
Senior Member

Re: Encoding issues with webscript

Jump to solution

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
howkymike
Alfresco Developer
afaust
Master

Re: Encoding issues with webscript

Jump 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.

upforsin
Senior Member

Re: Encoding issues with webscript

Jump to solution

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.

howkymike
Alfresco Developer
swapna31
Member II

Re: Encoding issues with webscript

Jump to solution

Thanks for the information..!!