Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Sent Events not working in Chrome

i am developing a web application with angular 4 and java. I am using server sent events to send some text data to the frontend. In the backend i am using jersey and this is my backend code

eventOutput.write(new OutboundEvent.Builder()
       .id(decodedToken)
       .name("responseBody")
       .data(String.class, respBody.toString()).build());

Frontend i am using angular 4 and the code looks like

var evtSource = new EventSource("url");
 source.addEventListener('eventName', (event) => {
    console.log(event);
});

Everything works fine in Mozilla firefox. When i use chrome with tomcat and windows everything works fine. But with tomcat+linux and chrome, i see the error in the console.as

EventSource's response has a charset ("iso-8859-1") that is not UTF-8. Aborting the connection.

What could be the issue. What is the fix? Please help. Any help would be appreciated. Thanks.

like image 329
Vikhyath Maiya Avatar asked Apr 12 '18 11:04

Vikhyath Maiya


1 Answers

Tomcat supports charset : iso-8859-1 by default. Please try

@Produces("application/json;charset=UTF-8")
eventOutput.write(new OutboundEvent.Builder()
       .id(decodedToken)
       .name("responseBody")
       .data(String.class, respBody.toString()).build());
like image 74
Arielle Nguyen Avatar answered Nov 02 '22 23:11

Arielle Nguyen