cancel
Showing results for 
Search instead for 
Did you mean: 

Encoding issues with webscript

upforsin
Star Collaborator
Star Collaborator

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 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

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 answer in original post

5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator

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
Star Collaborator
Star Collaborator

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
Legendary Innovator
Legendary Innovator

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
Star Collaborator
Star Collaborator

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
Champ in-the-making
Champ in-the-making

Thanks for the information..!!