Curious User 123
Curious User 123

Reputation: 11

ServiceStack's ServerEventsClient client can't process events with strings containing white spaces

I created a Java Springboot server that receives and broadcasts messages to C# and JS clients.

When sending messages without whitespaces, the message is correctly broadcast to all clients. However, when I add a whitespace, I get an exception ("OnException") from the C# client. It works fine with the JS client (non-ServiceStack). Doesn't matter where the whitespace is or how many, a single whitespace causes the client to fail.

Stack trace is:

System.ArgumentException: Invalid Selector '{"characterId":"6ed46423-6d70-4aae-a37f-4f5e799d326b","message":"\"hello'
   at ServiceStack.ServerEventsClient.ToTypedMessage(ServerEventMessage e) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServerEventsClient.cs:line 804
   at ServiceStack.ServerEventsClient.ProcessEventMessage(ServerEventMessage e) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServerEventsClient.cs:line 859
   at ServiceStack.ServerEventsClient.<>c__DisplayClass115_0.<ProcessResponse>b__0(Task`1 t) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServerEventsClient.cs:line 725

In the example above, there is a whitespace after the first word ("hello"). The message is a DTO with Guid CharacterId and string message.

Code: Java Springboot server:

    @PostMapping(path = "/message")
    public boolean sendMessage(@RequestBody DTOs.MessageDTO request) {
        for(SseEmitter sseEmitter: emitters){
            try {
                sseEmitter.send(request);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });

        return true;
    }

C# Client using Service Stack:

    private ServerEventsClient _create_sse_client()
    {
        baseUri = $"...";

        return new ServerEventsClient(baseUri)
        {
            OnMessage = this._events.Enqueue,
            OnException = errors.Add,
            OnCommand = this._commands.Enqueue,
            AllRequestFilters = req =>
            {
                req.Method = HttpMethod.Get;
                req.AddHeader("Accept", "text/event-stream");
            },
        };
    }

I'm new to C# so I'm wondering if there's anything obvious here that I'm missing.

Upvotes: 1

Views: 32

Answers (1)

mythz
mythz

Reputation: 143369

ServiceStack's C# Server Events Client is only designed for consuming ServiceStack's Server Events Feature, i.e. it shouldn't be used for consuming other 3rd Party SSE streams.

Upvotes: 0

Related Questions