Skip to content

Conversation

BrennanConroy
Copy link
Member

Fixes #62713

@BrennanConroy BrennanConroy added area-signalr Includes: SignalR clients and servers feature-client-java Related to the SignalR Java client labels Jul 15, 2025
@BrennanConroy BrennanConroy requested a review from halter73 as a code owner July 15, 2025 20:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the Java SignalR client to gracefully ignore message headers instead of throwing, and adds tests to verify header parsing across various message types.

  • The GsonHubProtocol is modified to skip over the "headers" JSON property rather than throwing an exception.
  • New unit tests in GsonHubProtocolTest ensure invocation, completion, and streaming messages with headers (including empty and reordered headers) are parsed without error.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java Replace exception on "headers" field with code that skips its contents
src/SignalR/clients/java/signalr/test/src/main/java/com/microsoft/signalr/GsonHubProtocolTest.java Add tests covering parsing of messages with headers in different scenarios

Comment on lines +142 to +148
// Parse headers as Map<String, String> but don't store for now as it's unused
reader.beginObject();
while (reader.hasNext()) {
reader.nextName(); // Read the key
reader.nextString(); // Read the value
}
reader.endObject();
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify skipping the entire headers object by using reader.skipValue() instead of manually iterating through each property—this reduces boilerplate and potential parsing errors.

Suggested change
// Parse headers as Map<String, String> but don't store for now as it's unused
reader.beginObject();
while (reader.hasNext()) {
reader.nextName(); // Read the key
reader.nextString(); // Read the value
}
reader.endObject();
// Skip the entire headers object as it's unused
reader.skipValue();

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a Java expert but I looked up this API and it seems like JsonReader.skipValue is a better way to skip processing the entire "headers" object. Is there a reason we aren't using it here, especially if the value isn't stored?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye, seems a nice API to use here. also as Brennan explained in one of the issue comments headers are parsed in MessagePack - but they are used later:


return new InvocationMessage(headers, invocationId, target, arguments, streams);

why do we completely ignore them here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we completely ignore them here?

They aren't really used. We set them on the messages but don't actually use them.

Is there a reason we aren't using it here, especially if the value isn't stored?

It doesn't really matter what we do here, but I do like the current code since it technically validates the json is {string:string} whereas skip would just validate that some type of object exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, approved.

@BrennanConroy BrennanConroy merged commit 84c4547 into main Jul 17, 2025
29 checks passed
@BrennanConroy BrennanConroy deleted the brecon/javaheaders branch July 17, 2025 18:18
@BrennanConroy
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/aspnetcore/actions/runs/16352820503

@BrennanConroy
Copy link
Member Author

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspnetcore/actions/runs/16352823734

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers feature-client-java Related to the SignalR Java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SignalR Java client failing on 'Headers not implemented yet.'
3 participants