I need to embed Vaadin app in a third party web page.
Web server and application server are in different domains.
Due to the nature of the application, using iframe is not an option. So I used VaadinXS add-on and embeded application inside a div.
Now my problem is:
Web page has non utf encoding (actually it is windows-1251).
And Vaadin servlet default encoding seems to be utf-8.
The question:
Is there a way to override character encoding for Vaadin UI.
public class MyHttpServletResponseWrapper extends
HttpServletResponseWrapper {
protected ByteArrayOutputStream byteArrayStream;
protected ServletOutputStream stream;
public MyHttpServletResponseWrapper(HttpServletResponse response) {
super(response);
byteArrayStream = new ByteArrayOutputStream();
stream = getNewServletOutputStream();
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
return stream;
}
private ServletOutputStream getNewServletOutputStream() {
ServletOutputStream stream = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
byteArrayStream.write(b);
}
};
return stream;
}
public byte[] getBytes(){
return byteArrayStream.toByteArray();
}
}
Now form fields and labels are rendered correctly, but if user enters values they arrive in wrong encoding.
I guess i have to decode request payload by myself. And convert it accordingly.
Any suggestions would be greatly appreciated.
Regards,
David.
Btw.
If AbstractCommunicationManager would respect request/response encoding information this issue would never be real issue.
Id would be sufficeint to set characterEncoding in request and response.
But deep in AbstractCommunicationManager’s
doHandleUidlRequest PrintWriter for response is created in the following way:
final PrintWriter outWriter = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(out, "UTF-8")));
never respecting if request/response character encoding is set.