OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.14k stars 587 forks source link

Certain Chinese characters fail to be sent properly to the client when using SSE in a JAXRS endpoint #19084

Open troy-bishop opened 2 years ago

troy-bishop commented 2 years ago

Describe the bug
A server-sent event based API does not return the proper Chinese string when invoked.

Steps to Reproduce
The following code shows the problem:

    /**
     *
     * @param eventSink
     * @param sse
     */
    @GET
    @Path("testSSE")
    @Produces(MediaType.SERVER_SENT_EVENTS)
    public Response testSSE(@Context final HttpHeaders headers, @Context final SseEventSink eventSink,
            @Context final Sse sse) {

        try (SseEventSink sink = eventSink) {
            String data = "正在查詢服務埠";
            OutboundSseEvent event = sse.newEventBuilder().mediaType(MediaType.TEXT_PLAIN_TYPE).name("monitor").id("0")
                    .data(String.class, data).build();
            sink.send(event);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        return Response.ok().build();
    }

The client receives the output:

event: monitor
id: 0
data: 正在查詢�?務埠

Expected behavior

The received response should be:

event: monitor
id: 0
data: 正在查詢服務埠

Diagnostic information:

troy-bishop commented 2 years ago

logs.zip

troy-bishop commented 2 years ago

In the attached log, I started the Liberty server, invoked the API https://localhost:9443/ZDTREST/zdtrs/devServices/testSSE which runs the code mentioned above, and then stopped the Liberty server.

troy-bishop commented 2 years ago

Here's a copy of my server.xml, if it matters: server.zip